Quick revision
The short answer
gRPC calls have no deadline by default, so when inventory got stuck, each call waited forever and checkout's threads piled up; the old REST client's 2-second read timeout did not carry over to the new stubs. We set a deadline on every call, for example stub.withDeadlineAfter(300, TimeUnit.MILLISECONDS), derived from the caller's remaining budget, and rely on gRPC Java propagating the remaining deadline through the request Context so deadlines shrink along the chain. Status codes are mapped deliberately: UNAVAILABLE, and DEADLINE_EXCEEDED when budget remains, may be retried with backoff for idempotent methods, while INVALID_ARGUMENT, NOT_FOUND and PERMISSION_DENIED must not be; retries go in the service config retry policy with a small maximum, and circuit breakers and bulkheads stay.
What to remember
In this answer, we saw that gRPC calls have no deadline by default, so a stuck inventory server held checkout threads indefinitely once the REST client's 2-second timeout was gone. We set a deadline on every call from the caller's remaining budget, let gRPC Java propagate the remaining deadline through the Context so it shrinks along the chain, retried only safe codes for idempotent methods through a small service-config retry policy, and kept circuit breakers and bulkheads in place.
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.
gRPC calls have no deadline by default, so when inventory got stuck, each call waited forever and checkout's threads piled up; the old REST client's 2-second read timeout did not carry over to the new stubs. We set a deadline on every call, for example stub.withDeadlineAfter(300, TimeUnit.MILLISECONDS), derived from the caller's remaining budget, and rely on gRPC Java propagating the remaining deadline through the request Context so deadlines shrink along the chain. Status codes are mapped deliberately: UNAVAILABLE, and DEADLINE_EXCEEDED when budget remains, may be retried with backoff for idempotent methods, while INVALID_ARGUMENT, NOT_FOUND and PERMISSION_DENIED must not be; retries go in the service config retry policy with a small maximum, and circuit breakers and bulkheads stay.
Why this question is asked
Protocol migrations are often treated as a transport swap: replace the HTTP client with a generated stub and move on. But a client library carries policies with it, and the most important one, how long to wait, was silently lost here. Interviewers ask this because it tests whether we understand deadlines as a design element of a call chain rather than a tuning knob. In this answer, we will see why the threads piled up, set deadlines properly, follow how they propagate, decide which status codes to retry, configure retries, and keep the resilience patterns we already had.
1Why the Threads Piled Up
The checkout service handles each request on a thread from a pool. With REST, the HTTP client was configured with a 2-second read timeout, so when inventory was slow, a checkout thread waited at most 2 seconds, failed the call, and was free again. In gRPC Java, a call has no deadline unless we set one. A blocking stub call to an inventory server that accepted the request but never answered simply waits, for minutes or forever.
During the partial outage, every checkout request that touched a stuck inventory instance took a thread and kept it. The pool emptied in seconds, new requests queued, memory grew, health checks timed out, and the service fell over. The outage of one dependency became an outage of checkout, which is exactly what timeouts exist to prevent.
2Setting a Deadline on Every Call
A deadline in gRPC is a point in time by which the call must finish; the client sends it to the server with the request. We set it per call, and we derive it from the caller's own budget rather than picking a number per call site in isolation. If checkout promises its callers an answer within 1 second and has already spent 400 ms, the inventory call cannot have more than what remains.
Because it is easy to forget withDeadlineAfter at one call site, many teams add a client interceptor that applies a default deadline whenever the call options have none, and a test that fails the build if a stub is used without one. The value comes from measurement: a little above the dependency's p99 latency, and inside the caller's budget.
3How Deadlines Shrink Along the Chain
gRPC Java keeps the incoming request's deadline in its Context, an object bound to the thread handling the request. When the server makes outgoing calls within that Context, the effective deadline of each outgoing call is the earlier of its own deadline and the one inherited from the Context. So deadlines shrink as the request travels down the chain, and a service deep in the chain never works on a request whose original caller has already given up.
7 messages in order. Play them, or step through them one at a time.
Notice the catch: the Context lives on the request thread. If we hand work to another executor, we must carry the Context along, for example with Context.current().wrap(task) or a Context-aware executor, otherwise the downstream call loses the deadline and we are back to waiting forever.
4Mapping Status Codes Deliberately
gRPC returns a status code with every failed call, and each code means something different for the caller. UNAVAILABLE means the server could not be reached or refused the call before processing, and is usually safe to retry with backoff. DEADLINE_EXCEEDED means we ran out of time; the server may or may not have done the work, so we retry only idempotent methods, and only if our own budget still has room. INVALID_ARGUMENT, NOT_FOUND and PERMISSION_DENIED describe the request itself, so retrying sends the same bad request again and must never happen.
For Reserve, idempotence matters: retrying a reservation that may have succeeded could reserve twice, so we send an idempotency key, such as the checkout id, that the inventory service uses to recognise a repeat.
5Retries in the Service Config, With the Old Safeguards
gRPC has built-in retries configured through the service config, per service or method, with a maximum number of attempts, exponential backoff and the status codes to retry. Built-in retries share the call's one overall deadline, so they cannot extend the wait beyond it.
We keep the maximum small, because retries multiply load on a struggling service; three attempts across five layers can become 243 calls. And the transport change does not replace the resilience patterns we had: a circuit breaker that stops calling inventory when most calls fail, and a bulkhead that limits how many threads checkout may spend waiting on inventory, so even a mistake in deadlines cannot take every thread.
6Follow-up questions
What does the client see when the deadline expires while the server is still working?
The client gets DEADLINE_EXCEEDED immediately at the deadline and moves on. The server is told the call was cancelled: its Context is cancelled, and code can check Context.current().isCancelled() or register a cancellation listener to stop work early. But any work already done, such as a reservation written to the database, stays done. That is why the client cannot assume a deadline failure means nothing happened, and why retried operations need idempotency keys.
Should the deadline be the same for every call?
No. It should come from the dependency's measured latency and the caller's remaining budget. A cheap cache lookup might get 50 ms and a report query several seconds, always within what the caller has left.
Does a non-blocking stub avoid the thread pile-up?
It avoids blocking threads, but calls without deadlines still never finish, so pending calls, memory and the user's wait grow without limit. Async code needs deadlines just as much.
7Conclusion
In this answer, we saw that gRPC calls have no deadline by default, so a stuck inventory server held checkout threads indefinitely once the REST client's 2-second timeout was gone. We set a deadline on every call from the caller's remaining budget, let gRPC Java propagate the remaining deadline through the Context so it shrinks along the chain, retried only safe codes for idempotent methods through a small service-config retry policy, and kept circuit breakers and bulkheads in place.
Open with
gRPC calls have no deadline by default. The old REST client had a 2-second read timeout, but that setting did not come along with the migration, so when some inventory instances hung, each checkout call waited indefinitely, the thread pool ran out and checkout fell over.
Then, if they want more
The fix is a deadline on every call, for example stub.withDeadlineAfter(300, TimeUnit.MILLISECONDS), derived from checkout's own remaining budget, and I would add a client interceptor that applies a default so no call can go without one.
In gRPC Java the deadline travels in the Context, so when a server makes outgoing calls within the request's Context, the remaining deadline is passed downstream and deadlines shrink along the chain; if work moves to another executor, the Context has to be carried with it. Then I map status codes on purpose.
UNAVAILABLE, and DEADLINE_EXCEEDED if budget is left, can be retried with backoff, but only for idempotent methods or with an idempotency key. INVALID_ARGUMENT, NOT_FOUND and PERMISSION_DENIED are never retried.
I would configure retries in the service config retry policy with a maximum of about three attempts and exponential backoff, and keep the circuit breaker and bulkhead we had with REST, because changing the transport does not replace them.
About this answer
- Last updated
- 13 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 "Why did this happen, and how should deadlines, retries and error codes be handled with...": https://scrivio-interview-library.netlify.app/architecture/api-design-at-scale/06d3b0351f/