Quick revision
The short answer
Pricing and inventory reads are idempotent, so they get short timeouts, one or two jittered retries, and circuit breakers with fallbacks such as cached prices or an "availability unknown" state. Payment authorisation is not naturally idempotent, so we retry it only with an idempotency key and otherwise resolve an unknown outcome asynchronously by querying or reconciling, never by blindly charging again. Bulkheads keep slow inventory calls from using the threads payment needs, the total of all timeouts and retries fits inside the checkout deadline, and we prove the policy with fault injection and watch retry rates in production.
What to remember
In this answer, we designed checkout resilience from its 3 second deadline. Pricing and inventory reads get short timeouts, one jittered retry, circuit breakers and business-approved fallbacks, called in parallel. Payment authorisation is retried only with an idempotency key stored before the first attempt, and an unknown outcome becomes a pending order resolved by a status check or reconciliation, never a second charge. Bulkheads keep slow dependencies from using payment's capacity, and fault injection plus monitoring of retries, breakers and pending orders prove the policy works.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Pricing and inventory reads are idempotent, so they get short timeouts, one or two jittered retries, and circuit breakers with fallbacks such as cached prices or an "availability unknown" state. Payment authorisation is not naturally idempotent, so we retry it only with an idempotency key and otherwise resolve an unknown outcome asynchronously by querying or reconciling, never by blindly charging again. Bulkheads keep slow inventory calls from using the threads payment needs, the total of all timeouts and retries fits inside the checkout deadline, and we prove the policy with fault injection and watch retry rates in production.
Why this question is asked
Checkout is where resilience mistakes cost real money: a hung inventory call loses a sale, and a careless retry of a payment charges a customer twice. Interviewers ask this design question because it forces us to apply the same tools, retries, timeouts, circuit breakers and bulkheads, differently to calls with different risks. In this answer, we will recap the four patterns, set a deadline budget for checkout, design the policy for the read calls, then the very different policy for payment, isolate the dependencies with bulkheads, and close with how we test and monitor it.
1A Quick Recap of the Four Patterns
A timeout limits how long one call may wait. A retry repeats a failed call, which is only safe when repeating cannot change the outcome. A circuit breaker watches the failure rate to a dependency and, when it is too high, stops calling for a while and fails immediately, which protects both us and the struggling dependency. A bulkhead, named after the watertight compartments of a ship, limits how many concurrent calls one dependency may have, so a slow dependency cannot use up every thread in the service.
Our checkout service calls three dependencies. Pricing returns the current price of each item. Inventory checks and reserves stock. Payment authorises the charge with a payment provider. The first two are reads or can be made safely repeatable; the third moves money.
2Starting From the Checkout Deadline
We design from the outside in. Suppose the user-facing checkout call has a budget of 3 seconds at most, after which the page shows an error. Our own work, database writes and margin take about 500 ms, leaving 2.5 seconds for dependencies. Pricing and inventory are independent, so we call them in parallel, and payment comes after them because we only charge once we know the total and the stock.
| Call | Timeout | Retries | Breaker and fallback |
|---|---|---|---|
| Pricing (parallel) | 300 ms | 1, jittered | cached prices, re-checked at payment |
| Inventory (parallel) | 400 ms | 1, jittered | fail checkout or allow backorder |
| Payment authorisation | 1,500 ms | only with idempotency key | no fallback; resolve unknown outcome |
| Total budget | about 2.5 s | within the 3 s deadline | outer timeout on the whole flow |
Notice that payment gets the largest share. Payment providers are slower than internal services, often hundreds of milliseconds at p99, and a timeout that is too tight there creates the most dangerous kind of failure, an unknown outcome.
3Reads: Pricing and Inventory
Reading a price or checking stock is idempotent, so retrying is safe. We give each a timeout a little above its measured p99, say 300 ms for pricing and 400 ms for inventory, allow one retry with jittered backoff, and wrap each in a circuit breaker. With two attempts and a short backoff, pricing takes at most about 700 ms, which fits easily in the budget.
Fallbacks are a business decision. For pricing, we can show cached prices from the last few minutes if the service is down, but we must recompute or confirm the final price before charging, because we cannot charge a stale price. For inventory, the fallback depends on the business: some shops prefer to accept the order and handle a rare backorder, others prefer to refuse checkout. Reserving stock is a write; we make it safe to retry by passing the order id as a reservation key, so a duplicate reserve call finds the existing reservation.
4Payment: Retry Only When It Cannot Charge Twice
Payment authorisation is a POST that moves money, and a failed call does not tell us whether the provider charged the card. If the connection dropped after the request was sent, the authorisation may have succeeded. A blind retry could charge twice. So we follow two rules. First, every authorisation carries an idempotency key, created once per order and stored with it before the first attempt; if the provider supports idempotency keys, which most major providers do, a retry with the same key returns the original result instead of charging again. Second, if we cannot be sure, for example the provider does not support keys or our retries are exhausted, we do not guess. We mark the order as payment pending and resolve it asynchronously by querying the provider for the status of that key, or by a reconciliation job that compares our orders with the provider's report.
7 messages in order. Play them, or step through them one at a time.
Notice the order of operations. The key is saved with the order first, so even if our service crashes mid-call, the status check can find the outcome later. The user sees "we are confirming your payment" instead of an error that invites them to pay again.
5Bulkheads: Keeping Inventory Away From Payment's Threads
Without isolation, all calls share the same request threads and connection pools. If inventory becomes slow, every checkout waits on it, threads pile up waiting for inventory, and soon there are none left for payment, even though payment is perfectly healthy. A bulkhead per dependency caps that. With a semaphore bulkhead, for example at most 30 concurrent inventory calls and 50 concurrent payment calls, the 31st inventory call fails immediately instead of waiting, so inventory's trouble cannot spread to payment. Separate connection pools per dependency give the same isolation at the network level.
6Testing and Monitoring the Policy
A resilience policy we have not tested is a guess. In staging we inject faults with a tool such as Toxiproxy or WireMock fault responses: add 2 seconds of latency to inventory, return 503 from pricing, drop the connection after the payment request is sent. For each, we check that the checkout answers within 3 seconds, that the fallbacks appear, that payment is never duplicated, and that the pending orders are resolved by the status job.
In production we watch retry rates per dependency, breaker state changes, bulkhead rejections and the number of orders stuck in payment pending. A rising retry rate is an early warning; payment-pending orders older than a few minutes need an alert, because each one is a customer waiting to know whether they paid.
7Follow-up questions
Why not retry payment on a 503 from the provider?
A 503 usually means the request was not processed, so a retry is often safe, but only with the idempotency key. With the key, any retry is safe because the provider deduplicates. Without it, I would treat even a 503 cautiously and prefer a status check over a blind retry.
Should the checkout call pricing and inventory in sequence or in parallel?
In parallel, because they are independent. That makes their combined time the slower of the two instead of the sum, which leaves more of the 3 second budget for payment, the call that most needs it.
Where do circuit breakers fit for payment?
A breaker on payment is still useful: if the provider is failing most calls, opening the breaker stops us from piling up pending orders and lets us show a clear message such as "payments are temporarily unavailable". But the fallback is an honest error, not a guess at the outcome.
8Conclusion
In this answer, we designed checkout resilience from its 3 second deadline. Pricing and inventory reads get short timeouts, one jittered retry, circuit breakers and business-approved fallbacks, called in parallel. Payment authorisation is retried only with an idempotency key stored before the first attempt, and an unknown outcome becomes a pending order resolved by a status check or reconciliation, never a second charge. Bulkheads keep slow dependencies from using payment's capacity, and fault injection plus monitoring of retries, breakers and pending orders prove the policy works.
Open with
I would start from the checkout deadline, say 3 seconds, and budget it: about half a second for our own work, pricing and inventory in parallel, then payment with the biggest share because providers are slower.
Then, if they want more
Pricing and inventory reads are idempotent, so I give them timeouts a bit above their p99, around 300 to 400 milliseconds, one retry with jittered backoff, and a circuit breaker with a fallback the business agrees on, like cached prices that we re-confirm before charging, or refusing checkout if stock is unknown.
The stock reservation uses the order id as a key so retrying it is safe. Payment is different, because a timeout does not tell me whether the card was charged. So I store an idempotency key with the order before the first attempt and send it on every try, which makes retries safe with providers that deduplicate.
If the outcome is still unknown, I never retry blindly; I mark the order payment-pending, show the customer that we are confirming, and resolve it with a status query or reconciliation. Bulkheads per dependency stop a slow inventory service from eating the threads payment needs.
Then I would prove it with fault injection in staging, latency, 503s and dropped connections, and monitor retry rates, breaker state and stuck pending orders.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Spring Framework reference, Spring Web MVC
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Design a resilience policy (retries, timeouts, circuit breakers, bulkheads) for a...": https://scrivio-interview-library.netlify.app/spring-boot/http-clients/bfe3c460eb/