Volume 5 · Chapter 11 — Storage and Databases
DynamoDB in Depth
11.1 Introduction
DynamoDB carries rich exam detail: keys and indexes (LSI vs GSI), capacity modes and auto scaling, DAX caching, Streams, global tables, TTL, transactions, and the operational realities of hot partitions and adaptive capacity. This chapter provides that depth so you can design DynamoDB tables that perform and scale correctly.
11.2 Keys, Partitions, and Indexes
A DynamoDB table’sprimary keyis either a partition key alone or a partition key + sort key. Thepartition keydetermines which physical partition an item lives on (via hashing), so it must be high-cardinality and evenly accessed to spread load - a poorly-chosen key creates ahot partitionthat throttles. Thesort keyenables range queries within a partition. For additional query patterns, you add secondary indexes: a**Local Secondary Index (LSI)shares the partition key but a different sort key (must be created at table creation, shares the partition’s capacity), and aGlobal Secondary Index (GSI)**has a completely different partition/sort key (can be added anytime, has its own capacity, eventually consistent). The exam pattern: design keys around access patterns, use a GSI for a new access pattern with a different partition key, and choose the partition key to avoid hot partitions.
11.3 Capacity Modes and Auto Scaling
DynamoDB has two capacity modes.On-Demandcharges per request and scales instantly with no capacity planning - ideal for unpredictable or spiky workloads and new tables.Provisionedcapacity (read/write capacity units) is cheaper for steady, predictable load, andauto scalingadjusts provisioned capacity to a target utilization.Adaptive capacityautomatically shifts capacity toward hot partitions to mitigate imbalance. The exam mapping: On-Demand for unpredictable/spiky or when you don’t want to manage capacity; Provisioned + auto scaling for steady, cost-sensitive workloads. Reads can beeventually consistent(default, cheaper) orstrongly consistent(latest, costlier), andtransactionalfor all-or-nothing multi-item writes.
flowchart TB Table[(DynamoDB table)] --> PK[Partition key - spreads load; avoid hot partitions] Table --> GSI[GSI - different key, own capacity, any time] Table --> LSI[LSI - same PK, different sort key, at creation] Table --> Streams[Streams - change feed -> Lambda] Table --> DAX[DAX - microsecond read cache] Table --> GT[Global Tables - multi-Region active-active]
11.4 DAX, Streams, and Global Tables
Three important features.**DAX (DynamoDB Accelerator)**is an in-memory cachespecifically for DynamoDBthat delivers microsecond read latency for read-heavy/hot-key workloads, transparently (no app rewrite) - use DAX rather than ElastiCache when the cache is purely in front of DynamoDB.DynamoDB Streamscapture item-level changes (a 24-hour change feed) that can trigger Lambda - for event-driven pipelines, replication, and aggregations.Global Tablesprovide multi-Region,active-activereplication (write in any Region) with eventual consistency between Regions - for globally distributed low-latency access and multi-Region resilience. The exam pattern: DAX for microsecond DynamoDB reads, Streams for change-driven processing, Global Tables for multi-Region active-active.
11.5 TTL, Backups, and Transactions
More features:**Time to Live (TTL)**auto-deletes expired items (by a timestamp attribute) at no cost - for sessions, temporary data, and cost control.**Point-in-time recovery (PITR)**gives continuous backups with restore to any second in the last 35 days, plus on-demand backups.Transactionsprovide ACID all-or-nothing operations across multiple items/tables when needed.Condition expressionsenable optimistic concurrency (write only if a condition holds), useful for idempotency and preventing lost updates. These make DynamoDB suitable even for workloads needing atomicity and recovery, within its key-based model. Knowing TTL for expiry, PITR for recovery, and transactions/condition expressions for correctness rounds out DynamoDB competence.
11.6 Banking Production Scenario
A bank stores customer sessions and high-volume activity in DynamoDB, with partition keys chosen for even distribution to avoid hot partitions and GSIs added for new query patterns. Session tables use On-Demand capacity for unpredictable load and TTL to auto-expire sessions; steady high-volume tables use Provisioned with auto scaling. DAX fronts a read-heavy reference table for microsecond reads. DynamoDB Streams trigger Lambda to feed the fraud pipeline on each change. Global Tables replicate a customer-preferences table active-active across Regions for low-latency global access. PITR protects against corruption, transactions ensure atomic multi-item updates where needed, and condition expressions enforce idempotency on writes. This complete DynamoDB design is the professional-level NoSQL competence the certification targets.
11.7 Chapter Revision Notes
- Partition key spreads load (avoid hot partitions); sort key enables ranges; LSI (same PK, different sort, at creation) vs GSI (different key, own capacity, any time, eventually consistent).
- Capacity: On-Demand (unpredictable/spiky, no planning) vs Provisioned + auto scaling (steady, cheaper); adaptive capacity mitigates hot partitions; reads eventually/strongly consistent.
- DAX = microsecond in-memory cache for DynamoDB; Streams = change feed to Lambda; Global Tables = multi-Region active-active (eventual between Regions).
- TTL auto-expires items; PITR = continuous 35-day recovery + on-demand backups; transactions = ACID multi-item; condition expressions = optimistic concurrency/idempotency.
- Use DAX (not ElastiCache) when caching purely in front of DynamoDB.