The transactional outbox on AWS: DynamoDB Streams and EventBridge Pipes
A Lambda that saves an order and then publishes an event will one day do only one of the two. Write the order and an outbox item in one DynamoDB transaction, and let an EventBridge Pipe deliver the event from the stream.
ON THIS PAGE
If a Lambda function saves an order and then calls PutEvents, there will be a day when one of the two happens without the other. The transactional outbox removes that day: write the order and a record of the event in one DynamoDB transaction, and let an EventBridge Pipe read the table's stream and deliver the event. The function then has one thing to get right, the write, and the database already makes that atomic.
Why retries do not fix a dual write#
A handler that calls PutItem and then PutEvents is talking to two systems that cannot share a transaction. Kill it between the calls (a timeout, a throttle, a deployment) and the order exists while nobody downstream hears of it. Swap the order of the calls and you get the opposite: invoicing bills a customer for an order whose write was rejected by a condition check.
Retries make it worse: the retried invocation cannot tell whether the first attempt's event went out, so it either sends a second or skips the only one. Try and catch only moves the gap. The flaw is the shape of the code.
Write the event into the table#
DynamoDB's TransactWriteItems groups up to 100 writes, across tables in one account and Region, that all succeed or all fail. Put the order and an outbox item in the same call:
await ddb.send(new TransactWriteCommand({ TransactItems: [
{ Put: { TableName: "shop", Item: order,
ConditionExpression: "attribute_not_exists(pk)" } },
{ Put: { TableName: "shop", Item: {
pk: order.pk, sk: `EVENT#${eventId}`, type: "OrderPlaced",
seq: 1, detail: summary, expiresAt: inSevenDays },
ConditionExpression: "attribute_not_exists(pk)" } },
]}));You could instead publish the order item's own change records, the change-data-capture variant AWS also describes. Resist that unless the table is already shaped like events. A stream record says which attributes of a row changed; an outbox item says what happened to the business. Consumers who read row images are coupled to your table design, and its next refactor breaks teams you have never met.
Enable DynamoDB TTL on expiresAt to clean up old outbox items. TTL follows the timestamp independently of delivery, so monitor relay failures and reconcile before expiry. The catch is that TTL deletions also enter the stream, as REMOVE records from the principal dynamodb.amazonaws.com. Publish only inserts and the cleanup stays silent.
The pipe: stream in, bus out, no code#
An EventBridge Pipe reads the table's stream, filters it, optionally reshapes each record, and hands it to a target: an event bus for fan-out, or an SQS FIFO queue when one consumer needs strict order. The filter is where the outbox becomes a contract:
{ "eventName": ["INSERT"],
"dynamodb": { "Keys": { "sk": { "S": [{ "prefix": "EVENT#" }] } } } }Records that fail the filter are not billed: on the EventBridge pricing page on 20 November 2026, a pipe cost $0.40 per million requests after filtering, each 64 KB of payload counting as one request. Order updates and TTL deletes cost nothing there.
Three settings decide whether anything is lost:
- Start at
TRIM_HORIZON. A pipe can take minutes to begin polling after it is created or changed, andLATESTskips whatever arrived in between. - Give the pipe a dead-letter queue, and a maximum record age well under the stream's 24-hour retention. The DLQ can carry stream position metadata. Keep enough stream retention to recover the original record, or recover it from the outbox. The better safety net is the outbox item itself: it stays in the table until its TTL, so a seven-day expiry means a week in which any lost event can be found and sent again.
- Never disable the stream. A re-enabled stream gets a new ARN, and a pipe cannot change its source, so the pipe is dead.
What the outbox does not give you#
It guarantees that the order and a durable record of its event commit together. Publication still depends on the relay and on recovery after extended failures. Delivery can repeat, so carry the outbox item's ID as the event ID and see idempotent consumers with SQS and Lambda for the receiving end.
Nor does it give you global order. DynamoDB Streams preserves the order of changes to an item, and Pipes maintains order by partition key when increasing concurrency. A Classic event bus can still reorder deliveries. A FIFO queue targeted directly by the pipe preserves the arrival order per message group. Use seq to detect gaps or stale events and carry the order ID as the FIFO group key.
And it covers one service's write. When a business action spans several services' data, the outbox becomes one step inside a saga with Step Functions; event-driven patterns on AWS places both on the wider map.
On Azure and Google Cloud#
Microsoft's version saves the document and its event in a Cosmos DB transactional batch, relays them from the change feed with an Azure Functions trigger or the change feed processor, and publishes to a Service Bus topic with duplicate detection and sessions. It is stricter than DynamoDB: a batch covers one logical partition, so the event must share the entity's partition key. On Google Cloud the nearest match is a Spanner change stream, which records committed changes; you read it with Dataflow or the Spanner API and publish to Pub/Sub yourself, so the relay is your code, not a configured pipe.
The diagram#
The order Lambda writes two items in one transaction; the stream feeds a filtered pipe with a dead-letter queue; the bus fans the event out to two consumers. Open it in archhy and press Make a copy to adapt it.
Reference documentation: DynamoDB stream sources for Pipes, Pipes failure handling, Pipes pricing, DynamoDB TTL, Azure transactional outbox, Spanner change streams.
