#78 Choreography/Outbox Pattern
Event-Driven Booking Architecture
Connect booking, payment, inventory, loyalty and notifications through events, so each service can change and scale on its own.
What is being asked
Design a booking platform where services talk through events rather than calling each other directly. The interviewer wants to hear how you keep data consistent without distributed transactions, and how you stop events from being lost or duplicated.
Requirements
Functional
- A booking flows through: reserve inventory → take payment → confirm → award loyalty points → notify.
- Failures at any step are compensated (release inventory, refund).
- New consumers (analytics, fraud) can join without changing the booking service.
Non-functional
- No lost events; duplicates are handled.
- Each service owns its own database.
- Traceable: you can follow one booking across all services.
Design
- The booking service writes the booking and an event row in the same database transaction (the transactional outbox).
- A relay reads the outbox and publishes to the broker (Kafka, for example). This removes the "saved to DB but failed to publish" gap.
- Each consumer processes events idempotently, keeping a table of processed event IDs.
- The happy path is a choreographed saga:
BookingRequested → InventoryReserved → PaymentCaptured → BookingConfirmed. A failure event triggers compensations.
Key decisions and trade-offs
- Choreography vs orchestration. Choreography (services react to events) is loosely coupled but the overall flow is hard to see. An orchestrator makes the flow explicit but becomes a central dependency. Many teams use an orchestrator for the core booking and events for everything around it.
- At-least-once delivery is the realistic guarantee; exactly-once effects come from idempotent consumers.
- Ordering. Partition by booking ID so all events for one booking arrive in order.
- Schema evolution. Version events and only add fields; consumers you don't know about depend on them.
Follow-up questions
- A consumer has a bug and processed 10,000 events wrongly. How do you replay?
- How do you trace one booking across six services?
- When is a synchronous call better than an event here?
- How do you test a saga's compensation paths?