Building microservices requires attention for many aspects of the architecture. One of these is reliability, and the “Circuit breaker” can help tackling this front in your system: services sometimes collaborate when handling requests and there is always the possibility that the other service is unavailable or is too slow to be usable. Resources might be wasted while waiting for the other service to respond, possibily leading to resource exhaustion and potentially cascading to other services throughout the application.

In a past project I did implement such mechanism in an API gateway built in Node.js (which had to communicate with various services via gRPC) — so I wrote a small wrapper for such calls using Hystrix.js (a library originally written in Java at Netflix).

The repository for the code below is here.