01

Why this matters

In distributed systems, failures are inevitable. Some failures are immediate, others are silent and destructive.

When a request fails to return, both client and server may waste resources. This can lead to cascading failures.

Timeouts are essential to convert slow failures into fast ones.

02

Fast vs Slow Failures

Fast failures occur immediately.

Example: A service returns a 503 error.

Slow failures occur silently.

Example: No response from a service after a request is sent.

Both services hold onto resources.

These include memory, threads, and open connections.

As more requests pile up, resources may be exhausted.

Eventually, one service may crash.

03

Timeout Types

There are two types of timeouts:

  • Connection timeout
  • Request timeout

Connection timeout defines how long a client waits to establish a connection.

Typical value: Tens of milliseconds.

This is because connection setup is fast and lightweight.

Request timeout defines how long a client waits for a response after the connection is established.

It applies when server-side processing takes too long.

04

Choosing Request Timeout

Setting a request timeout is tricky.

If too high:

  • Resources are still consumed while waiting.

If too low:

  • The client may miss responses.

A common practice:

  • Analyze the 0.1% percentile of request latency.

  • Set this value as the request timeout.

This reduces tail latencies.

Still, 0.1% of all requests will timeout.

05

What to do with failed requests

The failed request must be handled.

It may require retries, logging, or fallbacks.

The system must define how to respond to timeouts.

Questions

  • What is the difference between connection and request timeouts?
  • Why is 0.1% of request latency a common benchmark?
  • How do slow failures consume system resources?
  • What happens if a request timeout is set too low?
  • Why is it important to reduce tail latencies?
  • How does a timeout convert a slow failure into a fast one?
  • What are the consequences of not handling failed requests?
  • Can a timeout prevent a service from crashing?

Key takeaways

  • Failures are inevitable in distributed systems.
  • Slow failures waste resources and can cause cascading failures.
  • Timeouts convert slow failures into fast ones.
  • Connection timeout is short (tens of ms).
  • Request timeout is set to the 0.1% percentile of request latency.
  • 0.1% of requests will still timeout.
  • Failed requests must be handled with retries or fallbacks.