SkillSprout
Chapter 24 · Lesson 2
Intermediate
4 min read

Circuit Breakers, Bulkheads, Fallbacks and Graceful Degradation

Overview

Timeouts and retries handle single failures. When a dependency is persistently broken you need patterns that stop the damage spreading: a circuit breaker, a bulkhead, a fallback, graceful degradation and backpressure.

Detailed Notes

What is a cascading failure, and how do we contain it

A cascading failure is when a failure in one component causes failures in the components that depend on it. It is a common cause of large outages, and the patterns below contain it.

The problem it solves

On a streaming site's home page, three services contribute: catalog, recommendations and continue watching. Recommendations starts failing.

  • Without protection: every request waits for recommendations, times out and retries. Threads fill up and even the catalog cannot be served.
  • With protection: a circuit breaker stops calling recommendations and a fallback shows "Popular right now" from a cache. The catalog and playback are unaffected.

How it works

Circuit breaker. A wrapper around a remote call that stops sending calls when too many have failed recently, like the breaker in a fuse box. Calling a broken service wastes resources and adds load to it; failing immediately is cheaper for everyone. It has three states:

  • Closed: normal. Calls pass through and failures are counted.
  • Open: calls fail immediately (or use a fallback) for a cool-down period.
  • Half-open: after the cool-down a few trial calls are allowed. Success closes the circuit; failure reopens it.

A typical trigger is "more than 50 percent failures over the last 20 calls" (tuned per service).

Bulkhead. Separate resources into isolated pools so a problem in one cannot consume everything, like the watertight compartments in a ship's hull. Examples: a separate thread pool or connection pool per dependency, or separate servers for premium and free customers.

Fallback. A pre-planned alternative when the primary call fails: cached data, a default value or a friendly error. It must be safe; never fall back to "approve the payment anyway".

Graceful degradation. Deliberately reducing functionality to keep the core running. Classify features as critical (login, checkout, playback) or optional (recommendations, reviews) and drop the optional ones first.

Backpressure. Backpressure means a busy component pushes back on its callers (by slowing them down or refusing work) instead of silently accepting more than it can handle. Without it, work piles up in memory or queues, latency climbs, and eventually the service crashes, which is a cascading failure waiting to happen. Two common tools:

  • Queue limits: put a bounded queue in front of the workers. When it is full, new requests are told to wait or are rejected. An unbounded queue only hides overload: requests wait so long that users have given up, yet the server still does the work.
  • Load shedding: when overloaded, deliberately reject some requests, usually the least important, so the rest can succeed. A quick "try again later" (429 or 503) beats timing out for everyone. It is related to the rate limiting you met earlier, but reacts to the server's own overload rather than a per-client quota.

Callers must cooperate: on a 429 or 503 they should back off (as in the previous lesson), not retry immediately.

A simple example

The breaker in your fuse box trips when a faulty appliance overloads a circuit, and separate fuses per room (bulkheads) keep one fault from blacking out the house. A restaurant that stops seating guests when the kitchen is full is backpressure.

System design example

A shop's product page treats inventory and price as critical, and reviews and recommendations as optional. Each dependency gets its own connection pool, and the optional ones sit behind circuit breakers with fallbacks (cached reviews, hidden recommendations). Order workers read from a bounded queue and the API returns 503 when it is full. Alerts fire when a breaker opens, so the hidden failure is still noticed.

Summary

  • Cascading failures spread through dependencies; contain them early.
  • A circuit breaker fails fast: closed, open, half-open.
  • Bulkheads isolate resources; fallbacks give safe alternatives.
  • Degrade optional features first to protect critical ones.
  • Backpressure (bounded queues, load shedding) stops overload from turning into a crash.

Architecture Diagram

Circuit breaker with fallback
Architecture
Users
Page servicebulkhead per dependency
Circuit breakerclosed / open / half-open
Recommendations
Fallback cache

When the breaker is open, callers get a safe fallback instead of waiting.

  1. 1The page service calls recommendations through a breaker.
  2. 2Too many failures open the breaker; calls go to the cached fallback.
  3. 3After a cool-down, trial calls test recovery and may close it.

Common Interview Questions

Finished this lesson?

0 of 91 lessons done · 0% of the course