One Slow Service Took Down Our Whole App: Timeouts, Circuit Breakers and Bulkheads Explained
It was 8 PM on the first evening of a big sale. Traffic was high but expected. We had scaled up the night before. Dashboards were green.
Then the checkout page started returning errors.
The strange part: the checkout service itself looked healthy. CPU was around 20%. The database was calm. Memory was fine. Nothing had been deployed that day.
It took us about 25 minutes to find the real cause. It was not checkout at all. It was a small recommendations service, the "you may also like" box at the bottom of the checkout page.
This post explains what happened, how we fixed it, and how to explain it in an interview.
What actually happened
The recommendations service called a machine learning model to decide which products to show. Under sale traffic, that model became slow. It did not crash. It did not return errors. Every call just took around 30 seconds instead of 50 ms.
Checkout called the recommendations service on every page load. And the HTTP client had no timeout configured. The library default was effectively "wait forever".
So here is what happened, step by step:
- A user opens checkout.
- Checkout calls recommendations and waits.
- The thread handling that user is now stuck for 30 seconds.
- More users arrive. More threads get stuck.
- The thread pool (and the outgoing connection pool) fills up completely.
- New requests have no free thread, so they queue and then fail.
Checkout was not broken. It was simply busy waiting. Low CPU, no errors in its own code, and still completely unavailable.
One optional feature took down the most important page in the business. This is called a cascading failure: a problem in one service spreads to every service that depends on it.
Why "slow" is worse than "down"
If recommendations had been fully down, connections would have been refused in milliseconds. Checkout would have got an error quickly, freed the thread, and moved on.
A slow service is worse because it holds your resources. Every waiting request holds a thread, a socket and memory. A slow dependency quietly turns into a resource leak in every caller.
That is why the first fix is always about the caller, not the slow service.
Fix 1: A timeout on every network call
Every call over the network needs a timeout. No exceptions.
Set it based on what the call normally takes, not on hope. Recommendations normally answered in 50 ms, with a p99 of about 150 ms. We set the timeout to 300 ms.
import requests
try:
resp = requests.get(
"http://recommendations/api/v1/items",
params={"user": user_id},
timeout=(0.1, 0.3), # 100 ms to connect, 300 ms to read
)
items = resp.json()
except requests.exceptions.RequestException:
items = fallback_items()
Check timeouts at every layer: HTTP clients, database drivers, Redis clients, and load balancers. Many libraries default to no timeout at all.
Fix 2: A circuit breaker
A timeout limits how long one call waits. But if the service is slow for every call, we still waste 300 ms on each request and keep hammering a service that is already struggling.
A circuit breaker works like the one in your house. It has three states:
- Closed: calls go through normally. Failures are counted.
- Open: after too many failures (for example 50% of calls failing in the last 20 seconds), stop calling the service completely. Fail fast and use the fallback.
- Half-open: after a cool-down (for example 30 seconds), let a few test calls through. If they succeed, close the circuit. If not, open it again.
A simple version looks like this:
import time
class CircuitBreaker:
def __init__(self, max_failures=5, reset_after=30):
self.max_failures = max_failures
self.reset_after = reset_after
self.failures = 0
self.opened_at = None
def call(self, func, fallback):
if self.opened_at:
if time.time() - self.opened_at < self.reset_after:
return fallback() # open: fail fast
self.opened_at = None # half-open: try once
try:
result = func()
self.failures = 0
return result
except Exception:
self.failures += 1
if self.failures >= self.max_failures:
self.opened_at = time.time()
return fallback()
In real systems, use a tested library or the service mesh: Resilience4j in Java, Polly in .NET, or outlier detection in Istio or Envoy.
# Istio DestinationRule: eject a failing host for a while
trafficPolicy:
connectionPool:
http:
http1MaxPendingRequests: 50
maxRequestsPerConnection: 10
outlierDetection:
consecutive5xxErrors: 5
interval: 10s
baseEjectionTime: 30s
Fix 3: A fallback that makes sense
Failing fast only helps if you have something useful to do instead. For recommendations, the fallback was easy: show a cached "popular items" list, or hide the box. Nobody abandons a purchase because the "you may also like" box is missing.
Decide this for every dependency ahead of time. Ask: "If this call fails, what is the best thing we can show the user?" For some calls, like payment, the honest answer is a clear error message. For many others, a default or a cached value is fine.
Fix 4: Bulkheads
Ships have walls called bulkheads, so one leak floods only one section, not the whole ship.
In software, it means giving each dependency its own limited pool of threads or connections. Recommendations got a small pool of 20 connections. Payment and inventory got their own pools. When recommendations got slow, only its 20 connections were stuck. Payment kept working.
Fix 5: Careful retries
During the incident, our retries made things worse. Each failed call was retried three times, so a struggling service got four times the traffic.
Retry only when it is safe (idempotent calls), only a small number of times, with exponential backoff and random jitter. And never retry when the circuit is open.
What we monitor now
- p99 latency for every outgoing dependency, not just our own endpoints
- Thread pool and connection pool usage, with an alert at 80%
- Circuit breaker state changes (an open circuit is a page-worthy signal)
- How often fallbacks are served
How to answer this in an interview
A common question: "One downstream service becomes slow and your whole application goes down. What happened, and how do you prevent it?"
A weak answer: "Scale up the slow service."
A strong answer covers:
- Why slow is worse than down: waiting requests hold threads and connections.
- Timeouts on every network call, based on real latency.
- A circuit breaker to fail fast, with closed, open and half-open states.
- A fallback for non-critical features.
- Bulkheads so one dependency cannot use up all resources.
- Limited retries with backoff and jitter.
- Monitoring dependency latency and pool usage.
If you can tell it as a real story with numbers, like the 30-second calls and the full thread pool, it stands out.
The lesson
After 14+ years in production systems, this is one of the patterns I trust the most: protect the caller first. A dependency that is slow is often more dangerous than one that is down, and the cheapest protection is a timeout you set today.
Let's connect: Free 15-min Cloud & DevOps Interview Guidance Call 👆 link in bio (topmate.io/cloudtechbydevang)
About the author
- I help engineers learn cloud, DevOps, SRE and AI in simple English, crack interviews and follow clear roadmaps. 14+ years building and running platforms on AWS, GCP, Kubernetes and Terraform. One topic a day.
Comments
Join the discussionBulkheads are the part teams skip until the first big sale. Nice breakdown of when each pattern actually helps.
A non-critical "you may also like" widget stalling the entire checkout path while CPU sits at 20% is classic cascading saturation. Wrapping optional widgets behind strict short timeouts and a static fallback keeps the critical path alive.
