Skip to content
Visual explainer 4h to learn 5 steps

DynamoDB: keys, capacity, DAX & global tables

Model a key-value workload and size it for throughput.

By Invicly Tech, , in AWS Solutions Architect – Associate. About 12 minutes to read.

Topic 22 of 34

In short

DynamoDB is a serverless key-value and document database with single-digit millisecond latency at any scale. You design keys around access patterns, then choose on-demand or provisioned capacity. DAX adds microsecond caching and global tables give multi-Region, multi-active replication.

Explained simply

DynamoDB is a database where you look things up by key, very fast, at any size. There are no servers to manage: you create a table, and AWS spreads the data over many machines for you. A good design answers each request in single-digit milliseconds, whether the table holds 1 MB or 100 TB.

Each item (a row) is found by its primary key. The partition key decides which storage partition holds the item, like the first letter decides the drawer in a filing cabinet. An optional sort key orders items inside that drawer, so you can ask for all orders of one customer, newest first.

Unlike SQL databases, you design DynamoDB around your questions, not your data. First list the access patterns, such as get a user by ID or list a user's orders by date. Then choose keys and indexes so each question is one fast Query. There are no joins, so related data is often stored together.

You pay for storage and for reads and writes. On-demand mode charges per request and scales by itself. Provisioned mode reserves a fixed number of reads and writes per second, which is cheaper when traffic is steady and predictable.

Press Play on a diagram to walk through it one step at a time.

MapDynamoDB table design
Table
  • Primary key
    • Partition key: spreads data
    • Sort key: orders items
  • Items
    • Up to 400 KB each
    • Flexible attributes
  • Secondary indexes
    • GSI: any keys, anytime
    • LSI: same partition key, at creation
  • Add-ons
    • DAX cache
    • Streams
    • Global tables
    • TTL
CompareCapacity modes
On-demand
  • Pay per request
  • No capacity planning
  • Unpredictable or new workloads
  • Scales instantly to prior peaks
Provisioned
  • Set RCUs and WCUs
  • Auto scaling optional
  • Cheaper for steady traffic
  • Reserved capacity available
MapAccess patterns drive the keys (online shop)
Table: shop (PK, SK)
  • PK CUSTOMER#42, SK PROFILE
    • Get a customer's profile
  • PK CUSTOMER#42, SK ORDER#2026-11-03
    • List a customer's orders by date
    • Query with begins_with ORDER#
  • GSI1: PK ORDER#9001
    • Look up one order by its ID
  • GSI2: PK PRODUCT#7, SK date
    • Recent orders of one product
SequenceReads and writes through DAX
App
DAX
DynamoDB
  1. 1GetItem user 42
    App to DAX: GetItem user 42
  2. 2Cache miss: GetItem
    DAX to DynamoDB: Cache miss: GetItem
  3. 3Item
    DynamoDB to DAX: Item
  4. 4Item (milliseconds)
    DAX to App: Item (milliseconds)
  5. 5GetItem user 42 again
    App to DAX: GetItem user 42 again
  6. 6From cache (microseconds)
    DAX to App: From cache (microseconds)
  7. 7PutItem user 42
    App to DAX: PutItem user 42
  8. 8Write-through, then update cache
    DAX to DynamoDB: Write-through, then update cache

In depth

Partitions and hot keys

DynamoDB hashes the partition key to pick a partition. Each partition can serve up to 3,000 read capacity units and 1,000 write capacity units per second, and holds about 10 GB; tables split into more partitions as they grow. So the table as a whole can be enormous, but a single key value can only go so fast.

If most traffic hits one key, for example a status of PENDING or today's date, that partition throttles while the others sit idle. Adaptive capacity shifts capacity toward busy partitions and can split them, but it cannot fix one extremely hot key. The fix is in the design: choose keys with many distinct values, such as userId or orderId, or add a suffix (write sharding), like 2026-11-05#1 to 2026-11-05#10, and read all shards when you need the whole set.

FlowHow a write finds its partition
  1. 1
    PutItem

    customerId = c-42

  2. 2
    Hash the key

    c-42 becomes a number

  3. 3
    Pick partition

    Each partition owns a hash range

  4. 4
    Store in 3 AZs

    Replicated before success is returned

  5. 5
    Success

    Uses WCUs from that partition

Capacity units in real numbers

One RCU (read capacity unit) is one strongly consistent read per second of an item up to 4 KB, or two eventually consistent reads. One WCU (write capacity unit) is one write per second of up to 1 KB. Sizes round up: a strong read of a 9 KB item costs 3 RCUs, and writing a 2.5 KB item costs 3 WCUs. Transactional reads and writes cost double.

Example: 500 eventually consistent reads per second of 6 KB items need 500 x 2 / 2 = 500 RCUs. 100 writes per second of 1.5 KB items need 100 x 2 = 200 WCUs. In provisioned mode you set these numbers, add auto scaling to follow traffic, and can buy reserved capacity for steady loads. In on-demand mode you pay per request with the same rounding, and the table instantly handles up to double its previous peak.

  • Strong read: size divided by 4 KB, rounded up
  • Eventually consistent read: half of that
  • Write: size divided by 1 KB, rounded up
  • Transactions: double the units

GSIs and LSIs: choosing an index

A Query can only use a key, so other access patterns need indexes. A global secondary index (GSI) has its own partition and sort key, can be added or removed at any time, and has its own capacity. It is updated asynchronously, so GSI reads are only eventually consistent. If a GSI runs short of write capacity, writes to the base table are throttled too. The default limit is 20 GSIs per table.

A local secondary index (LSI) keeps the same partition key with a different sort key. It must be created together with the table, supports strongly consistent reads, and shares the table's capacity, but it limits each partition key value to 10 GB of data (an item collection). A table can have up to 5 LSIs. Projections (KEYS_ONLY, INCLUDE or ALL) copy only the attributes a query needs, which saves storage and write cost.

CompareGSI vs LSI
Global secondary index
  • Any partition and sort key
  • Add or remove at any time
  • Eventually consistent reads only
  • Own capacity; up to 20 by default
Local secondary index
  • Same partition key, new sort key
  • Only at table creation
  • Strongly consistent reads possible
  • 10 GB per key value; up to 5

DAX, Streams and TTL

DAX (DynamoDB Accelerator) is an in-memory cache cluster inside your VPC that speaks the DynamoDB API, so you change the client and keep your code. It caches GetItem and Query results and serves repeat reads in microseconds. Writes go through DAX to the table (write-through). Strongly consistent reads are passed straight to DynamoDB and are not cached, so DAX helps only read-heavy, eventually consistent workloads.

DynamoDB Streams records every item change for 24 hours, in order for each item. A Lambda function can read the stream to update a search index, send emails or keep running totals. TTL lets you give items an expiry time (a number in epoch seconds); DynamoDB deletes expired items for free, usually within a few days, and those deletes appear in the stream so you can archive them.

Global tables and backups

Global tables copy a table to other Regions, and every replica accepts reads and writes (multi-active). Changes usually reach the other Regions within about a second. If two Regions update the same item at nearly the same moment, the last writer wins and every Region ends up with that version. Apps that must avoid conflicts often send each user's writes to one home Region.

For recovery, point-in-time recovery (PITR) can restore a table to any second within up to the last 35 days, and on-demand backups keep full copies until you delete them. Both restore into a new table. Use global tables for Region failures and PITR for mistakes, because a bad write or delete reaches every Region within seconds.

Learn it in 5 short steps

About 50m each. Track them with a timer in your plan.

  1. 1
    Design partition and sort keys~50m
  2. 2
    Choose on-demand or provisioned capacity~50m
  3. 3
    Add GSIs and LSIs for access patterns~50m
  4. 4
    Speed up reads with DAX~50m
  5. 5
    Replicate with global tables~50m

Key points

  • Pick a high-cardinality partition key to avoid hot partitions.
  • One RCU is one strongly consistent 4 KB read per second, or two eventually consistent.
  • One WCU is one 1 KB write per second.
  • DAX caches reads in microseconds; it does not help write-heavy workloads.
  • Global tables provide active-active replication across Regions.

Key terms

Tap a card to flip it. 0/6 known

Examples

bash
aws dynamodb create-table \
  --table-name orders \
  --attribute-definitions \
    AttributeName=customerId,AttributeType=S \
    AttributeName=orderDate,AttributeType=S \
  --key-schema \
    AttributeName=customerId,KeyType=HASH \
    AttributeName=orderDate,KeyType=RANGE \
  --billing-mode PAY_PER_REQUEST

On-demand table keyed by customer and date.

Querying orders and adding a lookup index

The orders table has partition key customerId and sort key orderDate. Step 1: list one customer's November orders, newest first, with one Query using begins_with on the sort key. Step 2: support finding an order by its ID by adding a GSI on orderId, which can be done on a live table. The GSI only needs KEYS_ONLY projection if the app then fetches full items by key. Step 3: query the new index once it is ACTIVE.

bash
aws dynamodb query --table-name orders \
  --key-condition-expression 'customerId = :c AND begins_with(orderDate, :m)' \
  --expression-attribute-values '{":c": {"S": "c-42"}, ":m": {"S": "2026-11"}}' \
  --no-scan-index-forward

aws dynamodb update-table --table-name orders \
  --attribute-definitions AttributeName=orderId,AttributeType=S \
  --global-secondary-index-updates '[{"Create": {"IndexName": "orderId-index",
    "KeySchema": [{"AttributeName": "orderId", "KeyType": "HASH"}],
    "Projection": {"ProjectionType": "KEYS_ONLY"}}}]'

aws dynamodb query --table-name orders --index-name orderId-index \
  --key-condition-expression 'orderId = :o' \
  --expression-attribute-values '{":o": {"S": "o-9001"}}'

Sizing a table for a ticket sale

Normally the app does 200 strongly consistent reads per second of 3 KB items and 50 writes per second of 0.5 KB items. During a ticket sale both jump about 20 times for ten minutes. Step 1: compute normal capacity: 200 RCUs and 50 WCUs. Step 2: compute the peak: 4,000 RCUs and 1,000 WCUs. Step 3: decide. Provisioned auto scaling reacts over minutes, which is too slow for a sudden spike, so either use on-demand or raise provisioned capacity before the sale. Also check that ticket IDs, not the event ID, are the partition key, or one partition caps writes at 1,000 WCUs.

python
import math

def rcu(size_kb, per_sec, strong=True):
    units = math.ceil(size_kb / 4) * per_sec
    return units if strong else math.ceil(units / 2)

def wcu(size_kb, per_sec):
    return math.ceil(size_kb) * per_sec

print(rcu(3, 200), wcu(0.5, 50))      # 200 50   normal
print(rcu(3, 4000), wcu(0.5, 1000))   # 4000 1000 peak

Quick reference

  • Item max 400 KB; pick a partition key with many distinct values
  • Per partition: up to 3,000 RCU and 1,000 WCU per second
  • RCU: one 4 KB strong read per second (or two eventual). WCU: one 1 KB write per second
  • GSI: any keys, add anytime, eventual reads. LSI: same PK, only at creation, 10 GB per PK
  • Query uses keys and is cheap; Scan reads the whole table and is expensive
  • DAX caches eventually consistent reads in microseconds; strong reads skip the cache
  • Streams keep item changes for 24 hours; TTL deletes expired items for free
  • PITR restores to any second within up to 35 days, always into a new table

Common mistakes

  • Using a low-cardinality partition key like status, creating hot partitions.
  • Planning to add an LSI later; LSIs must be defined at table creation.

Quick quiz

Pick an answer to see if you're right and why.

Question 1

1How many RCUs does one strongly consistent read of an 11 KB item use?

Question 2

2A table has plenty of write capacity but writes are throttled. A GSI on it has low write capacity. What is happening?

Question 3

3Which kind of index can you add to an existing table?

Question 4

4Which workload benefits LEAST from DAX?

Question 5

5Two Regions update the same item of a global table at nearly the same time. What happens?

0/5 answered

Practice exercises

Try each one yourself first. Use the hint if you get stuck, then compare with the solution.

  1. Exercise 1easy

    Put three orders for customer c-42 into the orders table (customerId plus orderDate key), then query them newest first.

  2. Exercise 2medium

    Turn on TTL with the attribute expiresAt and write an item that expires one hour from now.

  3. Exercise 3hard

    Write a Python function with boto3 that sums the total attribute of all orders for one customer, handling result pages correctly.

Check yourself

Answer in your head, reveal, then be honest with yourself.

Feel confident about this topic?

Frequently asked questions

Is DynamoDB a NoSQL database?
Yes. It is a key-value and document database with no joins and no fixed schema beyond the key attributes. It also accepts a SQL-like language called PartiQL, but queries still follow the same key-based rules.
When should I use Scan?
Rarely in normal request paths. A Scan reads every item and uses capacity for all of them; keep it for one-off exports or small tables, and design a key or GSI for anything frequent.
On-demand or provisioned: which is cheaper?
For steady, predictable traffic, provisioned with auto scaling is usually cheaper. For new, spiky or mostly idle tables, on-demand usually wins because you pay nothing for unused capacity.
What is the maximum item size in DynamoDB?
400 KB, including attribute names. Store larger blobs in S3 and keep the S3 key in the item.

Go deeper

ShareXLinkedInWhatsApp