Skip to main content
App basics: HTTP, auth, dataLesson 9 of 11

Making Service Calls Survive Failures

Every call between services crosses a network that can be slow or broken. Follow one checkout request while the payments service struggles, and see which patterns keep the rest of the system standing.

Time budget—
Calls to payments1
Breaker—
User sees200 OK
ServicesClientcheckoutAPI gatewayedge proxyorderscalls two servicesClient policytimeout · retry · breakerCachelast known stockpaymentsPOST /chargesinventoryGET /stockPOST /checkoutForwardChargeReserve
RequestResponse / reportWatchAppears in a later step

What you will learn

  • Why one slow dependency spreads into a full outage
  • Timeouts on every call, and one budget across hops
  • Retries with backoff and jitter, and only for idempotent calls
  • How retries at every layer multiply load
  • Circuit breakers, bulkheads, load shedding and fallbacks

Patterns, and where they live​

PatternProtectsTypical settingWatch out
TimeoutThe caller from waiting foreverPer call, shorter than the caller's own timeoutToo long does nothing, too short fails healthy slow calls
Retry with backoff and jitterAgainst brief failures2 to 3 attempts, exponential wait with random spreadOnly idempotent requests, only in one layer
Retry budgetThe callee from retry stormsRetries limited to a share of normal trafficRetries silently stop when the budget is used up
Circuit breakerThe callee, and the caller's timeFailure ratio or count, cooldown, trial callsNeeds a fallback or a clear error for the open state
Bulkhead / pool limitOther dependencies of the same callerMax connections and pending requests per upstreamToo small rejects normal peaks
Load shedding / rate limitThe service itself429 or 503 with Retry-AfterClients must honor it
FallbackThe user experienceCache, default value, queue for laterMust not depend on the failing part
WhereExamplesGood forLimits
Client libraryresilience4j, Polly, gRPC retry and deadline settingsKnows which calls are idempotent and what fallback makes senseMust be done in every language and service
Service meshIstio VirtualService retries and timeouts, DestinationRule connection pools and outlier detection, Linkerd retries and budgetsSame policy for every service, no code changesDoes not know business meaning; fallbacks stay in code
Proxy or gatewayEnvoy, nginx, HAProxy, API gatewaysOne place at the edge, rate limits per clientSees only its own hop

Pick one layer for retries. A mesh that makes 3 attempts in front of a client library that also makes 3 attempts is the retry storm from step 6.

Try it yourself​

# A timeout on one call: 2 s to connect, 5 s for the whole request
curl -sS -o /dev/null -w '%{http_code} %{time_total}s\n' --connect-timeout 2 --max-time 5 https://example.com/

# curl's own retries: transient errors (timeouts, 408, 429, 500, 502, 503, 504),
# waiting 1 s then doubling; --retry-max-time caps the total time
curl -sS -o /dev/null --retry 3 --retry-max-time 20 https://example.com/

# See rate limit and Retry-After headers a server sends
curl -sSI https://example.com/ | grep -i -E 'retry-after|ratelimit'

# With Istio: retries, timeouts, pool limits and outlier detection per service
kubectl get virtualservice -A -o yaml | grep -E -A4 'retries:|timeout:'
kubectl get destinationrule -A -o yaml | grep -E -A6 'connectionPool:|outlierDetection:'

Check yourself

  1. payments is slow but not down, and orders has no timeout for it. Why do requests that never touch payments also start to fail?
  2. The gateway, orders and a mesh sidecar each make up to 3 attempts. During an overload, what does this do?
  3. A POST /charges call timed out. Why is an automatic retry risky without an idempotency key?

Further reading: Timeouts, retries and backoff with jitter (AWS Builders' Library) · Circuit breaker (Martin Fowler) · Envoy circuit breaking · gRPC deadlines · Service Mesh ② Splitting Traffic · Reverse Proxies and Load Balancing · Designing HTTP APIs