DynamoDB Streams: How They Work, View Types, and Single-Table Patterns
DynamoDB Streams is a change log for one table. Every insert, update and delete adds a record to the stream. A consumer, usually a Lambda function, reads the records and reacts. Records stay in the stream for 24 hours.
That is the whole feature. The hard part is not turning it on. The hard part is what you do in a single table, where one stream carries changes for every entity you own.
I use Streams for search sync, aggregates and fan-out. This post is the reference. The fan-out, CDC and projections post goes deeper on three of the patterns.
What a stream record contains
You enable a stream per table. After that, each write to the table produces one record. The record holds:
- The event name:
INSERT,MODIFYorREMOVE. - The primary key of the item.
- A sequence number.
- The item image before the write, after the write, both, or neither. This is the stream view type.
Writing to the stream does not slow your writes. AWS writes stream records asynchronously, so your PutItem does not wait for them.
AWS says each stream record appears once in the stream. A consumer can still see a record twice, because a Lambda batch can fail and retry. Write your consumers so a repeat is harmless. The idempotency keys post shows how.
Stream view types
You pick one of four when you enable the stream. You can change it later only by turning the stream off and on again, so choose with care.
| View type | Record holds | Use it when |
|---|---|---|
KEYS_ONLY | Primary key only | The consumer reads the item itself |
NEW_IMAGE | Item after the write | Search sync, projections, caches |
OLD_IMAGE | Item before the write | Audit of deletes, undo |
NEW_AND_OLD_IMAGES | Both | Diffs, aggregates, “what changed” logic |
My default is NEW_AND_OLD_IMAGES. Aggregates need the old value to subtract it, and diffs need both. The images count toward record size, but the stream read cost is per call, not per byte. See the cost section.
Use KEYS_ONLY when the consumer will fetch the current item anyway. A search indexer often wants the latest state, not the state at the moment of the write.
Lambda triggers
Lambda is the usual consumer. You create an event source mapping between the stream and a function. Lambda polls each shard, collects records into a batch, and invokes your function.
The settings that matter:
- Batch size. How many records per invocation. Larger batches mean fewer invocations.
- Starting position.
LATESTskips old records.TRIM_HORIZONstarts from the oldest record still in the stream. - Parallelization factor. Lets Lambda run more than one batch per shard at the same time. Order is kept per item.
- Retry limits and an on-failure destination. Without these, a bad record blocks its shard until it expires.
- Event filtering. Lambda can drop records before your code runs, using a filter on the record. You do not pay for invocations of filtered records.
- Partial batch response. Your function reports which records failed, so Lambda retries from that record and not the whole batch.
A handler for a single-table stream looks like this:
import type { DynamoDBStreamHandler } from 'aws-lambda'
import { unmarshall } from '@aws-sdk/util-dynamodb'
export const handler: DynamoDBStreamHandler = async (event) => {
const failures: { itemIdentifier: string }[] = []
for (const record of event.Records) {
try {
const image = record.dynamodb?.NewImage
if (!image) continue
const item = unmarshall(image as Parameters<typeof unmarshall>[0])
if (item.__edb_e__ !== 'order') continue // ElectroDB entity tag
await syncOrderToSearch(item)
} catch {
failures.push({ itemIdentifier: record.dynamodb!.SequenceNumber! })
break // stop here so later records keep their order
}
}
return { batchItemFailures: failures }
}
Partial batch response only works if you turn on ReportBatchItemFailures on the event source mapping. The break matters. If record 3 fails and you keep going, record 4 may succeed, and Lambda retries from record 3 anyway. For per-item ordering, stop at the first failure.
In a single table, every entity shares one stream. Filter early. The handler above filters in code with ElectroDB’s entity tag, but an event filter on __edb_e__ is better because the function never runs for other entities. The filter pattern goes on the event source mapping. See the Lambda event filtering docs for the syntax.
Ordering
DynamoDB Streams keeps the order of changes for each item. If you update the same item twice, the two records arrive in that order. Records for items with the same partition key go to the same shard, so a consumer sees a partition’s changes in one place.
I only rely on the per-item guarantee. Across items, even in one partition, I do not assume an order. Across partitions you get no order at all. If your consumer needs a global order, a stream is the wrong tool, or you need to carry a version number on the item and check it.
Shards split and merge as the table grows. Lambda handles this. If you write your own consumer with the Streams API, you have to follow the shard lineage, or you will read child shards before parents finish and break the order. This is a good reason to use Lambda.
24 hour retention
Stream records are available for 24 hours. After that they are gone.
If your consumer is down for a day, you lose changes. Set an alarm on the Lambda IteratorAge metric. A rising iterator age means the consumer is behind. Alarm at an hour, not at 23.
You cannot replay history from a stream. If you need to rebuild a search index or a read model, scan the table or restore from a backup. Plan the rebuild path before you need it. The same limit is the main reason people move to Kinesis, below.
Streams vs Kinesis Data Streams for DynamoDB
DynamoDB can also send item changes to a Kinesis data stream. You enable it per table, next to or instead of DynamoDB Streams.
| DynamoDB Streams | Kinesis Data Streams | |
|---|---|---|
| Retention | 24 hours | Up to 365 days, as you set it |
| Consumers | Few. Meant for one or two readers per shard | Many, including enhanced fan-out |
| Ordering | Per item | Per shard, but records can be duplicated or arrive out of order by timestamp |
| Setup | One setting on the table | A Kinesis stream you size and pay for |
| Billing | Stream read requests | Kinesis stream pricing plus DynamoDB change data capture units |
Retention numbers are as of November 2026. Check the Kinesis retention docs before you plan around them.
Pick DynamoDB Streams for the simple case: one Lambda or two, a 24 hour window, per-item order. Pick Kinesis when consumers fall behind for days, you need to replay, or many separate systems read the same changes. Kinesis for DynamoDB can deliver a record more than once and does not promise the order of records for one item, so you must sort by the approximate creation time or a version field yourself.
Most single-table apps never need Kinesis. I have not needed it on any of my own.
Patterns in single-table design
One stream, many entities. These four patterns work well.
Fan-out
One write, several reactions. A new ORDER# item triggers an email, a warehouse event and an analytics record. Do not make the stream consumer do all of them. Have one small function publish to EventBridge or SNS, and let each downstream subscribe. A slow email provider then cannot hold back the warehouse. The fan-out post has the code.
Aggregates
A stream can keep counts and totals that you would otherwise compute with a scan. When a COMMENT# item is inserted, add one to the commentCount on the parent post. Use NEW_AND_OLD_IMAGES so that a MODIFY can subtract the old value and add the new one.
Two cautions. First, the aggregate is eventually consistent. It lags the write by some milliseconds to seconds. Second, a retry can double-count. Use an update that is safe to repeat, or store the last processed sequence number on the aggregate item. If you need the count to be exact at write time, use a transaction instead.
Search sync
DynamoDB cannot do full-text search. The standard answer is to copy items to OpenSearch or another search engine. A stream consumer does the copy. On INSERT and MODIFY it indexes NewImage. On REMOVE it deletes the document by key.
Handle TTL deletes with care. A REMOVE caused by TTL carries a userIdentity of type Service with principal dynamodb.amazonaws.com. Check it if you treat expiry differently from a user delete. See TTL and soft deletes.
Outbox
The outbox pattern solves a dual write. You want to save an order and also publish an event. If you do both in your app, one can succeed while the other fails.
Instead, write the order and an OUTBOX# item in one transaction. A stream consumer reads the OUTBOX# inserts, publishes the event, and deletes the item. The publish happens at least once, so consumers dedupe by event ID. In a single table the outbox item can sit in the same item collection as the order. Event sourcing uses the same idea with a full event log.
Cost
Writing to the stream is free. You pay for read requests on the stream. As of November 2026 in us-east-1, the first 2.5 million stream read request units each month are free, then $0.02 per 100,000, based on the figures in my DynamoDB pricing post. Each GetRecords call is a read request unit, and a call can return many records. If your consumer is a Lambda trigger, you pay nothing for those reads. AWS does not charge for GetRecords calls made through DynamoDB triggers on Lambda, unless the function runs on Lambda Managed Instances. The official pricing page has the current numbers.
Costs that people forget:
- Lambda invocation and duration for your consumer.
- The Kinesis stream, if you use it, plus change data capture units.
- The downstream system, such as OpenSearch. It is usually the biggest line.
The stream read charge only matters for consumers other than a Lambda trigger, such as the Kinesis Client Library. Even then, a quiet table stays inside the free amount in most cases.
Mistakes I see
Letting a poison record block a shard. One bad record, no retry limit, no failure destination. The shard stalls until the record expires after 24 hours, and everything behind it is delayed. Set a retry limit and an on-failure destination.
Reading the stream and writing to the same table without a guard. A consumer that updates an item creates a new MODIFY record, which triggers the consumer again. Add a condition, or filter on the attributes that changed.
Assuming Streams is a queue. It is a short log. It is not for work you must retry for days.
Skipping the entity filter. In a single table, a function that handles order records still wakes up for user records. Filter at the event source mapping.
Next steps
Streams turn a single table into a source of events. Start with the smallest useful consumer, one entity filter and one side effect, and add the alarm on iterator age on day one.
The fan-out, CDC and projections post covers the code for three of these patterns. I’m building singletable.dev so you can see which entities share a table, and so which ones share a stream.
Limits and prices are as of November 2026 and change. See the DynamoDB Streams docs and the pricing page.