# Transactional Outbox

> Write to DB and publish an event atomically — no dual-write, no lost messages.

- **Category**: Microservices
- **Subcategory**: Messaging & Events
- **Canonical URL**: https://designpattern.fyi/patterns/transactional_outbox/

---

## Description
Clean, reusable architecture pattern.


## Use Cases
Order Service: BEGIN TRANSACTION → UPDATE orders SET status='placed' → INSERT INTO outbox (type='OrderPlaced', payload=...) → COMMIT. Either both succeed or neither does. Polling Publisher picks up outbox row and pushes to Kafka.





## Trade-offs


### Advantages

- Atomic guarantee — business update and event commit together or not at all

- No distributed transaction needed

- At-least-once delivery guaranteed (outbox row persists until published)

- Works with any relational DB




### Considerations & Drawbacks

- OUTBOX table adds schema complexity

- Need to pair with a publisher (Polling Publisher or CDC)

- Outbox rows need cleanup after publishing

- Slight latency from outbox-to-broker pipeline







---
**Reference**: [Original Source](https://microservices.io/patterns/data/transactional-outbox.html)

