# Timeout

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

**Field:** Software Development  
**Category:** Architecture  
**Also known as:** Request Timeout, Connection Timeout, Network Timeout

## Think of it like

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

## 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

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.

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

## Why it matters

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

## Common mistake

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

## Three principles

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

## Related terms

- [Retry with Exponential Backoff](https://learn.benibix.com/term/development/retry-with-backoff)
- [Circuit Breaker Pattern](https://learn.benibix.com/term/development/circuit-breaker)
- [Latency](https://learn.benibix.com/term/infrastructure/latency)
- [Model Fallback](https://learn.benibix.com/term/development/model-fallback)
- [HTTP Client](https://learn.benibix.com/term/development/http-client)
- [Deadlock](https://learn.benibix.com/term/development/deadlock)

![A checkout app calls a tax service. A clock on the line counts to a 2 second limit. The service has not answered, so at 2 seconds the call is cut and the app shows an error. Below, without a timeout, the same call waits on and on while more requests pile up behind it.](https://learn.benibix.com/diagrams/dev6-timeout.svg)

---

Source: https://learn.benibix.com/term/development/timeout
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-18
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
