System Design
Advanced

Idempotency, Sagas, and Recovery

Coordinate multi-step workflows without relying on fragile distributed transactions.

35 min
3 sections
idempotency
sagas
recovery
1
2
3

01. Treat retries as normal

Section 1 of 3

Retries happen after client timeouts, worker restarts, broker redelivery, and failover. Every handler that performs side effects should be safe to run more than once or detect duplicate work.

text
Payment capture handler:
1. Validate order is payable.
2. Check payment_attempt by idempotency_key.
3. If existing terminal result, return it.
4. Call provider with same idempotency key.
5. Store provider response.
6. Emit PaymentCaptured or PaymentFailed once.
Back to Course