← Week 2: DynamoDB Internals

Day 8: DynamoDB Data Model

Phase 5 · Aug 19, 2026

← Week 2: DynamoDB Internals

Agenda (2–3 hours)

  • Read (45 min): DynamoDB Developer Guide: core components, data types, partition key, sort key; Alex DeBrie "The DynamoDB Book" Chapter 1 (free excerpt)
  • Study (45 min): Model a social media post with replies using both a normalized relational model and a DynamoDB model; compare access patterns
  • Practice (45 min): Create a DynamoDB table; write 100 items with various data types; perform GetItem, Query, Scan
  • Challenge (30 min): Why does DynamoDB have no joins? How does this force you to denormalize data? When is denormalization a feature rather than a bug?
← Week 2: DynamoDB Internals

DynamoDB Core Concepts

Table: the top-level container
Item: a row (up to 400KB)
Attribute: a field (strongly typed, can be nested)

Primary key options:

  • Partition key only: uniquely identifies each item
  • Partition key + sort key (composite): enables range queries within a partition
← Week 2: DynamoDB Internals

Data Types

Category Types
Scalar String (S), Number (N), Binary (B), Boolean (BOOL), Null (NULL)
Set String Set (SS), Number Set (NS), Binary Set (BS)
Document List (L), Map (M)

Numbers are stored as strings internally — use Decimal for precise arithmetic.

← Week 2: DynamoDB Internals

Partition Key Distribution

DynamoDB distributes items across partitions by hash(partition_key) % num_partitions.

Hot partition problem: if all traffic hits the same partition key:

User activity table, partition key = user_id
→ A celebrity with 100M followers = "hot key"
→ That partition gets all the reads

Solutions:

  • Write sharding: append a random suffix to the partition key (user123#1 through user123#N)
  • Caching: cache hot items in ElastiCache
  • Design: choose a partition key with high cardinality and even access distribution
← Week 2: DynamoDB Internals

Local Secondary Index (LSI) and Global Secondary Index (GSI)

LSI: alternate sort key on the same partition — created at table creation time only
GSI: completely different partition key + sort key — created anytime

Table: Orders (PK: customer_id, SK: order_id)
GSI:   status-date-index (PK: status, SK: order_date)
→ Query all "pending" orders from the last 7 days

GSIs are billed separately and have their own throughput capacity.

← Week 2: DynamoDB Internals

Key Takeaways

  • DynamoDB is a key-value + document store: no joins, no SQL, no relations
  • Partition key distribution is critical for performance: avoid hot partitions
  • LSI: alternate sort key on same partition; GSI: entirely different key structure
  • Design table structure around access patterns first — not normalized data model

Tomorrow: DynamoDB capacity planning — RCU, WCU, and cost optimization.