Circuit Breaker is a Javascript design pattern used to handle faults and failures in distributed systems. It is particulary helpful in scenario when external resources might be unavilable and we want to prevent reaching out to them continously and save resources.
You can learn more about the circuit breaker pattern on Wikipedia.
We’ll recreate a very small utility function called createCircuitBreaker which takes a function and prevents calling the function if it fails for a threshold count. We can retry reaching the service again after a certain back-off cooling period.
When the service in unreachable, we can return a message saying “service unavailable”.