QA
Intermediate LevelSoftware Engineering Principles

How does the Circuit Breaker pattern prevent cascading failures in microservice architectures?

❓ Interview Prompt: Explain Circuit Breaker states (Closed, Open, Half-Open), failure thresholds, fallback execution, and Resilience4j / Hystrix implementation.

The Circuit Breaker Pattern prevents a failing downstream service from causing cascading failure across an entire microservice ecosystem:

3 Circuit States:

1
🟢 Closed: Normal operation. Requests pass through to downstream service.
2
🔴 Open: Downstream service failure threshold exceeded ($> 50\%$). Circuit breaker trips open immediately, failing fast without calling downstream service, returning a fallback response!
3
🟡 Half-Open: After a cooldown period, breaker allows a trial request through to check if downstream service has recovered.

Code Implementation Example

typescript
import { CircuitBreaker } from './circuit-breaker';

const breaker = new CircuitBreaker(fetchUserData, {
  failureThreshold: 50,
  cooldownPeriodMs: 10000
});

// Returns cached fallback response if Circuit is OPEN
const user = await breaker.fire(userId).catch(() => getCachedUserFallback(userId));
💡Wrapping microservice network calls with a Circuit Breaker.
🎯 Interview Key Takeaway

Use Circuit Breakers to fail fast and execute fallbacks when downstream services degrade, preventing cascading microservice failures.

#Circuit Breaker#Resilience#Microservices#Intermediate
Back to all Software Engineering Principles Questions→

More Software Engineering Principles Interview Questions

Beginner LevelSoftware Engineering Principles

Explain the 5 SOLID Principles of Object-Oriented Software Design with practical refactoring examples.

Beginner LevelSoftware Engineering Principles

What are DRY (Don't Repeat Yourself), KISS (Keep It Simple, Stupid), and YAGNI (You Aren't Gonna Need It)?

Beginner LevelSoftware Engineering Principles

Why is Composition Over Inheritance a fundamental object-oriented design principle?