DynamoDB Streams overview in AWS - Time & Space Complexity
We want to understand how the time to process DynamoDB Streams changes as more data updates happen.
Specifically, how does the number of stream records affect processing time?
Analyze the time complexity of reading and processing DynamoDB Stream records.
// Assume a Lambda function triggered by DynamoDB Streams
exports.handler = async (event) => {
for (const record of event.Records) {
// Process each record
console.log('Processing record:', record.eventID);
}
};
This code processes each record from the DynamoDB Stream triggered by table changes.
Look at what repeats when processing stream records.
- Primary operation: Processing each stream record one by one.
- How many times: Once per record in the stream batch.
As the number of stream records grows, the processing time grows too.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 | 10 processing steps |
| 100 | 100 processing steps |
| 1000 | 1000 processing steps |
Pattern observation: The work grows directly with the number of records.
Time Complexity: O(n)
This means processing time increases linearly as the number of stream records increases.
[X] Wrong: "Processing one record takes the same time no matter how many records there are."
[OK] Correct: Each record adds more work, so total time grows with the number of records.
Understanding how processing scales with input size helps you design efficient event-driven systems and shows you can reason about real cloud workloads.
"What if the Lambda function batches multiple stream records together before processing? How would the time complexity change?"
Practice
Solution
Step 1: Understand DynamoDB Streams function
DynamoDB Streams capture data changes like inserts, updates, and deletes in real time.Step 2: Compare options with Streams purpose
Only To track and react to data changes in real time correctly describes tracking and reacting to data changes. Other options describe unrelated features.Final Answer:
To track and react to data changes in real time -> Option DQuick Check:
DynamoDB Streams = Track data changes [OK]
- Confusing Streams with backup or encryption features
- Thinking Streams increase read capacity
- Assuming Streams store data permanently
Solution
Step 1: Identify the configuration for enabling Streams
To use DynamoDB Streams, the table must have StreamEnabled set to true.Step 2: Eliminate unrelated settings
BackupEnabled, EncryptionEnabled, and AutoScalingEnabled do not enable Streams.Final Answer:
StreamEnabled set to true -> Option CQuick Check:
Enable Streams = StreamEnabled true [OK]
- Confusing Streams with backups or encryption
- Assuming AutoScaling enables Streams
- Forgetting to enable Streams explicitly
StreamViewType set to NEW_AND_OLD_IMAGES, what data will the stream record for each change?Solution
Step 1: Understand StreamViewType NEW_AND_OLD_IMAGES meaning
This setting records both the item before and after the change.Step 2: Compare options with StreamViewType behavior
Only Both the new and old item images matches the behavior of capturing both new and old images.Final Answer:
Both the new and old item images -> Option BQuick Check:
NEW_AND_OLD_IMAGES = new + old data [OK]
- Choosing only new or only old images
- Confusing keys only with full images
- Not knowing StreamViewType options
Solution
Step 1: Check if Streams are enabled
If StreamEnabled is false, no stream records are generated regardless of updates.Step 2: Evaluate other options
KEYS_ONLY still produces records; retention period (24-168 hours) does not prevent seeing recent records; tables require primary keys but that doesn't stop streams if enabled.Final Answer:
StreamEnabled is false on the table -> Option AQuick Check:
No records = Streams not enabled [OK]
- Assuming KEYS_ONLY disables records
- Thinking retention period prevents seeing records
- Ignoring StreamEnabled setting
Solution
Step 1: Choose StreamViewType for updates
To capture both before and after update data, use NEW_AND_OLD_IMAGES.Step 2: Configure Lambda trigger on the DynamoDB Stream
Lambda triggers must be set on the stream, not directly on the table.Final Answer:
Enable Streams with StreamViewType NEW_AND_OLD_IMAGES and configure Lambda trigger on the stream -> Option AQuick Check:
Lambda trigger on stream with NEW_AND_OLD_IMAGES [OK]
- Triggering Lambda directly on table instead of stream
- Choosing KEYS_ONLY or OLD_IMAGE for update data
- Not enabling Streams before Lambda trigger
Ready to prove it?
Pass the test and this pattern moves unknown
