0PricingLogin
NestJS Enterprise Backend APIs · Lesson

Circuit Breakers for Downstream Failures

Protect services from cascading failure using opossum-style circuit breaker integration.

Why Cascading Failures Happen

In an enterprise NestJS backend, your service rarely lives alone. It calls a payment gateway, an auth provider, a search cluster, other microservices. When one downstream dependency slows down, every request waiting on it holds a connection, a thread, and a chunk of the event loop.

  • A slow dependency exhausts your HTTP connection pool.
  • Pending requests pile up; latency climbs everywhere.
  • Your service becomes unhealthy and its own callers start failing.

This domino effect is a cascading failure. A circuit breaker is the pattern that stops the dominoes from falling.

The Circuit Breaker State Machine

A circuit breaker wraps a risky call and tracks its health through three states:

  • CLOSED — calls flow through normally. Failures are counted.
  • OPEN — too many failures occurred; calls are rejected instantly without touching the dependency. This gives the downstream time to recover.
  • HALF_OPEN — after a cooldown, a few trial calls are allowed. If they succeed, the breaker closes; if they fail, it opens again.

The key insight: when the breaker is OPEN, you fail fast instead of waiting on a timeout for every request.

All lessons in this course

  1. Timeouts, Retries, and Bulkheads with Interceptors
  2. Circuit Breakers for Downstream Failures
  3. Distributed Tracing with OpenTelemetry
  4. Defining SLOs and Error Budgets
← Back to NestJS Enterprise Backend APIs