Stop 09 · Databases on AWSTopics · 8/11

DynamoDB Capacity Modes

Part of the AWS Roadmap

In short

A Lambda that scales from zero to thousands is wasted if your database sits on one fixed-size server. On-demand databases scale and bill per request too, so the whole stack moves together.

On-demand capacity mode charges per request and scales automatically, which suits unpredictable traffic and new apps. Provisioned mode lets you set read and write capacity units, optionally with auto scaling, which can be cheaper for steady, predictable traffic.

The blob character collects a stack of copies from a photocopy machine at a shop counter.

Think of it like this

The college photocopy shop

You don't buy a photocopier for your notes. You pay per page at the shop by the gate. The night before exams, the queue is long but the shop just runs more machines. On-demand capacity is paying per page.

Watch it happen

Reads and writes, billed per request

Lambda
DynamoDB
Bill meter

PutItem order#7

1/6A write. No capacity was reserved; the table simply accepts it.

The big ideas

What you need to know

Two billing modes

On-demand bills per request. Provisioned means you set read and write capacity, cheaper for steady, predictable load.

Design for keys

Serverless doesn't fix bad keys. Pick partition keys with many distinct values so load spreads out.

No connection pool

DynamoDB is an HTTPS API, so thousands of functions don't exhaust connections like they can with Postgres.

Other options

Aurora Serverless v2, Firestore and Cosmos DB serverless also scale with use, each with its own trade-offs.

See it in code

Walk through the code

bash
1aws dynamodb create-table \2  --table-name Orders \3  --attribute-definitions AttributeName=userId,AttributeType=S \4                          AttributeName=orderId,AttributeType=S \5  --key-schema AttributeName=userId,KeyType=HASH \6               AttributeName=orderId,KeyType=RANGE \7  --billing-mode PAY_PER_REQUEST

1/3Declare only the key attributes. Other fields are free-form per item.

PAY_PER_REQUEST is on-demand mode. No --provisioned-throughput needed.

Save yourself the pain

Common mistakes

Oops

Running a big Scan from a Lambda on every request.

Do this instead

Scans read the whole table and bill for all of it. Query by key or add a secondary index.

Oops

Picking on-demand forever for a table with flat, high traffic.

Do this instead

Review the bill. Steady load is often cheaper on provisioned capacity with auto scaling.

Your mission

Pay-per-page table

~25 min

Quick check

Why does DynamoDB pair well with Lambda compared to a classic relational database?

Go deeper

  1. 1Read how read and write capacity units are calculated from item size.
  2. 2Switch a test table between modes and note the restrictions on how often you can switch.
  3. 3Decide which mode fits a college fest registration app with one big traffic spike.

More topics at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge