Skip to content
BENIBIX Learn

Timeout

Development🏗️ ArchitectureDistributed Systems

Also known as Request Timeout, Connection Timeout, Network Timeout

The longest a program will wait for a reply. Then it gives up.

Think of it like

It is like waiting for a friend at the park. After ten minutes, you stop waiting and go home.

Example

Jack's checkout calls a tax service with a 2-second timeout. When the service hangs, checkout shows a kind error. It does not spin forever.

Why it matters

Waiting forever ties up threads and memory. One stuck service can then bring down every service that calls it.

Definition

A timeout is the longest a program will wait for something before it gives up. A call to another service, a database query or a network link can each have one. When time runs out, the caller stops waiting and treats the call as failed. It can then retry, use a backup plan or show an error. With no timeout, one slow service can leave every caller stuck.

Example code

python
import requests

r = requests.get("https://example.com/api/rates", timeout=2)
If the server stays silent for 2 seconds, requests stops waiting and raises an error.
With a 2-second timeout the call is cut and the app moves on. Without one, requests pile up.

Common mistake

Keeping the default, which in many code kits is no timeout at all. Set one on every call over the network.

Key takeaways

  1. 1
    A limit on waiting. Then give up.
  2. 2
    Fail fast. Better than hanging.
  3. 3
    Pair with retries. Try again, with care.