Course contentsShow
← Cloud and Infrastructure
Lesson 2582 of 2,98955. Microservices on CloudFree lesson

Retry and Timeout Strategies

Configuring exponential backoff, jitter, and timeout policies for resilient inter-service communication.

Retry and Timeout Strategies

You'll learn how to configure exponential backoff, jitter, and timeout policies to handle transient failures gracefully in microservice communication.

What Is This About?

When services communicate over a network, temporary failures happen: a service might be overloaded, a network packet drops, or a brief outage occurs. Retry and timeout strategies prevent cascading failures by intelligently retrying failed requests and abandoning hopeless ones before they consume all resources.

Core Components

Timeouts set maximum wait times for responses. Without them, your service might wait indefinitely for a response that never comes, exhausting threads and connections.

Exponential backoff increases delay between retry attempts exponentially (e.g., 1s, 2s, 4s, 8s). This prevents overwhelming an already-struggling downstream service with immediate retries—like giving someone space to recover rather than pestering them repeatedly.

Jitter adds randomness to retry delays. If 100 services all retry simultaneously after the same delay, they create thundering herd problems. Jitter staggers these retries across time, spreading the load.

How They Work Together

Attempt 1: Fail immediately → Wait 1s + random(0-200ms)
Attempt 2: Fail → Wait 2s + random(0-400ms)
Attempt 3: Fail → Wait 4s + random(0-800ms)
Attempt 4: Fail → Circuit breaker opens

Configure maximum retry attempts and cap delays to prevent infinite waits. Combine with Circuit Breaker Pattern (from your previous lesson) to stop retries when a service is definitively down.

Configuration Example

Set request timeout to 5 seconds. Use exponential backoff starting at 1 second with jitter. Retry up to 3 times for transient errors (5xx, timeouts) but never for client errors (4xx).

Key Takeaway: Exponential backoff with jitter and proper timeouts make microservices resilient to transient failures, preventing both resource exhaustion and thundering herds while gracefully handling temporary issues.