Skip to Content
Asterrr's Handbook
2 · New solutions

Amazon DynamoDB

Key design, capacity math, indexes, consistency, streams, global tables, backups and security for DynamoDB, with the limits the exam asks about.

Exam tasks: 2.5 and 4.3 (purpose-built data stores), 2.2 (multi-Region data), 3.2, 3.3

The decision: do you know your access patterns, and do you need single-digit millisecond reads and writes at any scale? If so, how should the keys, capacity mode and replication be set?

DynamoDB is a serverless key-value and document store. Tables scale by partitioning on the partition key, so the design question is always how your keys spread the load.

Region ARegion Breadsmisswriteschangesglobal tableApplicationDAX clusterTableStreamLambda triggerReplica table
A table in one Region with DAX in front for reads. Streams feed other services, and a global table replicates writes to a second Region.
400 KB
Maximum item size. Store larger objects in S3 and keep a pointer
4 KB / 1 KB
Read and write unit sizes. One RCU is a 4 KB strongly consistent read, one WCU a 1 KB write
3,000 / 1,000
RCU and WCU a single partition can serve, before splitting
35 days
Longest point-in-time recovery window
24 hours
DynamoDB Streams retention
100
Items in a transaction

Designing keys

  • Pick a high-cardinality partition key that spreads requests evenly, such as a customer or device ID. A key like date or status concentrates traffic on one partition, a hot partition.
  • Adaptive capacity shifts throughput toward hot items and splits busy partitions, which softens skew. It does not rescue a key with one overwhelmingly popular value.
  • To spread a single hot key, add a write-sharding suffix, such as device#7, and read across the shards.
  • Model from the access patterns. List the queries first, then choose keys and indexes that answer each one with a Query. Many teams put several entity types in one table (single-table design) to fetch related items in one call.
  • Query reads items under one partition key and is efficient. Scan reads the whole table, and a filter expression only drops results after reading, so it does not reduce consumed capacity.

Capacity math

OperationRounding ruleCost
Strongly consistent readItem size rounded up to the next 4 KB1 RCU per 4 KB
Eventually consistent readSame rounding0.5 RCU per 4 KB
Transactional readSame rounding2 RCUs per 4 KB
WriteItem size rounded up to the next 1 KB1 WCU per 1 KB
Transactional writeSame rounding2 WCUs per 1 KB

Worked examples:

  • 100 strongly consistent reads per second of 6 KB items: 6 KB rounds up to 8 KB, which is 2 RCUs each, so 200 RCUs. Eventually consistent halves it to 100 RCUs. Transactional doubles it to 400 RCUs.
  • 50 writes per second of 3.5 KB items: 3.5 KB rounds up to 4 KB, which is 4 WCUs each, so 200 WCUs.

Exam signal

Round the item size up first, then multiply by the rate. Exam questions hide the trap in an item size that is not a multiple of 4 KB or 1 KB.

Capacity modes, indexes and features

Capacity modes

On-demandProvisioned
BillingPer requestPer RCU and WCU per hour
Best forUnknown, spiky or new workloadsSteady, predictable traffic
ScalingAutomaticAuto scaling within limits you set
Cost leverNone beyond the modeReserved capacity for steady baselines

You can switch modes on a table periodically, so start on-demand and move to provisioned once traffic is known.

Indexes

Global secondary indexLocal secondary index
KeysAny partition and sort keySame partition key, different sort key
When createdAnytimeOnly at table creation
ConsistencyEventually consistentStrong or eventual
CapacityIts ownShares the table's
Size limitNone10 GB per partition key value
Per table20 by default5

Adding an LSI later

An LSI can't be added to an existing table. If a question needs a new query pattern on a live table, the answer is a GSI (or a new table and a migration).

Other features

  • Streams: an ordered, 24-hour log of item changes, consumed by Lambda or the Kinesis Client Library adapter. Use it for triggers, audit and cross-system sync. Kinesis Data Streams for DynamoDB is the alternative for longer retention and more consumers.
  • Global tables: multi-Region, multi-active. The default mode is eventually consistent with last writer wins. Multi-Region strong consistency (three Regions, or two plus a witness) gives an RPO of zero at higher write latency.
  • TTL deletes expired items in the background for free, usually within a few days of expiry. Deletions appear in the stream, so you can archive them to S3.
  • PITR restores to any second in the last 35 days (the window is configurable) into a new table. On-demand backups are kept until you delete them.
  • Transactions give all-or-nothing writes across up to 100 items.
  • Maximum item size is 400 KB. Store larger objects in S3 and keep a pointer.

Consistency and conditional writes

  • Reads are eventually consistent by default. Ask for strong consistency per read on a table or LSI, not on a GSI and not across Regions in a global table's default mode.
  • Conditional writes (attribute_not_exists, a version number) give optimistic locking, so two writers do not overwrite each other. Atomic counters use UpdateItem with an increment.
  • BatchGetItem reads up to 100 items and BatchWriteItem writes up to 25. Each item inside a batch still consumes its own capacity, and a throttled item is returned as unprocessed, so retry with backoff.

Table classes, import and export

  • Standard is the default. Standard-IA lowers storage cost and raises request cost, for tables that are mostly at rest.
  • Export to S3 (from PITR) writes a snapshot without consuming read capacity, which suits analytics with Athena. Import from S3 creates a new table from files.

Security

  • Encryption at rest is always on, using an AWS owned key, an AWS managed key or a customer managed key.
  • Fine-grained access control uses IAM conditions such as dynamodb:LeadingKeys to limit a caller to items whose partition key matches their identity, which fits per-user data with web identity federation.
  • Use a gateway VPC endpoint so traffic stays off the internet, and an endpoint policy to limit which tables.
  • Back up across accounts and Regions with AWS Backup.

DynamoDB has no read replicas

There is no read replica feature. Read scale comes from the table itself, DAX for cached reads, or global tables for local reads in other Regions. A question that offers a DynamoDB read replica is a distractor.

DAX

  • An in-VPC, write-through cache that speaks the DynamoDB API. Swap the client library and keep your code.
  • Caches items (GetItem, BatchGetItem) and query or scan results separately.
  • Serves eventually consistent reads. Strongly consistent reads pass straight through to DynamoDB.
  • Helps read-heavy, repeated-key workloads. It doesn't help write-heavy tables and doesn't raise write capacity.
  • Run at least three nodes across AZs for production.

Scenarios

Scenario
A game stores one item per match, keyed by game_mode (five values) with the match ID as the sort key. At peak, requests for the most popular mode are throttled although the table has plenty of provisioned capacity overall. What is the best fix?
Scenario
An application reads 80 items per second with strong consistency. Each item is 9 KB. How many read capacity units must the table provision?
Scenario
An analytics team needs a nightly copy of a 2 TB DynamoDB table in S3 to query with Athena, without affecting production latency or consuming the table's read capacity. What should they use?

Further reading

On this page