AlgoViz

Timeouts

easy 30 min

A 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 hearSayBecause
It calls another serviceWith a limit of about its p99.9Every arrow can hang
The request passes four servicesOne deadline, passed alongSeparate limits do not add up
It calls another companyShort limit, or take it out of the requestYou do not control its latency
Users upload filesA limit on silence and on the whole, sized for the fileOne value does not fit both
Reports run on the main databaseA statement limit and a separate poolOne query can hold locks and connections
Threads are exhaustedWhich call has no limit?It is nearly always one slow call

Saying it in the room

  1. Interviewer

    Your checkout calls payments. How long do you wait?

  2. 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.

  3. Interviewer

    Two attempts of one second. What is left?

  4. 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.

  5. Interviewer

    And if both time out?

  6. 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.