These DynamoDB interview questions cover keys, GSIs, capacity modes, single-table design, and the AWS SDK for JavaScript v3 in Node.js.
15 DynamoDB Interview Questions with Answers
Use the short version first, then offer trade-offs if the interviewer wants depth.
1. What is DynamoDB and when would you choose it over RDS?
DynamoDB is a fully managed, horizontally scaled key-value/document database with single-digit millisecond latency at high scale. Choose it for flexible schema, massive throughput, and serverless ops. Choose RDS when you need complex joins, ad hoc SQL analytics, or strong relational constraints as first-class features.
2. Explain partition keys and sort keys.
The partition key determines which physical partition stores the item via hashing. An optional sort key orders multiple items under the same partition key, enabling Query with begins_with and between. Together they form the primary key; GetItem and Query on the primary key are the most efficient operations.
3. What is a Global Secondary Index (GSI)?
A GSI projects an alternate partition and sort key, letting you query a different access pattern—e.g., items by status instead of by userId. GSIs have their own throughput and eventually consistent reads by default. You pay storage for projected attributes and must plan for throttling separately from the base table.
4. What is the difference between Query and Scan?
Query reads items sharing a partition key (and optional sort condition)— efficient and cheap. Scan reads every item in a table or index— expensive and slow at scale. Interviews expect you to redesign access patterns with GSIs rather than relying on Scan in production hot paths.
5. Compare on-demand vs provisioned capacity.
On-demand bills per request with no capacity planning—ideal for new or unpredictable workloads. Provisioned sets RCU/WCU (or auto-scaling targets) and costs less at steady, predictable traffic. Throttling occurs when consumed capacity exceeds limits; handle with exponential backoff and retries in the SDK.
6. What is a hot partition and how do you avoid it?
A hot partition occurs when too many requests hit one partition key—e.g., monotonically increasing timestamps or a status flag with low cardinality. Mitigate with high-cardinality keys, write sharding (append random suffix then query aggregate), or splitting write-heavy keys across synthetic buckets.
7. What is single-table design?
Single-table design stores multiple entity types in one table using composite PK/SK patterns like USER#123 and ORDER#456#ITEM#789. Related records share partition keys for efficient Query batches. It trades normalization for access-pattern optimization and requires upfront modeling discipline and GSIs for alternate lookups.
8. How do you perform conditional writes in DynamoDB?
Use ConditionExpression on PutItem, UpdateItem, or DeleteItem—e.g., attribute_not_exists(PK) for create-if-not-exists or version = :expected for optimistic locking. ConditionalCheckFailedException means another writer won; retry or surface conflict to the user. This is the primary concurrency control mechanism.
9. How do you use the AWS SDK v3 DynamoDB client in Node.js?
Create DynamoDBClient with region, wrap with DynamoDBDocumentClient from @aws-sdk/lib-dynamodb for native JS types. Use commands like GetCommand, QueryCommand, PutCommand with marshall/unmarshall handled for you. Reuse the client across requests in Lambda or Express for connection pooling benefits.
10. What are DynamoDB Streams and common use cases?
Streams capture item-level changes (INSERT, MODIFY, REMOVE) in near real time. Consumers include Lambda functions for denormalization, audit logs, OpenSearch indexing, or cross-region replication. Process records idempotently because shards may deliver duplicates and at-least-once semantics apply.
11. Explain strongly consistent vs eventually consistent reads.
Eventually consistent reads (default) may return stale data shortly after a write but consume half the RCUs of strong reads. Strongly consistent reads return the latest successful write but only on the base table primary key or a GSI with strong consistency disabled limitation—GSIs are eventually consistent only.
12. What is the difference between LSI and GSI?
Local Secondary Indexes share the same partition key as the base table but a different sort key—must be defined at table creation and share throughput. GSIs have independent partition/sort keys and capacity. LSIs are less common; most secondary access patterns use GSIs.
13. How do batch operations work?
BatchGetItem reads up to 100 items across tables; BatchWriteItem puts or deletes up to 25 items. Unprocessed keys can remain if throttled—retry with backoff. BatchWriteItem is not atomic across all items; use TransactWriteItems when you need all-or-nothing across up to 100 items in one account/region.
14. What is TTL in DynamoDB?
TTL deletes items automatically after a Unix epoch timestamp in a designated attribute—free, eventually within days. Use for sessions, ephemeral logs, or cache expiry. The attribute must be Number type epoch seconds; deleted items can still appear briefly and trigger stream events.
15. How would you migrate or evolve a DynamoDB schema?
DynamoDB is schemaless per item but access patterns are not—add GSIs for new queries, dual-write during migrations, backfill with Scan+Write (carefully), and use version fields on items. Avoid blocking table operations; use online index creation and phased cutover with feature flags.
Pro Tip
Walk through one concrete access pattern ("get all orders for user X sorted by date") and show PK/SK plus an optional GSI—interviewers prefer applied modeling over definitions.