← всС Π²ΠΈΠ΄Π΅ΠΎ

The Outbox Pattern Explained (Complete Guide)

System Design Lab Β· 2026-07-13 Β· 10ΠΌ 23с Β· 2Β 955 просмотров Β· YouTube β†—

Π’ΠΎΠΏΠΈΠΊΠΈ: durable-execution

Аудио Π΅Ρ‰Ρ‘ Π½Π΅ скачано.

πŸ“ Summary

Summary Π΅Ρ‰Ρ‘ Π½Π΅ сгСнСрён.

πŸ“œ Transcript

Transcript Π΅Ρ‰Ρ‘ Π½Π΅ сдСлан.

βš™οΈ Pipeline jobs

НСт job'ΠΎΠ² Π² ΠΎΡ‡Π΅Ρ€Π΅Π΄ΠΈ.

πŸ“„ ОписаниС YouTube

ΠŸΠΎΠΊΠ°Π·Π°Ρ‚ΡŒ
The outbox pattern fixes one of the most common bugs in backend systems: you save a row, then publish an event, and the event silently vanishes while your logs stay clean. This is the complete model β€” the dual-write problem, why reordering and distributed transactions don't save you, the transactional outbox fix, polling vs CDC relays, at-least-once delivery, idempotent consumers, and how DynamoDB Streams is the outbox pattern in disguise.

We start from the silent failure (a signup succeeds, the welcome email never goes out, zero errors), name the dual-write problem underneath it, and prove that flipping the two writes only moves the crash. Then we build the fix: write the event into an outbox table in the same database transaction as your data, hand it to a separate relay, and design consumers for duplicates. We finish on AWS β€” the RDS + scheduled Lambda + SNS polling shape and the DynamoDB Streams + Lambda + EventBridge CDC shape β€” and the one decision rule you can carry to any "change my data and tell another system" problem.

━━━━━━━━━━━━━━━━━━━━━━━
CONNECT WITH ME
━━━━━━━━━━━━━━━━━━━━━━━
πŸ”— LinkedIn: https://linkedin.com/in/joud-awad
🐦 X/Twitter: https://x.com/TheJoud97
πŸ“ Medium: https://medium.com/@joudwawad
πŸ“§ Substack: https://joudawad.substack.com/
🌐 Website: https://joudawad.com/

━━━━━━━━━━━━━━━━━━━━━━━
πŸ“š WHAT YOU'LL LEARN
━━━━━━━━━━━━━━━━━━━━━━━
βœ… The dual-write problem β€” why "save the row, then publish the event" is two writes to two separate systems with no shared transaction wrapping both
βœ… Why reordering doesn't help β€” commit-then-publish drops events on a crash, publish-then-commit creates phantom events, and the crash just moves to the other side of the gap
βœ… Why distributed transactions are mostly off the table β€” many brokers don't support them, and they couple your service to both systems
βœ… The transactional outbox fix β€” write the event into an outbox table in the SAME database transaction as your data, so both commit or neither does
βœ… The relay β€” a separate worker that reads committed outbox rows and publishes them, moving the risky cross-system call out of the request path
βœ… Polling vs Change Data Capture (CDC) β€” the latency/load tradeoff, the out-of-commit-order trap that silently drops rows, and when to pick each
βœ… At-least-once, not exactly-once β€” how a relay crash between publish and mark-sent produces duplicates, and why you design for them instead of fighting them
βœ… The idempotent consumer contract β€” dedupe with a stable event id + a processed-messages table keyed by (consumer, event id), and keeping per-entity order with the log position
βœ… The operational tax β€” the outbox grows forever unless the relay deletes after publish, and keeping your retry budget shorter than stream retention
βœ… Outbox on AWS β€” the RDS + scheduled Lambda + SNS polling shape, and the DynamoDB Streams + Lambda + EventBridge CDC shape (with the per-item ordering and 24-hour retention caveats)

━━━━━━━━━━━━━━━━━━━━━━━
⏱ CHAPTERS
━━━━━━━━━━━━━━━━━━━━━━━
0:00 The silent bug: save a row, publish an event
0:26 A sign-up where the welcome email never sends
1:33 Two writes to two systems (the dual-write problem)
2:15 Where it breaks, and why reordering won't save you
3:11 Why distributed transactions aren't the answer
3:37 The Outbox pattern: write the event, don't send it
4:23 The relay: a separate worker that publishes
5:02 Building the relay: polling vs change data capture
6:14 At-least-once delivery and how duplicates happen
6:51 The idempotent consumer
7:46 Cleaning up the outbox table
8:27 Outbox on AWS: RDS + SNS and DynamoDB Streams
9:33 The rule to remember + recap


━━━━━━━━━━━━━━━━━━━━━━━
πŸ”§ WHO THIS IS FOR
━━━━━━━━━━━━━━━━━━━━━━━
Mid-to-senior backend engineers building event-driven systems who've written "save the row, then publish the event" and want the bug-free version β€” the transactional outbox, the relay, and idempotent consumers β€” without hand-waving the failure modes.

#distributedsystems  #systemdesign  #eventdrivenarchitecture  #distributedsystems  #aws