Containing Failures with Circuit Breakers and Load Shedding
This lesson explains the mechanisms that stop failures spreading when a dependency fails persistently or a service receives more work than it can handle: circuit breakers on the calling side and load shedding on the serving side.
Learning outcomes
After completing this lesson, you will be able to:
- Describe how a circuit breaker opens and recovers.
- Explain how load shedding rejects excess work early.
- Describe graceful degradation and bulkheads.
Circuit breakers
A circuit breaker tracks failures of calls to a dependency. When failures exceed a threshold, it opens and fails calls immediately, returning a fallback such as cached data or a degraded response, which gives the dependency time to recover. After a pause it lets a few trial calls through (half-open) and closes again if they succeed. Circuit breakers are implemented in application libraries or service meshes; Step Functions with a DynamoDB status item can implement one for workflows.
Load shedding
Load shedding rejects excess work early, cheaply and explicitly, with HTTP 429 or 503, rather than accepting everything and timing out on all of it. A server that accepts more requests than it can process makes every request slow, so even the work it completes arrives too late to be useful; rejecting some requests quickly keeps the rest fast.
AWS provides several places to shed load before it reaches a fragile back end. API Gateway throttles at account, stage, method and usage plan level. Lambda reserved concurrency, and maximum concurrency on event source mappings, cap how much parallel work reaches a database. AWS WAF rate-based rules block abusive clients at the edge. A queue turns overload into a backlog rather than errors, which is often the best outcome for work that does not need an immediate answer.
Graceful degradation and bulkheads
Graceful degradation keeps the essential function working when a non-critical dependency fails, for example showing a product page without its recommendations rather than an error page. It requires deciding in advance which dependencies are essential and what the fallback is for each of the others.
Bulkheads give each dependency its own connection pool or thread pool, so that one slow dependency cannot consume the resources needed to call the others; without them, a single slow service can exhaust every connection and take down unrelated features. Per-client throttling applies the same idea to callers, so that one client cannot consume capacity meant for all.
An order service calls a payment provider's API. When the provider slows down, the service's containers exhaust their connection pools and the whole site becomes unavailable, including browsing. The company wants browsing to stay available during provider problems.
Adding containers only adds more blocked connections. The fix is to isolate the dependency: a separate connection pool (a bulkhead) and a circuit breaker on payment calls, and ideally accept orders into an SQS queue and process payments asynchronously so that the checkout path does not hold connections while the provider is slow. Browsing no longer shares fate with payments.
What does a circuit breaker do when a dependency keeps failing?
Show answer
It stops calling the dependency for a while and fails fast or returns a fallback, then lets a few test calls through before resuming normal traffic.
Exam Tips
Remember for the exam
- Circuit breakers stop calling a failing dependency and return a fallback.
- Load shedding rejects excess work early with HTTP 429 or 503 instead of timing out on everything.
- API Gateway throttling, Lambda reserved concurrency and queues protect back ends from overload.
- Bulkheads give each dependency its own resources so one cannot exhaust the others.
- Degrade gracefully when non-critical dependencies fail.