Quick revision
The short answer
I would split the 500 ms into budgets for each call and for checkout's own work, keeping a margin. Inventory and pricing are independent, so they run in parallel and share one slot of the budget, followed by payment. Each client timeout sits below its budget, outer timeouts are larger than inner ones, at most one retry is allowed and only for idempotent calls that still fit, and when pricing is slow we degrade to cached prices instead of failing the checkout.
What to remember
In this answer, we split a 500 ms p99 checkout into budgets for checkout's own work, a parallel step for inventory and pricing, a payment step and a margin. We ran the independent calls concurrently with CompletableFuture, set client timeouts below each step's budget and kept outer timeouts larger than inner ones. We allowed at most one retry, only for idempotent calls that fit, protected payment with idempotency keys, and degraded to cached prices when pricing was slow.
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.
I would split the 500 ms into budgets for each call and for checkout's own work, keeping a margin. Inventory and pricing are independent, so they run in parallel and share one slot of the budget, followed by payment. Each client timeout sits below its budget, outer timeouts are larger than inner ones, at most one retry is allowed and only for idempotent calls that still fit, and when pricing is slow we degrade to cached prices instead of failing the checkout.
Why this question is asked
A checkout that is slow costs money directly, so a p99 target like 500 ms is common in real systems. Meeting it is not about making one service fast; it is about how the time is shared between the calls. Interviewers ask this design question to see whether we can do the arithmetic, run calls concurrently and make timeouts and retries consistent. In this answer, we will recap what a p99 budget means, split the 500 ms, run inventory and pricing in parallel, set timeouts that nest correctly, decide on retries and design the degraded paths.
1A Quick Recap: What a 500 ms p99 Means
p99 is the 99th percentile of latency: 99 out of 100 checkouts must finish within 500 ms. It is a promise about the slow tail, not the average, which matters because the tail is where calls to several services pile up. If each of three sequential calls has a p99 of 200 ms, the checkout's p99 is not 200 ms; in the worst case the delays add up.
A latency budget is the share of the 500 ms each step may spend. Writing it down turns the target into numbers each team can design for, and turns a missed target into a question with an owner: which step spent more than its share?
2Splitting the 500 ms
Checkout has its own work, such as validating the cart, reading the customer and writing the order, plus three calls. Inventory and pricing do not depend on each other, but payment must come after both, because we only charge a confirmed total for items we have. So the critical path is: own work, then the slower of inventory and pricing, then payment, then writing the order.
| Step | Budget | Client timeout |
|---|---|---|
| Validate cart, load customer | 40 ms | - |
| Inventory and pricing, in parallel | 150 ms | inventory 140 ms, pricing 120 ms |
| Payment authorisation | 200 ms | 190 ms, no automatic retry |
| Write order, build response | 40 ms | - |
| Margin for GC pauses, queueing | 70 ms | - |
| Total | 500 ms | gateway timeout 1,000 ms |
Notice the margin of 70 ms. Garbage collection pauses, thread pool queueing and network jitter are real, and a budget that adds up to exactly 500 ms will be missed at p99. Notice also that running inventory and pricing in parallel saves a whole step: sequentially they would need 270 ms, which leaves too little for payment.
3Running Inventory and Pricing in Parallel
In Java we can run the two calls concurrently with CompletableFuture. With virtual threads, an executor that starts a new virtual thread per task makes these blocking calls cheap.
Notice that orTimeout and completeOnTimeout only stop us waiting; they do not cancel the HTTP call underneath. That is why the RestClient read timeouts are set too, slightly below the step budget, so the threads and connections are released at the same time. Structured concurrency, StructuredTaskScope, expresses the same idea more safely by cancelling the sibling task when one fails; it is still a preview API in recent JDKs and its shape has changed between releases, so check your version before using it.
4Timeouts Must Nest: Inner Smaller Than Outer
Every layer has a timeout, and they must form a nested set. The API gateway in front of checkout must wait longer than checkout's whole budget, or the gateway gives up while checkout is still working and may still charge the card. Inside checkout, each client timeout must be smaller than the step's budget.
The opposite arrangement is a classic bug. If payment's client timeout is 2 seconds but the gateway gives up at 1 second, the user sees an error while the payment may still succeed a moment later. The user retries, and now we risk charging twice.
- Gateway timeout: 1,000 mslarger than checkout's whole budget
- Checkout request budget: 500 msp99 target
- Payment client: 190 msinside its 200 ms step
- Inventory 140 ms, pricing 120 msinside the 150 ms parallel step
4 layers, from the top down. Step through them one at a time.
5Retries: At Most One, and Only When Safe
A retry spends the budget again, so it must fit. Pricing and inventory reads are idempotent, safe to repeat, but with a 150 ms step there is no room for a second full attempt. A retry with a shorter attempt, say two attempts of 60 ms, is possible only if their p99 is well below 60 ms, which we check with real data.
Payment is the case to be careful with. Charging a card is not naturally idempotent: if the first attempt timed out, it may have succeeded. We only retry payment if the payment API accepts an idempotency key, a unique id we send with the request so that a repeated request returns the first result instead of charging again, and even then usually not inside the 500 ms request, but in a recovery process that checks the payment status.
6Degrading Gracefully When a Dependency Is Slow
Degrading means giving a slightly worse answer instead of an error. Pricing is a good candidate: we can show the last known prices from a cache and mark the order for price confirmation, because prices change rarely and the difference can be handled. The business has to agree to this rule, for example accepting a cached price up to 10 minutes old.
Inventory can sometimes degrade too, by accepting the order and confirming stock asynchronously, with a cancellation path if the item is gone. Payment cannot degrade silently; if it does not answer in time, we tell the user honestly that the result is pending and resolve it in the background. Each degraded path is counted in metrics, so we know how often we use it.
7Follow-up questions
Why not simply give each call a long timeout to avoid errors?
Because the user is waiting either way. A long timeout turns a fast error into a slow error, holds threads and connections longer and can push the gateway past its own timeout. A short timeout with a fallback gives the user an answer inside the target, which is what the business asked for.
How do you know the budget numbers are right?
From measurements. We take each dependency's p99 from production metrics or load tests, set the budgets so that each step's p99 fits with room to spare, and then watch per-step latency in traces. If a step regularly exceeds its share, either that service needs work or the budget must be renegotiated.
What if payment alone often takes 400 ms?
Then the 500 ms target and the design do not fit, and arithmetic tells us so before production does. Options are to start payment authorisation earlier, for example right after the cart is validated in parallel with pricing when the total is known, to move authorisation off the synchronous path with a pending status, or to agree a different target for this journey with the business.
8Conclusion
In this answer, we split a 500 ms p99 checkout into budgets for checkout's own work, a parallel step for inventory and pricing, a payment step and a margin. We ran the independent calls concurrently with CompletableFuture, set client timeouts below each step's budget and kept outer timeouts larger than inner ones. We allowed at most one retry, only for idempotent calls that fit, protected payment with idempotency keys, and degraded to cached prices when pricing was slow.
Open with
I would start from the critical path. Checkout has its own work, inventory and pricing are independent, and payment depends on both. So I would budget roughly 40 ms for validation, 150 ms for inventory and pricing in parallel, 200 ms for payment, 40 ms to write the order, and keep about 70 ms margin for GC and queueing, since a budget that sums exactly to 500 never holds at p99.
Then, if they want more
I would run inventory and pricing concurrently with CompletableFuture on virtual threads, or with structured concurrency if the JDK version supports it, and set each RestClient read timeout slightly below its step, because orTimeout alone does not cancel the HTTP call.
Timeouts must nest: the gateway waits longer than checkout's whole budget, and each client timeout is smaller than its step, otherwise the user sees an error while a payment still goes through. Retries: at most one, only for idempotent calls and only if both attempts fit; for payment only with an idempotency key, and usually in a recovery process.
And I would degrade where the business accepts it, such as showing cached prices when pricing is slow, with metrics on every fallback.
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 official documentation for the version you use. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
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 "A checkout API must respond within 500 ms at p99 and calls inventory, pricing and...": https://scrivio-interview-library.netlify.app/spring-boot/service-performance/9fe469c34f/