Timeouts
easy 30 minA timeout is the longest time you are willing to wait for something.
When it comes up
The moments this idea belongs in a design interview, and the moments it does not.
Signals
When to bring it up
| You hear | Say | Because |
|---|---|---|
| It calls another service | With a limit of about its p99.9 | Every arrow can hang |
| The request passes four services | One deadline, passed along | Separate limits do not add up |
| It calls another company | Short limit, or take it out of the request | You do not control its latency |
| Users upload files | A limit on silence and on the whole, sized for the file | One value does not fit both |
| Reports run on the main database | A statement limit and a separate pool | One query can hold locks and connections |
| Threads are exhausted | Which call has no limit? | It is nearly always one slow call |
Saying it in the room
Interviewer
Your checkout calls payments. How long do you wait?
You
The user gets an answer within 3 seconds. I measured payments: p99.9 is 800 milliseconds. So one attempt gets 1 second, and there is room for one more with the same key.
Interviewer
Two attempts of one second. What is left?
You
About 3 minus 2 minus 0.2 for the pause: 0.8 seconds for stock and for writing the order. I pass the remaining time to payments, so that it does not start a charge it cannot finish.
Interviewer
And if both time out?
You
Then I do not know whether the card was charged. The order is saved as pending, and a worker asks the provider with the same key.
Options
Compare your moves
A page calls a pricing service with p50 40 ms, p99 200 ms, p99.9 350 ms. Which limit?
Breaks30 seconds, to be safe
- How
- The library's example value.
- Limit
- At 100 calls a second a hang wants 3,000 threads. The pool is gone after a few seconds.
- Choose when
- Never for a page.
Works200 ms, the p99
- How
- Fail fast.
- Limit
- Cuts 1 good call in 100. A small slowdown cuts many, and retries add load.
- Choose when
- The value is optional and a good fallback exists.
StrongAbout 400 ms, capped by the remaining deadline
- How
- p99.9 of 350 ms plus room, min with what the request has left, one hedged or retried read, alert on the timeout rate.
- Limit
- Needs latency data and a deadline in the request.
- Choose when
- A normal internal read on the user's path.