Senior LevelNode JS
How do you implement enterprise Circuit Breaker patterns (opossum) in Node.js to survive downstream microservice outages?
❓ Interview Prompt: Explain Circuit Breaker pattern, states (CLOSED, OPEN, HALF-OPEN), failure thresholds, and fast-failing cascading microservice outages.
When downstream microservices slow down or crash, continuing to send requests exhausts Node.js socket pools and cascades failures system-wide!
Circuit Breaker States (Opossum library):
1
CLOSED: Normal operation.
2
OPEN: Tripped when failure rate exceeds threshold (e.g. 50%). Fails fast immediately or returns fallback cache!
3
HALF-OPEN: Periodically tests downstream service recovery.
Code Implementation Example
javascript
import CircuitBreaker from 'opossum';
async function callUnstableService() {
return fetch('https://unstable-api.internal/data');
}
const breaker = new CircuitBreaker(callUnstableService, {
timeout: 3000,
errorThresholdPercentage: 50,
resetTimeout: 10000
});
breaker.fallback(() => ({ status: 'FALLBACK_DATA' }));💡Implementing Circuit Breaker fault tolerance with Opossum.
🎯 Interview Key Takeaway
Use Circuit Breakers (Opossum) to isolate microservice failures and prevent cascading outages.
#Circuit Breaker#Opossum#Fault Tolerance#Microservices#Senior
Back to all Node JS Questions→