Ravindra BagaleCourses & study guides मराठी Track your progress

DynamoDB On-Demand vs Provisioned Capacity, Auto Scaling and Cost

Intro mentioned on-demand vs provisioned briefly. Jakarta startup CTO Budi Santoso flipped to provisioned without auto scaling and melted on launch day. This chapter is capacity modes, auto scaling, reserved capacity and cost math. Intro link: What Is DynamoDB?.

What you'll learn in this chapter

  • Explain with an everyday story
  • Apply Why/What/How
  • Read commands with output+meaning
  • Map across industries
  • Finish lab + cleanup

1. Everyday example: buffet vs thali coupons

On-demand is a buffet — pay for what you eat, great when unsure. Provisioned is buying thali coupons (RCU/WCU) ahead — cheaper when steady, painful if you buy too few. Auto scaling adjusts coupons. Reserved capacity is a bulk discount for predictable load.

2. Vertical steps

Why -> What -> How -> Lab -> CleanupWhyWhatHowLabCleanup
Cleanup labs

3. Why do we need this?

Why do we need this?

Wrong mode causes either throttling or surprise bills. Teams need a deliberate choice and alarms on cost and throttles.

4. What is it?

What is it?

PAY_PER_REQUEST (on-demand) bills per request units. PROVISIONED sets RCU/WCU with optional auto scaling. Reserved capacity discounts steady provisioned usage.

5. How to do it (step by step)

How to do it (step by step)

  1. Start on-demand for new/spiky apps.
  2. Move to provisioned when steady 24/7.
  3. Enable auto scaling with sane target %.
  4. Alarm on ThrottledRequests and estimated cost.
  5. Review reserved capacity quarterly.

6. Simple cost intuition

On-demand: pay per million request units + storage. Provisioned: pay for RCU/WCU hours even if idle. Scans and large items multiply cost.

7. Auto scaling notes

Application Auto Scaling on DynamoDB table and indexes. Set min/max WCU/RCU. Scale-out faster than scale-in by design.

8. Commands with output and meaning

aws dynamodb describe-table --table-name lab-dda-shop --query 'Table.BillingModeSummary'
# Output: BillingMode PAY_PER_REQUEST (or PROVISIONED)
aws dynamodb update-table --table-name lab-dda-shop --billing-mode PROVISIONED \
  --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5
# Output: TableStatus UPDATING. Meaning: now you own 5 RCU/WCU — add autoscaling next for production.

describe shows mode. update-table can switch modes (with limits). Lab: keep on-demand unless practicing autoscaling.

9. Industry stories

  • SaaS (Priya Nair): on-demand until traffic baseline known.
  • Bank batch (Lucas Meyer): provisioned + autoscaling for night jobs.
  • Gaming launch (Carlos): on-demand launch week, then tune.
  • IoT (Mei Lin): provisioned with high write autoscaling.
  • Clinic (Meera Kulkarni): tiny on-demand — bill noise smaller than ops time.

10. Lab

How to do it (step by step)

  1. describe BillingMode; optionally switch to provisioned 5/5; switch back to on-demand.
  2. Set a budget alert INR/USD.
  3. Delete lab table.

Cleanup (stop billing)

  1. Delete lab tables/indexes/triggers.
  2. Confirm describe-table fails or status missing.

11. Access-pattern workshop (paper first)

  1. List every screen or API that reads or writes data.
  2. For each: write the exact key lookup or query shape in plain English.
  3. Mark 1:1, 1:many, many:many relationships.
  4. Circle anything that needs a sort range (time, status, score).
  5. Only then invent PK/SK and optional GSI keys.
  6. Estimate peak items per partition key per second.
  7. Write one sample item JSON for each entity type.
  8. Peer-review with someone who did not design it.

12. Copy-paste DynamoDB CLI starters

# Region habit for this series
export AWS_DEFAULT_REGION=ap-south-1

# Describe + sample
aws dynamodb describe-table --table-name ShopApp
aws dynamodb scan --table-name ShopApp --max-items 3

# Query by PK (replace names)
aws dynamodb query --table-name ShopApp   --key-condition-expression "PK = :pk"   --expression-attribute-values '{":pk":{"S":"USER#u123"}}'

# On-demand capacity mode check
aws dynamodb describe-table --table-name ShopApp   --query 'Table.BillingModeSummary'

# Streams status
aws dynamodb describe-table --table-name ShopApp   --query 'Table.StreamSpecification'

13. More industry stories

  • Retail (Aisha Khan, Dubai): single-table cart+orders; PK=USER#id keeps each shopper hot path local.
  • Gaming (Carlos Rivera, Mexico City): leaderboard uses sparse GSI on score; write shard on hot gameId.
  • IoT (Mei Lin, Shenzhen): sensor#day PK + timestamp SK; TTL 30 days keeps storage flat.
  • Healthcare (Rohan Deshmukh, Pune): appointment slots use conditional Put — no double book.
  • Fintech (Elena Petrova, Warsaw): Streams fan-out to audit table; never update audit in place.
  • Travel (Omar Haddad, Amman): global tables for read-local catalog; writes region-sticky for inventory.

14. Glossary (short)

TermMeaning
PK / Partition keyHash key that places the item in a partition
SK / Sort keyOrders items inside a partition; enables ranges
Item collectionAll items that share the same PK
GSIGlobal Secondary Index — alternate PK/SK, own partitions
LSILocal Secondary Index — same PK, different SK
RCU / WCURead/Write Capacity Units on provisioned mode
Conditional writeWrite succeeds only if a condition is true
Stream view typeKEYS_ONLY / NEW_IMAGE / OLD_IMAGE / NEW_AND_OLD_IMAGES

15. Practice: explain out loud

  1. 60s: why access patterns come before table design.
  2. 60s: hot partition and one fix (write sharding).
  3. 60s: GSI vs LSI in one breath.
  4. 60s: on-demand vs provisioned for a startup.
  5. 60s: optimistic locking with a version attribute.
  6. 60s: Streams + Lambda for an audit trail.
  7. Record once; cut filler; record again.

16. Safe lab hygiene

  • Use ap-south-1 labs with a budget alert (₹/USD).
  • Prefix lab tables with lab- and your initials.
  • Prefer on-demand for tiny labs unless you are learning auto scaling.
  • Delete tables and Lambda triggers after the lab.
  • Never point Streams consumers at production without a DLQ.
  • Tag every resource Owner + Expiry.

18. Single-table sketch pad

Write entities as rows in one mental table before you open the console. Example for a small shop: USER#, ORD#, ORD#|ITEM#, PROD# under carefully chosen PK/SK.

EntityPKSKExample attrs
UserUSER#u1PROFILEname, city
OrderUSER#u1ORD#2026-10-31#o9total, status
Order itemORD#o9ITEM#sku1qty, price
ProductPROD#sku1METAtitle, stock

19. Ten oral drill questions

  1. What is an access pattern?
  2. Why overload PK with entity prefixes?
  3. Name one hot-partition symptom.
  4. Sparse GSI means what?
  5. When is LSI impossible after create?
  6. On-demand bills for what?
  7. What does attribute_not_exists do?
  8. NEW_AND_OLD_IMAGES costs more — why still pick it?
  9. How do you stop a poison Streams message loop?
  10. Which existing chapter do you open for PutItem syntax?

20. Capacity and throttle drill

  1. Open CloudWatch for your table: ConsumedReadCapacityUnits, ConsumedWriteCapacityUnits, ThrottledRequests.
  2. Note whether BillingMode is PAY_PER_REQUEST or PROVISIONED.
  3. If provisioned, write current RCU/WCU and autoscaling min/max.
  4. Name your hottest expected PK in one sentence.
  5. Write one mitigation: shard, cache, or redesign.
  6. Set or verify a budget alert for DynamoDB.
  7. Check GSI list and whether each is still used.
  8. Confirm Streams enabled only where consumers exist.

21. Condition expression cheatsheet

# Create-once
attribute_not_exists(PK)

# Optimistic lock
version = :v

# Stock / seat
stock > :zero
#status = :free

# Combine
attribute_not_exists(PK) AND #type = :user

Meaning: conditions are the seatbelt for concurrent writers. Put them on every race-prone update. Full SDK samples stay in the SDK chapter — here we only list the expressions you will reuse.

22. Streams consumer checklist

  • View type matches need (KEYS_ONLY vs NEW_AND_OLD).
  • Lambda has DLQ and retry policy.
  • Handler idempotent on eventID or keys.
  • IteratorAge alarm before users feel lag.
  • No accidental write-loop back into the same table without markers.
  • Fan-out via SNS/EventBridge when >1 consumer team.
  • Disable stream when lab ends.
  • Ch1 Modeling -> Ch2 Hot keys -> Ch3 GSI/LSI -> Ch4 Capacity -> Ch5 Transactions -> Ch6 Streams.
  • Always link intro + CRUD + CLI + SDK instead of rewriting Put/Get.
  • Projects P1-P7 come in later batches and reuse these ideas.

24. Extra oral drills

  1. Explain single-table to a product manager in 45 seconds.
  2. Draw PK/SK for a chat thread on a whiteboard.
  3. Name three CloudWatch metrics for DynamoDB pain.
  4. Say when you would refuse a new GSI request.
  5. Describe one transaction for seat + payment record.
  6. Explain why Streams are at-least-once.
  7. Convert a Scan-based feature request into a Query design.
  8. List cleanup steps after a DynamoDB lab.

25. Teacher story: the notebook that became a database

Ravindra once watched a shop keep every customer, order and payment in one paper notebook. Finding last Tuesday's unpaid bills meant flipping pages. DynamoDB single-table thinking is that notebook done carefully: one place, clear labels (PK/SK), and an index tab (GSI) only when a second way to find rows is worth the cost. Do not photocopy the notebook into ten unrelated books unless the shop truly has ten separate businesses.

When Meera (clinic), Omar (travel), and Aisha (retail) design together, they still start on paper: screen list, key sketch, sample JSON, peer review. Console clicks come last. That ritual is why this deep series links the intro and CRUD chapters instead of rewriting PutItem on every page.

26. Sixteen mini tasks (self-check, leak-free)

  1. Write three access patterns for a cart app in one minute.
  2. Invent PK/SK for user profile and orders under that user.
  3. Name one hot-partition anti-pattern.
  4. Explain write sharding to a teammate in 40 seconds.
  5. Say GSI vs LSI without notes.
  6. Pick KEYS_ONLY or ALL for a sparse open-orders index — why?
  7. Choose on-demand or provisioned for a weekend flash sale.
  8. List five DynamoDB bill line-item types.
  9. Write a create-once condition in words.
  10. Describe optimistic locking with a version attribute.
  11. When do you wrap two writes in a transaction?
  12. Pick a stream view type for an audit log — justify.
  13. Name two Stream consumer safety rules.
  14. What CloudWatch metric shows stream lag?
  15. Which linked chapter has PutItem CLI syntax?
  16. Write your lab cleanup checklist (table, stream, lambda, alarms).

27. Marathi classroom lines (say out loud)

  • Access patterns आधी, keys नंतर — हे mantra आठवा.
  • Hot partition म्हणजे एक PK वर गर्दी — shard किंवा redesign.
  • GSI लवचिक; LSI create-time — चुकीचा index महाग.
  • On-demand म्हणजे वापरल्यावर पैसे; provisioned म्हणजे आरक्षित units.
  • Condition आणि transaction म्हणजे race साठी seatbelt.
  • Streams at-least-once आहे — handler idempotent ठेवा.

28. Hindi bridge lines

  • Pehle access patterns likho, baad mein PK/SK.
  • Hot partition ek key par zyada load.
  • GSI kabhi bhi; LSI table banate waqt.
  • On-demand spike ke liye; provisioned steady ke liye.
  • Transaction = sab milkar ya kuch nahi.
  • Streams duplicate de sakte hain — idempotent likho.

29. Common errors and fixes

Each row is a real mistake students and juniors hit. Read the fix before you panic.

Error / symptomFix
Provisioned without autoscalingEnable autoscaling.
On-demand blamed for hot keysFix keys first.
No cost alarmBudget + CW.
Reserved for spiky appsReserved needs steady.
Forgotten GSI capacityScale GSIs too.
Switching modes during peakSwitch off-peak.
RCU math ignoring eventually consistentEC reads cheaper.
Lab left on high provisionedBack to on-demand/delete.
Ignoring storage costsWatch item size growth.

30. Troubleshooting checklist

  1. Throttles on provisioned: raise WCU/RCU or fix hot key.
  2. Bill spike on-demand: check Scan/traffic surge.
  3. Autoscaling lag: warm with pre-provision.
  4. GSI throttles separately.
  5. Mode update stuck: wait UPDATING.

31. FAQ

Q. Should I always use a single table?

Often yes for related access patterns; not a religion. Separate tables are fine for unrelated domains or different capacity/security needs.

Q. Do I still need RDS?

Yes for heavy joins, multi-row SQL reports, and strong relational constraints. See the intro DynamoDB vs RDS chapter.

Q. Is Scan evil?

Scan is a tool for rare admin jobs and small tables. Design so hot paths use Query/GetItem.

Q. Where are Put/Get command details?

In the CRUD survey, CLI and SDK chapters — this deep set links them instead of copying.

Q. On-demand vs provisioned?

Pay-per-request vs set RCU/WCU.

Q. Autoscaling?

Adjusts provisioned toward target utilization.

Q. Reserved?

Discount for steady provisioned.

Q. Lab default?

On-demand.

32. Interview Q&A

Q. (B) Which mode for unknown traffic?

On-demand.

Q. (B) RCU?

Read capacity unit.

Q. (M) When provisioned?

Steady predictable load.

Q. (M) Autoscaling target?

Often ~70% utilization starting point.

Q. (S/MNC) Cost governance?

Budgets, tags, mode policy, quarterly review.

Q. (MNC) Launch week plan?

On-demand or pre-warm provisioned; page on throttles.

33. Tips in English, Marathi and Hindi

Ravindra Bagale's Tip (EN)

Pick mode from traffic shape, not habit.

Ravindra Bagale's Tip (MR)

Traffic shape ने mode.

Tip (HI)

आदत से नहीं, traffic से mode चुनो।

Try at home

  1. Sketch 24h traffic for your app.
  2. Choose a mode + alarm list.
  3. Read intro capacity paragraph once.

In short

  1. On-demand for spiky/unknown.
  2. Provisioned+AS for steady.
  3. Reserved only if steady.
  4. Alarm cost and throttles.

Revision, interview and comparison cards

Revise this lesson in a few minutes. Save the cards on your phone or download them as PNG files. The QR code on each card opens this lesson.

Revision card: On-demand vs provisioned. Wrong mode surprises either the bill or the throttle graph. On-demand = pay per request; provisioned = set RCU/WCU (+ auto scaling). Spiky/unknown → on-demand; steady → provisioned + AS; reserved if committed. Rohan Deshmukh starts labs on-demand and revisits after a week of metrics.
Revision card: On-demand vs provisioned · Download PNG · Open card page
Revision card: DynamoDB cost map. Teams only watch WCU and miss GSI, PITR, Streams, storage. Table+GSI storage, reads/writes, Streams, backups/PITR, DAX, export. Enable budget alert → tag Owner/Expiry → delete lab tables same day. Sana Iqbal posts a weekly DynamoDB cost screenshot in Slack.
Revision card: DynamoDB cost map · Download PNG · Open card page
Comparison: On-demand vs Provisioned. On-demand: Bill consumed RRU/WRU. Provisioned: Set RCU/WCU (+ AS).
Comparison: On-demand vs Provisioned · Download PNG · Open card page
Comparison: Auto scaling vs Reserved capacity. Auto scaling: Min/max around target utilization. Reserved capacity: Commitment discount for steady provisioned.
Comparison: Auto scaling vs Reserved capacity · Download PNG · Open card page
Interview card: On-demand or provisioned?. Decision. Spiky/unknown → on-demand; steady predictable → provisioned + AS. Revisit with metrics.
Interview card: On-demand or provisioned? · Download PNG · Open card page
Interview card: What does auto scaling do?. Mechanism. Moves provisioned RCU/WCU toward a utilization target within min/max. Does not fix a hot partition alone.
Interview card: What does auto scaling do? · Download PNG · Open card page
Interview card: What is on the DynamoDB bill?. FinOps. Storage, RRU/WRU or RCU/WCU, GSI, Streams, backups/PITR, DAX. Budget alert + tags.
Interview card: What is on the DynamoDB bill? · Download PNG · Open card page
Interview card: Throttle on provisioned — why?. Troubleshoot. Exceeded capacity or hot key; check metrics and Insights. Scale, shard, or switch mode with a plan.
Interview card: Throttle on provisioned — why? · Download PNG · Open card page

More cards: Ravi Sir's Cards.

Practice Tasks

About this scenario

Amravati Agro Market is a agriculture business in Amravati. Anjali Thakre looks after its IT and cloud work. They count money in INR and run their AWS resources in the ap-south-1 Region. In the tasks below you do real jobs for them using what this lesson teaches. All names, account IDs, IP addresses and numbers are made up for practice.

0 / 16

Easy On-demand pays per request — 1

Why: Mode.

What to do: Enter 1 if on-demand bills for consumed request units.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Easy Provisioned sets RCU/WCU — 1

Why: Mode.

What to do: Enter 1 if provisioned mode sets RCU and WCU.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Easy Auto scaling adjusts provisioned — 1

Why: AS.

What to do: Enter 1 if auto scaling adjusts provisioned capacity toward a target.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Easy Reserved capacity needs steady load — 1

Why: Commit.

What to do: Enter 1 if reserved capacity fits steady provisioned workloads.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Easy Describe table billing mode

Why: CLI.

What to do: Describe table ShopApp

How:
  1. Read the task and decide which AWS service it is about.
  2. Write aws, then the service name, then the operation (the action word).
  3. Add each needed flag (--name) followed by its value from the task.
  4. Flags can be in any order. Click Check answer.

Easy Mode pick YAML

Why: Choose.

What to do: YAML: spiky: on-demand, steady: provisioned.

How:
  1. Start from the top-level keys the task names.
  2. Indent child keys with 2 spaces (no tabs).
  3. Fill in each property with the value from the task.
  4. Click Check answer. Key order does not matter.

Easy PAY_PER_REQUEST is on-demand — 1

Why: Name.

What to do: Enter 1 if PAY_PER_REQUEST means on-demand billing mode.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Medium Spiky traffic often starts on-demand — 1

Why: Choice.

What to do: Enter 1 if unknown spiky traffic often starts on on-demand.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Medium Throttle if over provisioned — 1

Why: Symptom.

What to do: Enter 1 if exceeding provisioned (or hot keys) causes throttles.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Medium Bill includes storage and indexes — 1

Why: Cost.

What to do: Enter 1 if cost includes table+GSI storage, reads/writes, streams, backups.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Medium Mode switches need a plan — 1

Why: Change.

What to do: Enter 1 if switching capacity modes needs monitoring and a plan.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Medium Metrics list YAML

Why: CW.

What to do: YAML list metrics with ConsumedReadCapacityUnits and ThrottledRequests.

How:
  1. Start from the top-level keys the task names.
  2. Indent child keys with 2 spaces (no tabs).
  3. Fill in each property with the value from the task.
  4. Click Check answer. Key order does not matter.

Hard Budget alerts catch surprises — 1

Why: FinOps.

What to do: Enter 1 if budget alerts help catch surprise DynamoDB spend.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Hard Intro has a short mode note — 1

Why: Complement.

What to do: Enter 1 if the intro chapter has a short modes note this chapter deepens.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Hard GSI capacity can throttle separately — 1

Why: Index.

What to do: Enter 1 if GSIs can throttle on their own capacity in provisioned mode.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.

Hard Labs prefer on-demand usually — 1

Why: Hygiene.

What to do: Enter 1 if tiny labs usually prefer on-demand unless learning auto scaling.

How:
  1. Write down the numbers the task gives you.
  2. Work it out step by step on paper.
  3. Type only the final answer in the box.
  4. Click Check answer.