Concept
Cascading Failures & Timeout Management
In a microservices architecture, a single slow service can block thread pools in upstream gateways. If the BFF calls a downstream service that is hanging due to database load, and holds the connection open, the BFF's Node.js event loop eventually runs out of sockets, causing a cascading failure that crashes the entire application.
To prevent this:
- Set strict connection timeouts: Stop waiting for slow responses after a set threshold (e.g. 1.5 seconds) and return a fallback or error.
- Implement Fallback States: Return cached or placeholder data rather than throwing an exception.
The Circuit Breaker Pattern
The Circuit Breaker pattern acts as an automated electrical switch that protects services from failing repeatedly: