Skip to content

The reservation that succeeded twice

Failure story 01, in requests, retries and side effects.

The server committed the booking. The customer saw a timeout. Their retry has a new request ID. What should the system do?

Try answering before you read on. There’s a second half to the question: whatever you design must still let the same customer book a second seat on purpose.

Assumption Value
Event A concert with 2 seats left
Client A web app. Its HTTP library adds a fresh X-Request-Id to every attempt and retries once after a timeout
Server Rejects a request whose X-Request-Id it has already processed
Network The load balancer times out after 10 seconds; the booking took 11
Step What happens Seats left
1 The customer clicks Book 1 seat. Attempt 1 goes out with request ID r-81. 2
2 The server reserves a seat, takes payment and commits booking B-1. 1
3 The load balancer gave up at 10 seconds. The customer sees Something went wrong, retrying… 1
4 The client retries with request ID r-82. The server has never seen r-82. 1
5 The server commits booking B-2 and takes a second payment. 0
6 The customer has two bookings and two charges. The next customer is told the concert is sold out. 0

Every component did what it was designed to do. The deduplication worked perfectly, for a question nobody needed answered.

A request ID identifies an attempt. The customer had one intent: one seat. Deduplicating attempts protects against the network delivering the same packet twice, but a retry is, by design, a new attempt. The only thing that stays the same across the customer’s attempts is what they meant to do, so that’s what the server has to recognize.

The tempting fix makes it worse in a different way: “reject a second booking by the same customer for the same concert within five minutes” blocks the customer who genuinely wants to bring a friend.

Aspect Design A: per-attempt request ID Design B: booking-intent ID
Where the ID comes from Generated by the HTTP library for each attempt Created when the customer starts a booking, and stored before the first submission (server-side, or in session storage)
What a retry sends A new ID The same intent ID
What the server does on a repeat Treats it as new Returns the original booking, B-1, without charging again
A deliberate second booking Allowed Allowed: starting a new booking creates a new intent
Survives a page reload Not applicable Yes, because the intent ID was stored before submission

A simple way to build Design B is to make the client create the intent first, then put the booking at an address only that intent can have:

POST /booking-intents → 201 { "intentId": "bi-7f3a" }
PUT /bookings/bi-7f3a { "event": "E-55", "seats": 1 }

PUT to a client-known address is naturally idempotent: doing it twice leaves the same state as doing it once. On the server, a unique constraint makes the guarantee hold even when two attempts race:

INSERT INTO bookings (intent_id, event_id, seats, customer_id)
VALUES ('bi-7f3a', 'E-55', 1, 'C-9')
ON CONFLICT (intent_id) DO NOTHING;
-- Then return the booking for intent_id = 'bi-7f3a', whether it was just created or already there.

Payment needs the same treatment: pass the intent ID, or a key derived from it, to the payment provider as its idempotency key, so the second attempt can’t create a second charge either.

Run both of these against the design. Design A fails the first; a naive deduplication rule fails the second; Design B passes both.

  1. Retrying one intent creates one booking. Create intent bi-1. Submit it, drop the response, submit it again. Expected: one row in bookings, one charge at the payment provider, and both responses name the same booking.
  2. A deliberate second booking still works. Create intents bi-2 and bi-3 with identical bodies, from the same customer, one second apart. Expected: two bookings, two charges.

Count rows and charges, not responses. A design can return the right response and still have charged twice.

This check is in the checks catalog as test templates in Java and Python.

  • Nothing retries automatically and users can’t resubmit, which is rarer than it sounds once mobile networks and impatient people are involved.
  • A duplicate is harmless or trivially reversed, such as adding the same item to a wish list.
  • There’s a natural key that genuinely allows only one, such as one vote per voter per poll. Then the natural key is the intent.

Discussion question. Where should an intent begin: when the page loads, when the customer clicks Book, or when the server creates a checkout? What does each choice mean for a customer who opens checkout in two tabs?

Exercise. Using Design B, the intent ID is generated in the browser when the checkout page loads. The customer opens checkout in two tabs and clicks Book in both. How many bookings are created? Is that the right answer, and what would you change if the business says it isn’t?

Worked answer

Two. Each tab loaded the page separately, so each has its own intent ID, and the server sees two different intents. Whether that’s right is a business question: a customer with two tabs open almost certainly meant one booking. If the business agrees, the intent has to belong to something both tabs share. Create it on the server when the customer’s cart enters checkout, and have both tabs fetch the same intent ID. Then the second Book returns the first booking. The general lesson: one intent is a business definition that the design has to encode, not a technical detail.

Glossary: idempotency

Written and edited by Abhinav Taduka, enterprise software architect.