What are DynamoDB Streams and what are they used for?
Understand DynamoDB Streams: ordered change capture of inserts, updates and deletes, view types, 24-hour retention, and use cases like replication and search.
Expected Interview Answer
DynamoDB Streams is a change-data-capture feature that emits an ordered, time-sequenced log of every item-level modification (insert, update, delete) in a table, which other services can read to react to changes in near real time.
When enabled, each write produces a stream record containing the keys and, depending on the configured view type, the item's before and/or after image. Records are grouped by partition into shards, kept in strict order per partition, and retained for 24 hours. Common consumers are AWS Lambda (via an event-source mapping) or the Kinesis Client Library, powering use cases like replicating data, updating search indexes, sending notifications, maintaining aggregates, and building event-driven pipelines without polling the table.
- Near real-time reaction to data changes
- Ordered, per-partition change history
- Decouples producers from downstream consumers
- Enables replication, search indexing and analytics
- No polling — changes are pushed to consumers
AI Mentor Explanation
A DynamoDB Stream is the ball-by-ball commentary feed of a match: every delivery, wicket, and boundary is announced in the exact order it happens. Downstream listeners — the scoreboard, the stats team, the highlights editor — each consume that ordered feed and react, instead of repeatedly walking onto the pitch to ask what just changed.
Step-by-Step Explanation
Step 1
Enable the stream
Turn on Streams for the table and choose a view type: keys only, new image, old image, or new and old images.
Step 2
Writes generate records
Every insert, update, or delete produces a stream record capturing the change according to the view type.
Step 3
Records land in shards
Records are grouped by partition into shards and kept in strict order within each shard, retained for 24 hours.
Step 4
A consumer reads the stream
Attach a Lambda event-source mapping or use the Kinesis Client Library to process records in order.
Step 5
React to the change
The consumer replicates data, updates a search index, sends a notification, or updates an aggregate.
What Interviewer Expects
- Defines Streams as ordered item-level change capture
- Knows the four stream view types and their images
- Understands shards, ordering per partition, and 24-hour retention
- Names real consumers: Lambda and the Kinesis Client Library
- Gives concrete use cases like replication and search indexing
Common Mistakes
- Confusing Streams with backups or point-in-time recovery
- Thinking records are retained indefinitely (it's 24 hours)
- Assuming global ordering rather than per-partition ordering
- Forgetting to choose the correct view type for the use case
- Believing the consumer must poll the table instead of the stream
Best Answer (HR Friendly)
“DynamoDB Streams is like a live activity feed for a table — whenever a record is added, changed, or deleted, it records that event in order. Other systems can watch this feed and react instantly, which is great for things like sending alerts or keeping a search index up to date.”
Code Example
await client.send(new UpdateTableCommand({
TableName: 'Orders',
StreamSpecification: {
StreamEnabled: true,
StreamViewType: 'NEW_AND_OLD_IMAGES',
},
}))export const handler = async (event) => {
for (const record of event.Records) {
if (record.eventName === 'INSERT') {
const item = record.dynamodb.NewImage
await indexInSearch(item)
}
}
}Follow-up Questions
- What are the four StreamViewType options?
- How long are stream records retained?
- How is ordering guaranteed in DynamoDB Streams?
- What is the difference between DynamoDB Streams and Kinesis Data Streams for DynamoDB?
- How does a Lambda event-source mapping handle failures and retries on a stream?
MCQ Practice
1. How long are DynamoDB Streams records retained?
Stream records are available for 24 hours before they expire.
2. Which StreamViewType provides both the pre- and post-change item?
NEW_AND_OLD_IMAGES includes the item as it looked before and after the modification.
3. In DynamoDB Streams, ordering is guaranteed:
Records are strictly ordered within each shard, which corresponds to a partition, not globally.
Flash Cards
What is DynamoDB Streams? — A change-data-capture feature emitting an ordered log of item-level inserts, updates, and deletes.
What are the stream view types? — KEYS_ONLY, NEW_IMAGE, OLD_IMAGE, and NEW_AND_OLD_IMAGES.
How long are stream records kept? — 24 hours, after which they expire.
Name common stream consumers. — AWS Lambda via event-source mapping, or the Kinesis Client Library (KCL).
Continue Learning
Related Interview Questions
How does DynamoDB integrate with AWS Lambda for event-driven processing?
medium
What are global tables in DynamoDB and how does multi-region replication work?
hard
When would you choose Kinesis Data Streams for DynamoDB over DynamoDB Streams?
hard
What is DynamoDB Time to Live (TTL) and when do you use it?
easy