Skip to main content
DynamoDB Architecture

Module Overview

Estimated Time: 4-5 hours | Difficulty: Intermediate-Advanced | Prerequisites: Core Concepts
DynamoDB is AWS’s fully managed NoSQL database designed for single-digit millisecond performance at any scale. The fundamental trade-off: DynamoDB gives you predictable, fast performance and infinite scalability, but in exchange you must design your data model around your access patterns upfront. Unlike a relational database where you can write any SQL query against any column, DynamoDB requires you to know how you will query your data before you create the table. This is the single biggest mental shift for developers coming from PostgreSQL or MySQL — and the source of most DynamoDB frustration. This module covers everything from data modeling to advanced patterns used in production systems. What You’ll Learn:
  • DynamoDB fundamentals and architecture
  • Data modeling and access patterns
  • Primary keys, GSIs, and LSIs
  • Capacity modes (On-Demand vs Provisioned)
  • Transactions and consistency models
  • DynamoDB Accelerator (DAX)
  • Streams and change data capture
  • Performance optimization and cost management

Why DynamoDB?

Fully Managed

No servers to manage, automatic scaling, built-in backup and restore

Single-Digit Milliseconds

Consistent performance at any scale, from 1 to millions of requests/second

Serverless

Pay-per-request pricing, no idle capacity charges with On-Demand mode

Global Tables

Multi-region, active-active replication for global applications

DynamoDB Architecture


Core Concepts

Primary Keys

DynamoDB supports two types of primary keys:

Data Types


Data Modeling Patterns

Single-Table Design

Best Practice: Use single-table design for related entities. This enables fetching all related data in a single query, reducing latency and cost. However, single-table design is NOT always the right answer. It adds complexity that may not be justified for simple CRUD applications. Use it when: (1) you need to fetch related entities in a single query, (2) you have well-defined access patterns, and (3) your team understands the pattern. For a simple user-profile service with one access pattern, a regular table with a partition key is perfectly fine.

Access Pattern First Design


Secondary Indexes

Global Secondary Index (GSI)

DynamoDB GSI

Local Secondary Index (LSI)

GSI vs LSI Comparison


Capacity Modes

On-Demand vs Provisioned

Capacity Units Explained


Operations

Basic CRUD Operations

Batch Operations


Transactions

DynamoDB supports ACID transactions across multiple items and tables.

DynamoDB Accelerator (DAX)

DAX Architecture
DAX is an in-memory cache for DynamoDB, providing microsecond response times.

DynamoDB Streams

Capture item-level changes for event-driven architectures.

Best Practices

Performance Optimization

Even Key Distribution

Use high-cardinality partition keys to avoid hot partitions

Sparse Indexes

Only include items with indexed attributes in GSIs

Projection Carefully

Only project needed attributes to GSIs (reduce WCU)

Use BatchGetItem

Batch reads instead of multiple GetItem calls

Cost Optimization


🎯 Interview Questions

Choose DynamoDB when:
  • Predictable, single-digit millisecond latency at any scale
  • Simple access patterns (key-value or document)
  • Massive scale requirements (millions of requests/second)
  • Serverless architecture
  • Global distribution needed (Global Tables)
Choose RDS when:
  • Complex queries with JOINs
  • Strong ACID requirements across tables
  • Existing SQL skills/codebase
  • Complex reporting needs
Prevention strategies:
  1. Use high-cardinality partition keys
  2. Add random suffix (write sharding)
  3. Use composite keys to distribute writes
Example - Order ID with random suffix:
When reading, query all shards in parallel and merge results.
GSI:
  • Flexible (any partition/sort key)
  • Own capacity (no throttling impact on base table)
  • Eventually consistent only
  • Can be added/removed anytime
LSI:
  • Must share partition key with base table
  • Shares capacity (can throttle base table)
  • Strongly consistent available
  • Must be defined at table creation
  • 10 GB partition limit
Recommendation: Prefer GSIs unless you need strongly consistent reads on alternate sort key.
Key points:
  • Use Limit for page size
  • Use ExclusiveStartKey for continuation
  • LastEvaluatedKey indicates more pages exist
Access patterns:
  • Get user profile
  • Get user’s posts
  • Get user’s followers
  • Get user’s following
  • Get feed (posts from following)
Single-table design:

🧪 Hands-On Lab

1

Create DynamoDB Table

Create a table with composite primary key and enable Streams
2

Implement Single-Table Design

Model users, orders, and order items in a single table
3

Create GSI

Add a GSI for querying orders by status
4

Implement Transactions

Build an atomic order placement with inventory check
5

Process Streams

Create Lambda to process DynamoDB Streams for real-time updates

Next Module

AWS Lambda

Master serverless compute with AWS Lambda