Skip to content

Files

Latest commit

00db231 · Jul 19, 2020

History

History
172 lines (111 loc) · 3.21 KB

dynamo-presentation.adoc

File metadata and controls

172 lines (111 loc) · 3.21 KB

DynamoDB Presentation

Objectives

  • Get to know each other

  • Compare and contrast DynamoDB data modeling to relational data modeling

  • Describe the importance of partitioning in DynamoDB

Non-Work Facts About Me!

Chuck

headshot
  • My first job was at a doggy daycare

  • I randomly know a lot about aphids

  • I graduated with high honors in pure math and produced a thesis as an undergraduate

  • I love building PCs to play big beautiful video games

  • I am a podcast nerd:

    • Freakonomics, Software Engineering Daily, Intelligence Squared, Not Another DnD Podcast, Radiolab, and more

  • My wife Caroline and my 1.5yo Rafael are my best friends and make me laugh every day

Notice and Wonder

notice wonder

What do you notice?

What do you wonder?

Notice and Wonder Debrief

notice wonder debrief

NoSQL vs. Relational Data Modeling — Online Gaming



Think of an online multiplayer game.

What are some "entities" involved?

What are some access patterns?



The Relational Way

Suppose we want to query for all the usernames of users in a particular game.

Star Schema Pros Cons
  • Table for "user"

  • Table for "game"

  • Fact table that relates "user_ID" with "game_ID"

  • Join "user" and "game" tables and filter for records with the given "game_ID"

  • Great for ad-hoc queries

  • Great for analytics, like aggregations

  • Joins don’t scale well

The DynamoDB Way

entities
Note
One table with O(1) lookup by primary key, or O(log(n)) if including a sort key. No joins! You plan the access pattern into your data model and include everything in one table.

Design the Primary Key

Table 1. Composite Primary Key
Entity Partition Key (a.k.a. HASH) Sort Key (a.k.a. RANGE)

User

USER#<USERNAME>

#PLACEHOLDER#<USERNAME>

Game

GAME#<GAME_ID>

#PLACEHOLDER#<GAME_ID>

UserGameMapping

GAME#<GAME_ID>

USER#<USERNAME>

Code Example

Query multiple entities in one request to one table

resp = dynamodb.query(
        TableName='battle-royale',
        KeyConditionExpression="PK = :pk AND SK BETWEEN :placeholder AND :users",
        ExpressionAttributeValues={
            ":pk": { "S": "GAME#{}".format(game_id) },
            ":placeholder": { "S": "#PLACEHOLDER#{}".format(game_id) },
            ":users": { "S": "USER$" },
        },
        ScanIndexForward=True
    )

3, 2, 1 Reflection

  • What are 3 things you learned?

  • What are 2 things you found interesting?

  • What’s 1 question you still have?

Objectives

  • Get to know each other

  • Describe the importance of partitioning in DynamoDB

  • Compare and contrast DynamoDB data modeling to relational data modeling