Scrivio Interview library
DesignIntermediate6 min read · updated 12 November 2026

A checkout API must respond within 500 ms at p99 and calls inventory, pricing and payment services. How would you set latency budgets, timeouts and retries?

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.

Budget for the checkout request (p99 500 ms)
StepBudgetClient timeout
Validate cart, load customer40 ms-
Inventory and pricing, in parallel150 msinventory 140 ms, pricing 120 ms
Payment authorisation200 ms190 ms, no automatic retry
Write order, build response40 ms-
Margin for GC pauses, queueing70 ms-
Total500 msgateway 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.

Java
ExecutorService io = Executors.newVirtualThreadPerTaskExecutor();
CompletableFuture<Stock> stock = CompletableFuture
.supplyAsync(() -> inventory.check(cart), io) // RestClient, read timeout 140 ms
.orTimeout(150, TimeUnit.MILLISECONDS); // fail the checkout step at 150 ms
Prices cached = priceCache.lastKnown(cart); // local, about 1 ms
CompletableFuture<Prices> prices = CompletableFuture
.supplyAsync(() -> pricing.quote(cart), io) // RestClient, read timeout 120 ms
.completeOnTimeout(cached, 150, TimeUnit.MILLISECONDS) // slow pricing -> cached prices
.exceptionally(e -> cached); // pricing failed -> cached prices
Stock s = stock.join(); // about 110 ms typical
Prices p = prices.join(); // ready at the same time: both ran together

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.

Step throughNested timeouts, outermost first
  1. Gateway timeout: 1,000 mslarger than checkout's whole budget
  2. Checkout request budget: 500 msp99 target
  3. Payment client: 190 msinside its 200 ms step
  4. 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.

What to say in the interviewAbout 80 seconds aloud

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/