Lab 06: Amazon DynamoDB Design

Time: 50 minutes | Level: Architect | DB: DynamoDB (boto3 simulation)


🎯 Objective

Master DynamoDB data modeling: partition key design, sort keys, GSI/LSI, single-table design, access-patterns-first methodology, and avoiding hot partitions. Build a complete e-commerce model with boto3.


📚 Background

DynamoDB Core Concepts

Concept
Description

Partition Key (PK)

Hash key — determines physical partition

Sort Key (SK)

Range key — enables range queries within partition

Item

Row equivalent (up to 400 KB)

GSI

Global Secondary Index — different PK+SK, separate partition

LSI

Local Secondary Index — same PK, different SK, same partition

On-demand

Pay per request; auto-scales instantly

Provisioned

Fixed RCU/WCU; can use auto-scaling

Access-Patterns-First Design

DynamoDB design rule: Define your access patterns BEFORE designing your schema.

Unlike RDBMS where you normalize then query, DynamoDB is query-driven:

  1. List all access patterns

  2. Design partition key to spread data evenly

  3. Use SK to support range queries

  4. Add GSI for additional access patterns

Single-Table Design

Store multiple entity types in ONE table using composite keys:


Step 1: Install boto3

📸 Verified Output:


Step 2: Define Access Patterns (Design First)

📸 Verified Output:


Step 3: Create Table with GSI (boto3)

📸 Verified Output:


Step 4: Put Items (Single-Table Design)

📸 Verified Output:


Step 5: Hot Partition Problem & Solutions

📸 Verified Output:


Step 6: DynamoDB Streams & CDC

📸 Verified Output:


Step 7: Capacity Planning

📸 Verified Output:


Step 8: Capstone — Complete DynamoDB Design Review

📸 Verified Output:


Summary

Concept
Key Takeaway

Partition Key

Must have high cardinality; distributes data across partitions

Sort Key

Enables range queries and efficient data organization

Single-table design

Multiple entity types in one table with composite keys

GSI

Separate partition key for alternative access patterns; eventual

LSI

Same partition key, different sort key; created at table creation

Hot partition

Single PK getting >1,000 WCU/s → throttled; use write sharding

On-demand

Auto-scales; best for unpredictable or new applications

Provisioned + auto-scaling

Better cost for predictable workloads

DynamoDB Streams

CDC: INSERT/MODIFY/REMOVE events trigger Lambda

Access-patterns-first

Design schema for your queries, not normalization

💡 Architect's insight: DynamoDB rewards you for knowing your access patterns upfront. The single-table design pattern — counterintuitive at first — eliminates table joins and gives consistent single-digit-millisecond performance at any scale.

Last updated