Build Resilient Microservices Using Spring Retry and Circuit Breaker Pattern
“Everything fails all the time” — Werner Vogels
This is sad but true, everything fails specially in Microservice architecture with many external dependencies. Modern applications have tens of microservices which communicate with each other over REST. Anytime any microservice may go down causing entire operation to fail. At a broad level we can classify these failures in two categories
Transient — where application will heal itself in a matter of seconds such as network glitch.
Non-Transient — where application suffer for a longer period, minutes or hours such as database connection, unavailability due to high traffic or throttling limit.
To improve the resilience of our microservice architecture we should consider following two patterns.
- Retry
- Circuit Breaker
For transient failures, we don’t want to fail the request immediately rather would prefer to retry few times. There may a temporary network glitch and next attempt may be successful. While implementing Retry Pattern you should be careful how many retries you want. May be you can limit to 3 retries for each REST call as an example. But if the failure is not transient and you keep on doing 3 retries for each…