Problem Context
A hospitality group wanted guests to search and book rooms without leaving WhatsApp.
The booking engine's v1.0.5 API documented search, a temporary hold and create — but
nothing about idempotency, timeouts, rate limits or webhooks. The work was pre-sales:
answer the client's technical questions, surface the gaps, and design middleware that
could not double-book a room.
Key Requirements & Constraints
- No new partner API, webhook or outbound feed; every call is middleware-initiated.
- Payment stays in the booking engine; no card data touches the platform.
- The hold is the only lock; inventory remains the partner's source of truth.
- A timeout must never become a blind retry.
- The guest must never be told the booking failed while the outcome is unknown.
- One short-lived token per booking flow; credentials live in a secret manager.
Architecture Overview
The middleware sits between the conversation flow and the booking engine. A booking
intent is a first-class object with its own UUID and a ledger entry.
- Authenticate once per flow and keep the token in memory.
- Search live availability and rates for the requested dates and occupancy.
- Add the room plan to the cart and call
confirm-booking for a preview and a temporary hold.
- Call
create immediately after a successful hold, with the gateway code returned by the engine.
- Read status through
booking/list and booking/detail; never infer it from the conversation.
Key Design Decisions & Trade-offs
1) Ledger before retry
Before the first create, the middleware writes the intent and the exact payload to the
ledger as PENDING. Every retry reuses the same UUID. A second UUID is never
generated for the same intent, so a duplicate call can always be traced back to one
decision.
2) Reconcile before retry
On a timeout, the middleware does not create again. It runs a read-only lookup: list the
account's bookings, shortlist by hotel, dates, occupancy and status, then verify each
candidate with booking/detail on name, email, phone and amount. A match is
adopted and the ledger closes as RECONCILED. The API offers no idempotency
key, so this heuristic is the only way to prove a booking does not already exist.
3) A quiet period and one retry
If nothing matches, the middleware waits two minutes and re-checks once. Only then is a
single create retry allowed. If the outcome is still ambiguous, the case goes
to a human queue marked MANUAL_REVIEW and "do not honour until confirmed".
create is never looped.
4) Payment stays with the engine
confirm-booking returns the payment model; create returns a type
and payload — a QR image, a redirect URL, or null. The platform never collects or stores
card data and never marks a booking paid itself. Amounts come from the confirm preview,
never from the conversation.
5) Token per flow, secrets server-side
A fresh token is obtained per flow, kept in memory and discarded. Credentials live in the
secret manager, and every call validates the property id against an allow-list. If the
account is later split per property, the credential model changes but the middleware does not.
Security, Data & Reliability
- The reconcile phase is read-only; nothing is created there.
- Creates are serialised per guest and room plan, and the quiet period bounds the duplicate window.
- Availability is never cached; a fresh search precedes every hold, and a stale hold is re-searched rather than retried.
- Ambiguous cases reach a human with the intent id, guest details, room plan, dates and amount.
- No card data, no long-lived token, no guess at the partner's payment state.
Outcome & Impact
This was a pre-sales engagement, not a shipped system. The deliverable was the integration
design, the middleware model and the answers the client needed to sign.
- 36 client questions answered across integration model, logging and security, data responsibility, sandbox/UAT and concurrent-booking risk.
- The spec's gaps were surfaced before signature: no idempotency key, no webhooks, no documented timeouts or rate limits, no pagination or created-at on the booking list.
- One reconciliation path defined; zero blind retries by design.
- A working mock of the partner API and the middleware was built to prove the flow before delivery.
What I'd Improve Next
- Validate the matching heuristic against real sandbox data; a partner-side idempotency key would replace it entirely.
- Publish an OpenAPI contract and a sandbox test suite for the middleware.
- Decide per-property credentials versus one account with an allow-list.
- Add adaptive polling and backoff for status instead of fixed re-checks.
Why This Case Study Matters
Most integration designs assume the partner API behaves. This one starts from the
opposite: no idempotency, no events, incomplete documentation. The interesting work is
the reconciliation path — and the honesty of the guest experience when the system does
not yet know whether the booking exists.