Learning pathsPricingChecking sign-in…
Key Technologies

DynamoDB

DynamoDB is a managed key-value/document database whose efficient access depends on known partition and sort key patterns.

What, why, when and how

What is it?

DynamoDB is a managed key-value and document database organized around primary keys, optional sort keys and secondary access paths.

Why is it needed?

Known key-based workloads need scalable low-latency access without operating database servers directly.

When should I use it?

Use it when requests map to bounded key queries and conditional writes or supported transactions can enforce the needed state changes.

When should I choose something else?

Avoid modeling around routine full-table scans or arbitrary joins. Secondary indexes have their own consistency and capacity implications.

How do I use it?

List access patterns, design partition and sort keys, estimate hot-key pressure, use conditional mutations and define index propagation expectations.

Can you show a concrete example?

A lease record is updated only if its prior version or ownership condition matches. A new owner receives a higher epoch, and the downstream resource must enforce that epoch if stale owners can still issue effects.

Lease record has owner A and epoch 9; Conditional claim grants B epoch 10; Protected sink rejects writes carrying epoch 9
DynamoDB: one concrete example
Read the diagram

Lease record has owner A and epoch 9; Conditional claim grants B epoch 10; Protected sink rejects writes carrying epoch 9

Open original
DynamoDB: worked example
Lease record has owner A and epoch 9; Conditional claim grants B epoch 10; Protected sink rejects writes carrying epoch 9

DynamoDB: one concrete example

Follow the detailed diagrams below to trace the additional state changes and failure cases behind these answers.

DynamoDB is a managed key-value/document database whose efficient access depends on known partition and sort key patterns. A schema should be derived from queries, item-size and throughput constraints, and transaction needs. It is not a relational database with arbitrary joins hidden behind a different syntax.

Read the keys that a Query actually visits

Use a query-shaped table with PK=TENANT#t1#RECIPIENT#r7 and sort keys DELIVERY#2026-10-11T12:03#d93, ...#d91, ...12:02#d90. A Query selects this partition key and an applicable sort-key condition. GetItem selects a complete primary key; Scan reads across the chosen table/index scope. A filter removes results after reading the matching input items and is not a free substitute for a selective key.

Contract / pseudocode
base delivery d91: version=4, state=queued
conditional claim: version=4 AND state=queued
winner: version=5, state=claimed
loser: conditional failure; reread/resolve
GSI entry may still show version=4
base delivery d91: version=4, state=queued; conditional claim: version=4 AND state=queued; winner: version=5, state=claimed; loser: conditional failure; reread/resolve; GSI entry may still show version=4
Read the keys that a Query actually visits
Read the diagram

base delivery d91: version=4, state=queued; conditional claim: version=4 AND state=queued; winner: version=5, state=claimed; loser: conditional failure; reread/resolve; GSI entry may still show version=4

Open original
Read the keys that a Query actually visits
base delivery d91: version=4, state=queued; conditional claim: version=4 AND state=queued; winner: version=5, state=claimed; loser: conditional failure; reread/resolve; GSI entry may still show version=4

Read the keys that a Query actually visits

A GSI supports another partition/sort access pattern and propagates asynchronously; strongly consistent GSI reads are not available. A local secondary index shares the base partition key and has different creation/size/consistency constraints. A strong base-table read does not synchronize every derived index or external view. Transactions can coordinate supported item sets, with scope and cost constraints; an external provider remains a separate effect.

Capacity and price depend on bytes, operation type, consistency and transaction/index work. Round item sizes according to the selected service's current billing units; do not budget only the response payload after a filter. On-demand capacity still has limits, hot-key behavior and cost. Streams offer a retained change-feed contract, not arbitrary permanent event history. DAX is a cache with its own path and freshness boundary.

Show answer and explanation

Answer: Seeing queued in a GSI cannot authorize a claim; the conditional write at the base owner decides. A conditional failure is an expected conflict, not a reason to replay the provider call with a new identity.

Step-by-step reasoning

1. 1 · Frame

List read/write patterns with frequency and required consistency. Design partition keys that distribute traffic and sort keys that support bounded range queries. A tenant-only key may create a hot partition for a very large tenant; adding a time bucket or shard suffix spreads work but makes cross-bucket reads and writes more complex.

2. 2 · Model

Single-table designs can place multiple entity types under partition/sort keys and use prefixes for access patterns. Secondary indexes provide alternate lookups with their own projection and propagation properties. Conditional writes enforce per-item invariants; transactions group supported items but add limits and cost. Keep item sizes and request units within service constraints for the selected deployment.

3. 3 · Scale

Use strongly consistent reads only where the access path and operation require them and support that mode; otherwise define eventual freshness. Global tables and cross-region behavior need explicit conflict and replication expectations. Hot keys should be measured by partition activity and throttling. Use adaptive capacity thoughtfully, not as a substitute for a skew-aware key design.

4. 4 · Recover

Retries after a timeout may have written the item. Conditional expressions and transaction request tokens, where applicable, can make retries safer within the documented semantics. Handle throttling with backoff and jitter, and do not immediately fan out more workers. Reconcile multi-item workflows whose external side effects are outside a DynamoDB transaction.

Contracts and state

The following sketch makes the decision boundary concrete. Field names and capacity assumptions are illustrative; adapt them to the stated product contract.

Contract / pseudocode
PK = TENANT#42, SK = ORDER#2026-10-08#o17
GSI1PK = USER#u9, GSI1SK = ORDER#created#o17
Conditional update: version = expected_version
Transaction: bounded set of related item operations
Hot-tenant alternative: shard suffix + explicit query fan-out

Worked example

An orders screen asks for one tenant’s 50 newest orders. A tenant/order partition with a sortable timestamp supports a bounded query. If one tenant becomes exceptionally hot, shard its key across a small number of buckets and query each bucket, then merge 50 candidates. The extra read fan-out is an explicit cost of distributing writes.

Failure walkthrough

A conditional update times out. Repeating it without a stable request identity may increment a balance twice. Use a condition/version or idempotency item in the same supported transaction, then resolve ambiguous outcomes by reading the authoritative item. A global secondary index may lag; do not use its result as the sole authority for a uniqueness invariant.

Tenant traffic grows hot → Add bounded key buckets → Write to stable shard → Query each bucket → Merge ordered page
DynamoDB · scenario walkthrough
Read the diagram

Tenant traffic grows hot → Add bounded key buckets → Write to stable shard → Query each bucket → Merge ordered page

Open original
DynamoDB · scenario walkthrough
Tenant traffic grows hot → Add bounded key buckets → Write to stable shard → Query each bucket → Merge ordered page

DynamoDB · scenario walkthrough

Decisions and trade-offs

MechanismBenefitLimit
Partition/sort keysPredictable key queriesAccess-pattern specific
GSIAlternate lookupExtra write/storage and propagation
Condition expressionAtomic item predicateScope is defined by item key
TransactionRelated item atomicityBounded actions and added cost

Check your understanding

How would you make a hot tenant’s recent-order query scale, and what query cost does that introduce?

Show answer and explanation

Answer: Add a bounded shard/bucket dimension for writes, query the relevant buckets in parallel, and merge ordered results. This distributes hot writes but introduces fan-out, merge work, and more complex pagination. If measured traffic does not justify it, retain the simpler tenant key.

Primary documentation

Read the first-party engineering account or official technical reference. Company engineering posts describe the scope and date of that publication; the interview reconstruction and scenarios here are original teaching examples.

Continue the connection

Study Data Modeling and explain which guarantee from this lesson carries into that topic.

Model the query and conditional write together

Choose partition and sort keys from access patterns. An item collection for one account can colocate profile, orders and state under one partition key with distinct sort-key prefixes. This can simplify queries but requires deliberate size and traffic distribution. A scan is not a substitute for a missing access pattern at scale.

Conditional expressions enforce version checks or absence at the write boundary. Transactions support coordinated item operations within their documented limits, while secondary indexes provide additional access paths with their own consistency and capacity behavior. Do not assume a global secondary index is an immediately current authority for uniqueness.

TTL is asynchronous cleanup, not an exact lease-expiry scheduler. Read the expiry value when deciding whether ownership is still valid. Hot partition keys remain hot under on-demand capacity; adaptive behavior does not remove every per-key or partition constraint. Store stable request IDs and compare-and-set generations for retryable work.

A decision worksheet for DynamoDB: read the mechanism and its guarantee together.
A decision worksheet for DynamoDB: read the mechanism and its guarantee together.
Read the diagram

Mechanism / Benefit / Limit; Partition/sort keys / Predictable key queries / Access-pattern specific; GSI / Alternate lookup / Extra write/storage and propagation; Condition expression / Atomic item predicate / Scope is defined by item key; Transaction / Related item atomicity / Bounded actions and added cost

Open original
DynamoDB choices for this workload
A decision worksheet for DynamoDB: read the mechanism and its guarantee together.

A decision worksheet for DynamoDB: read the mechanism and its guarantee together.

Operational sketch

Contract / pseudocode
PK = TENANT#42; SK = JOB#17
state=running; generation=8; expires_at=...
conditional update: generation = :expected
unique operation item: attribute_not_exists(PK)
query by key; avoid full-table scan

A tempting mistake

An expired item can still exist until cleanup runs. Treat expiration as business data during conditional decisions, not as proof that the database has removed the item.

Transfer exercise

Can a GSI lookup followed by PutItem guarantee uniqueness?

Show answer and explanation

Answer: No. Concurrent or not-yet-visible index updates can both pass the lookup. Use an authoritative conditional write on a canonical uniqueness key.

Your study notes