Capacity unit arithmetic, because you need to do it by hand. One write capacity unit is one write of up to 1 KB; one read capacity unit is one strongly consistent read of up to 4 KB, and an eventually consistent read of that size costs 0.5 RCU. Sizes round up: a 5 KB item costs 5 WCUs to write and 1.25 RCUs to read eventually-consistently. A transactional write costs 2 WCUs per KB and a transactional read 2 RCUs per 4 KB. Index writes are additional, per matching index.
This arithmetic is how you turn an access pattern list into a cost estimate, and doing it by hand once for your own design is the exercise that makes DynamoDB cost legible.
On-demand against provisioned.
On-demand charges per request with no capacity planning, scales instantly within limits, and costs roughly six to seven times more per request than fully-utilised provisioned capacity. It is right for unpredictable or spiky traffic, for development, and for new applications whose load you cannot predict.
Provisioned charges for capacity whether you use it or not, is much cheaper per request when well utilised, and throttles when you exceed it. With auto scaling it adjusts to demand - but auto scaling reacts over minutes, so it does not protect against a sudden spike. Reserved capacity discounts provisioned further for a commitment.
The practical rule: start on-demand, measure for a month, and move to provisioned with auto scaling if the pattern is predictable and the saving is material. Note you can switch modes, with a cooldown.
Hot partitions are the characteristic performance problem. Throughput is ultimately per-partition, and a partition has limits (around 3,000 RCU and 1,000 WCU). A partition key with skewed traffic therefore throttles while the table as a whole is far below its provisioned capacity - which is confusing the first time, because the table metrics look fine.
Adaptive capacity mitigates this: DynamoDB automatically shifts capacity toward hot partitions and can isolate a very hot item onto its own partition. It is instantaneous now rather than taking minutes, and it is genuinely effective - but it cannot exceed the per-partition ceiling, so a single extremely hot key still throttles. Write sharding - appending a suffix 0..N to the partition key, writing to a random one and reading all N - is the design fix.
Diagnosing throttling. ThrottledRequests and UserErrors in CloudWatch, ConsumedReadCapacityUnits against provisioned, and - the useful one - CloudWatch Contributor Insights, which names the most-accessed partition keys. The distinction to make: throttling because the table's capacity is genuinely too low (raise it) against throttling because one partition is hot while the table has headroom (change the key). Treating the second as the first means paying for capacity that does not help.
Cost modelling covers reads, writes, index writes, storage, stream reads, backup storage, PITR, global table replication (which charges replicated writes) and data transfer. Build the spreadsheet from your measured capacity consumption.
Laboratory exercise 4 - a measured improvement.
Load at least two million items. Declare a baseline: ten access patterns with p50, p95 and p99 and consumed capacity for each.
Do the capacity arithmetic by hand for your item size distribution, then compare your calculation with the actual ConsumedCapacity. Reconcile any difference - that reconciliation is the exercise.
Create a hot partition deliberately: drive 95% of writes at one partition key under provisioned capacity, and record the throttling while the table has headroom. Show the table metrics looking healthy. Then apply write sharding and re-measure.
Compare the modes: run the same workload on on-demand and on provisioned with auto scaling, and record cost and throttling for both. Then introduce a sudden 10x spike and show auto scaling failing to keep up.
Apply the other techniques and re-measure: a narrower index projection, BatchGetItem against individual GetItem calls, eventual against strong consistency on a read-heavy pattern, and parallel segmented Scan for a legitimate full-table job.
Then build the cost model and project it to 10x and 100x your test load.
Deliverable: the benchmark report with percentiles and capacity at each step, the hand calculation reconciled against the measurement, the hot partition evidence including the misleading table metrics, the sharding fix, the mode comparison with the spike, the cost model with projections, and one change that did not help.
// ==================================================================
// CAPACITY ARITHMETIC. Do it by hand once; it makes cost legible.
// ==================================================================
// 1 WCU = 1 write of up to 1 KB
// 1 RCU = 1 STRONGLY consistent read of up to 4 KB
// = 2 EVENTUALLY consistent reads of up to 4 KB (so 0.5 each)
// SIZES ROUND UP.
// transactional write = 2 WCU per KB
// transactional read = 2 RCU per 4 KB
// + one index write per MATCHING index
//
// a 5 KB item:
// write 5 WCU
// write + 3 matching GSIs 20 WCU
// read, strong 1.25 -> 2 RCU
// read, eventual 0.625 -> 1 RCU
// read, transactional 2.5 -> 3 RCU
//
// 1,000 writes/s of 5 KB items with 3 GSIs = 20,000 WCU provisioned
//
// Then CHECK your arithmetic against reality:
const r = await db.send(new PutCommand({
TableName: "Commerce", Item: bigItem, ReturnConsumedCapacity: "INDEXES"
}));
r.ConsumedCapacity;
// Reconciling your calculation with this number IS the exercise.
// ==================================================================
// ON-DEMAND vs PROVISIONED.
// ==================================================================
// ON-DEMAND per request, no planning, scales instantly within
// limits. ~6-7x the per-request price of
// WELL-UTILISED provisioned.
// Right for: spiky or unknown traffic, development,
// a new application.
//
// PROVISIONED paid whether used or not. Much cheaper per request
// when well utilised. THROTTLES above the limit.
// + AUTO SCALING: adjusts to demand, but REACTS OVER
// MINUTES - it does NOT protect against a sudden
// spike. Demonstrate that.
// + RESERVED CAPACITY: a further discount for a
// commitment.
//
// THE RULE: start ON-DEMAND, measure for a month, move to
// provisioned with auto scaling if the pattern is predictable and
// the saving is material. Modes can be switched, with a cooldown.
//
// aws dynamodb update-table --table-name Commerce \
// --billing-mode PROVISIONED \
// --provisioned-throughput ReadCapacityUnits=500,WriteCapacityUnits=200
// ==================================================================
// HOT PARTITIONS: the characteristic problem.
// ==================================================================
// Throughput is ultimately PER PARTITION, and a partition has limits
// (~3,000 RCU / ~1,000 WCU). So a skewed partition key THROTTLES
// WHILE THE TABLE IS FAR BELOW ITS PROVISIONED CAPACITY.
//
// provisioned: 10,000 WCU
// consumed (table): 1,200 WCU <- metrics look HEALTHY
// ThrottledRequests: 4,208 <- and yet
//
// That gap is the confusing part, and it is the whole diagnosis.
// BAD: everything under one key.
// PK: "ORDERS" SK: "2026-11-30T09:14:00Z#o-55"
// BAD: a monotonic key.
// PK: "DATE#2026-11-30" all of today's writes, one partition
// WRITE SHARDING: the design fix.
const SHARDS = 20;
const shard = Math.floor(Math.random() * SHARDS);
await db.send(new PutCommand({ TableName: "Commerce", Item: {
PK: `ORDERS#2026-11-30#${shard}`, // <- spread across 20
SK: `${new Date().toISOString()}#o-55`,
entityType: "Order"
}}));
// Reading means querying all N shards and merging - N queries in
// parallel instead of one. That is the trade, and it is worth it:
const results = await Promise.all(
Array.from({length: SHARDS}, (_, i) => db.send(new QueryCommand({
TableName: "Commerce",
KeyConditionExpression: "PK = :pk",
ExpressionAttributeValues: {":pk": `ORDERS#2026-11-30#${i}`}
})))
);
// ADAPTIVE CAPACITY shifts capacity toward hot partitions
// automatically, and can ISOLATE a very hot item onto its own
// partition. It is instantaneous now rather than taking minutes, and
// it is genuinely effective. It CANNOT EXCEED THE PER-PARTITION
// CEILING, so a single extremely hot key still throttles. Sharding
// is still the answer for that.
// ==================================================================
// DIAGNOSING THROTTLING. Make the right distinction.
// ==================================================================
// CloudWatch:
// ThrottledRequests, ReadThrottleEvents, WriteThrottleEvents
// ConsumedReadCapacityUnits vs ProvisionedReadCapacityUnits
// SuccessfulRequestLatency
// OnlineIndexThrottleEvents <- a GSI's OWN capacity
//
// CONTRIBUTOR INSIGHTS - the useful one. It NAMES the most-accessed
// partition keys:
// aws dynamodb update-contributor-insights --table-name Commerce \
// --contributor-insights-action ENABLE
//
// THE DISTINCTION:
// consumed ~= provisioned AND throttling
// -> capacity is genuinely too low. RAISE IT.
// consumed << provisioned AND throttling
// -> ONE PARTITION IS HOT. Raising capacity DOES NOT HELP.
// CHANGE THE KEY.
//
// Treating the second as the first means paying for capacity that
// does nothing. It is the most common DynamoDB misdiagnosis.
//
// Also: a GSI has its OWN capacity, and A THROTTLED GSI THROTTLES
// WRITES TO THE BASE TABLE. An under-provisioned index stops your
// writes, which is a surprising failure path.
// ==================================================================
// The other techniques, each measured.
// ==================================================================
// BatchGetItem: 100 items or 16 MB per call, ONE round trip.
await db.send(new BatchGetCommand({ RequestItems: { Commerce: {
Keys: [ {PK:"PRODUCT#SKU-001", SK:"META"},
{PK:"PRODUCT#SKU-044", SK:"META"} ],
ProjectionExpression: "PK, SK, #nm, unitPrice",
ExpressionAttributeNames: {"#nm": "name"}
}}, ReturnConsumedCapacity: "TOTAL" }));
// UnprocessedKeys must be RETRIED WITH BACKOFF, or you silently get
// partial results. Same trap as BatchWriteItem.
// PARALLEL SCAN, for a legitimate full-table job (an export, a
// migration) - never for a user-facing query:
await Promise.all(Array.from({length: 8}, (_, i) =>
db.send(new ScanCommand({
TableName: "Commerce", Segment: i, TotalSegments: 8,
ProjectionExpression: "PK, SK" // project: cost is per KB READ
}))
));
// ==================================================================
// THE COST MODEL. From measured capacity, not from guesses.
// ==================================================================
// reads RCU/s x hours x $/RCU-hour (provisioned)
// or requests x $/million (on-demand)
// writes WCU/s, same
// INDEX WRITES one per matching index, per item write
// <- the line people forget
// storage GB-month, INCLUDING every index's copy
// stream reads per 100,000 read requests
// backup storage on-demand backups, GB-month
// PITR GB-month, SEPARATE from backups
// global tables REPLICATED WRITES ARE BILLED AGAIN,
// per region, plus cross-region transfer
// data transfer out of the region
//
// Build it from your ConsumedCapacity measurements and project to
// 10x and 100x. A DynamoDB design you cannot price is a design you
// have not finished.
Open this example in the editor and change it. Nothing you type is saved.
Discussion
No questions on this topic yet. Sign in to ask the first one.