Lesson 6 of 9 · 25m
Failure Modes: Timeouts, Retries, and Backpressure
Design outbound calls, retries, queues, and bulkheads around partial failure instead of assuming dependency outages are rare exceptions.
Dependencies do not fail cleanly in production. They become slow, half-open, intermittently reset, or correct but thirty seconds late. Your service then fails not because the dependency is down, but because every request thread waits on it. Resilience is capacity management under uncertainty.
Every network call needs a deadline
'No timeout' means the timeout is the operating system, the proxy, the client, or the customer closing the browser — whichever happens last. Set connect, read, and overall request deadlines deliberately:
RestClient client = builder
.baseUrl("https://inventory.internal")
.requestFactory(ClientHttpRequestFactories.get(
ClientHttpRequestFactorySettings.DEFAULTS
.withConnectTimeout(Duration.ofSeconds(1))
.withReadTimeout(Duration.ofSeconds(3))))
.build();A read timeout is not a total operation timeout when redirects, retries, or response streaming are involved. If the workflow has a user-facing budget, enforce that budget at the orchestration layer too.
Retry only operations that are safe or made safe
Retrying a non-idempotent POST can duplicate charges, emails, orders, or inventory reservations. Safe retry needs one of three things: a naturally idempotent operation, an idempotency key accepted by the downstream service, or a deduplication mechanism you control:
POST /v1/payments
Idempotency-Key: 7a6a62c7-9f9a-4ac2-a0cb-4a87de82250eUse exponential backoff with jitter. A fixed one-second retry across a thousand workers is not resilience; it is a synchronized retry storm.
Circuit breakers protect capacity, not feelings
A breaker that opens after repeated failures prevents a sick dependency from consuming all worker threads or event-loop capacity. It must be paired with a fallback strategy and observability. Silent fallbacks create silent data corruption.
closed normal calls flow
open fail fast and shed load
half-open limited probes test recoveryDo not wrap every call in the same global breaker. Inventory, pricing, email, and analytics have different criticality. Bulkhead thread pools or virtual-thread concurrency limits so one dependency cannot monopolize the application.
Queues shift failure; they do not delete it
Asynchronous work can absorb bursts, but poison messages, schema mismatches, slow consumers, and retry loops still exist. A durable queue needs dead-letter handling, idempotent consumers, redrive tooling, and lag metrics. 'We put it on a queue' is the start of an operational design, not the end.
Backpressure is a product decision
When capacity is exhausted, choose what happens: reject low-priority work, degrade optional recommendations, queue writes, return stale reads, or fail with a clear 503. If the application does not choose, thread pools and garbage collection will choose for you.
Field notes
- Retry timeouts can multiply latency. Three attempts at five seconds is not a five-second dependency budget.
- Test failure paths with latency injection, malformed responses, and connection resets, not only clean HTTP 500 responses.
- A fallback cached value must carry age or staleness metadata if correctness depends on freshness.
- Log retry exhaustion with correlation IDs, but do not log full payloads containing credentials or personal data.
- Resilience annotations are easy to scatter without ownership. Prefer explicit resilience components around integration clients.
Was this lesson helpful?