The Desi Architect
Notes / Docker Sandboxes / Transactional Outbox Pattern & Polling Relay (PostgreSQL SKIP LOCKED)
Docker Sandboxes · Tier 3: Reliability & Messaging · Lab 41

Transactional Outbox Pattern & Polling Relay (PostgreSQL SKIP LOCKED)

Save an order and tell the warehouse about it, without ever losing the message or inventing one. Crash between the two steps and see the lost event. Then write the event in the same transaction as the order, run two relays side by side with SKIP LOCKED, and see the duplicate that appears when a relay crashes.

Time40 minutes
StackPostgreSQL 16Ports 15445
MemoryAbout 90 MB
Before thisLab 05SQL Transaction Isolation Levels &
Verified runWindows, Mac, LinuxBash and PowerShell
  1. 1PrepareWhat you will learn
  2. 2PredictGuess before you run
  3. 3RunStep by step
  4. 4ObserveWhat you should see
  5. 5Break itChange one thing
  6. 6Clean upLeave nothing running
On this page
  1. 00 / What You Will Learn
  2. 01 / Why It Matters
  3. 02 / What We Are Building
  4. 03 / Words You Need
  5. 04 / Predict First
  6. 05 / Step by Step
  7. 06 / What You Should See
  8. 07 / Look Inside
  9. 08 / Break It, Fix It
  10. 09 / In Real Projects
  11. 10 / Interview Corner
  12. 11 / Clean Up

00 /What You Will Learn

By the end you will be able to
  • Explain the dual-write problem and what each order of the two writes can lose.
  • Explain the transactional outbox: event and data in one transaction, a relay publishes later.
  • Use FOR UPDATE SKIP LOCKED so several relays share work without overlap.
  • Explain why delivery is at least once, and make a consumer idempotent with an inbox.

Before you start

Finish Lab 05 (SQL Transactions and Isolation) and Lab 17 (Queue Basics) first. You should know BEGIN, COMMIT, ROLLBACK, and what a message broker is. Docker Desktop and Python 3 are needed.