An integration that connects hotels to guests lives on webhooks: a booking is created, a reservation changes, a guest sends a message. Most providers promise the same thing: delivery at least once. Not exactly once, or in order, or soon. In practice, a webhook arrives late, twice, or never, and a reliable integration is designed for all three from the start.
Acknowledge fast, process later
A provider retries when it doesn’t get an answer in time, and “in time” is often a few seconds. If the handler does the real work before answering, any slow day turns into duplicates.
So the request does only three things: verify the signature, store the raw payload, and queue a job. The raw payload means that when a bug is fixed next week, the events it broke can be replayed from what actually arrived.
Idempotency is a unique index
The tempting version checks first: “have I seen this event? No? Then process it.” Two deliveries a few milliseconds apart both pass the check. The only check that holds is one the database enforces: a unique index on the event’s source and key, and an insert that either wins or doesn’t.
The key is the provider’s event ID when it stays the same across retries. Otherwise it’s a hash of the fields that define the event, never of the whole body, because a retry can differ in small ways and look like a new event.
The same rule applies on the way out. Sending a guest the same message twice is worse than sending it a few seconds late, so outbound sends carry their own key too.
Late and out of order
Two events about the same reservation can arrive in either order. Apply “cancelled” and then a late “modified”, and you’ve resurrected a cancelled booking.
There are two defences, and I’d use both. First, compare the provider’s own version of the record, not arrival times, and skip an event older than what you already have. Second, where state matters more than the event, treat the webhook as a hint that something changed and fetch the current state from the API. Order stops mattering, at the cost of an API call per event.
Retries that know what they’re retrying
Retrying everything is as bad as retrying nothing, so failures are sorted by kind first. Timeouts and server errors are retried with growing gaps. Rate limits are retried after the wait the provider asks for. Rejected credentials are not retried: they raise an alert and pause that integration. Bad data goes straight to a dead letter, because retrying can’t fix it.
Dead letters you can replay
A dead letter is only useful if somebody reads it and can act on it. Two things make it useful: a way to replay dead letters through the normal pipeline once the bug is fixed, and grouping by error instead of by event. Two hundred dead letters with one cause are one problem, and grouped, they look like one.
Noticing “never”
The hardest failure is the one that doesn’t arrive, because nothing errors. The integration simply goes quiet. Two things catch it. An alert per source when the usual volume drops to nothing, even with no errors anywhere. And a periodic reconciliation job that asks the API what changed since the last sync, fixes anything the webhooks missed, and counts what it fixed. If that count isn’t zero, a webhook was lost somewhere, and now you know where.
What I’d tell someone starting out
- Assume every event will arrive twice, late, and out of order, and test those cases first.
- Put idempotency in the database, not in a check your code makes first.
- Store what you received before you parse it.
- Decide per kind of error whether to retry, and make “don’t” a real option.
- Alert on silence, not just on errors.