CTO @ Beautron.AI · AI Product Engineer
3 min read
Architecture / Microservices / Payments / Travel
Booking flows are sagas, not transactions
Flights, hotels, cars and payments live in different systems you don't control. Model the booking as a saga with compensations, idempotency keys and a reconciliation loop — not as one big database transaction.
I've built flight, hotel and car-rental booking flows from scratch, integrated with suppliers such as Hotel Planner and payment gateways such as Stripe and Authorize.net. The most important lesson is also the simplest: a booking is not a transaction. It's a conversation between several systems you don't own, and any of them can say "no", time out, or say "yes" twice.
Why ACID doesn't reach far enough
Inside your own database you can wrap a few inserts in a transaction and sleep well. A trip booking spans:
- the payment gateway (authorize, later capture or void),
- one or more suppliers (hold a room, ticket a seat, reserve a car),
- your own order store, inventory cache and notification pipeline.
There is no distributed transaction that covers a supplier's API and your SQL Server. Two-phase commit across HTTP APIs you don't control isn't an option, so you need a different model.
Model the booking as a saga
A saga is a sequence of local steps where every step has a compensating action that undoes its business effect:
| Step | Action | Compensation |
|---|---|---|
| 1 | Authorize payment | Void authorization |
| 2 | Hold hotel room | Release hold |
| 3 | Reserve car | Cancel reservation |
| 4 | Capture payment | Refund |
| 5 | Confirm booking, notify customer | — |
If step 3 fails, you run the compensations for steps 2 and 1 in reverse order. The customer sees "the car is no longer available" instead of a half-paid trip.
Two rules make this work in practice:
- Authorize early, capture late. Authorizing first proves the customer can pay without moving money. Capture only after every supplier has confirmed, so the most common failure path is a void, not a refund.
- Put the riskiest step first. If one supplier fails far more often than the rest, try it before the reliable ones. Fewer compensations run, and fewer things can go wrong while they do.
Orchestration over choreography (for this domain)
You can run a saga by letting services react to each other's events (choreography) or by having one orchestrator drive the steps. For bookings, I prefer an explicit orchestrator with a persisted state machine:
Pending → PaymentAuthorized → RoomHeld → CarReserved → Captured → Confirmed
↓ ↓ ↓
Compensating ──────────────────────→ Cancelled
The orchestrator stores its state after every step, so when a process restarts mid-booking it knows exactly where to resume or what to compensate. Support staff can see that state too: "stuck in RoomHeld for ten minutes" is a question you can answer. With choreography, the flow is spread across a dozen handlers and nobody can see the whole booking.
Idempotency is not optional
Networks retry, users double-click, and queue consumers get the same message twice. Every external call in the saga needs an idempotency key derived from the booking and the step (for example booking-8f2c:capture):
- Payment gateways such as Stripe accept idempotency keys natively, so use them.
- For suppliers that don't, keep your own record of "request sent / response received" per key, and check it before calling again.
- Your own handlers should treat "already done" as success, not as an error.
Without this, the retry that saves you from a timeout is the same retry that charges a customer twice.
Timeouts are the hardest failure
A supplier that returns an error is easy. A supplier that times out is ambiguous: maybe the room is held, maybe not. Treat a timeout as "unknown" and move the step to a verification state:
- Query the supplier for the reservation by your reference before retrying.
- If the supplier can't be queried, retry with the same idempotency key.
- If it's still unknown after a bounded number of attempts, compensate and flag the booking for a human.
Reconciliation closes the loop
Even with all of the above, the real world drifts: a supplier confirms by email, a refund is issued manually, a webhook never arrives. A scheduled reconciliation job that compares your bookings against supplier and gateway reports catches what the saga missed. It's dull work, and it's the part that keeps finance and customer support on your side.
Takeaways
- Treat every booking as a saga with explicit compensations.
- Authorize early and capture late; run the riskiest step first.
- Persist the orchestrator's state machine so restarts and support are boring.
- Put idempotency keys on every external call.
- Treat timeouts as "unknown", and reconcile regularly.
Working on something similar? Let's talk — or ask ARA, the assistant in the corner, about this article.