Experimenting with circuit breaker pattern.
Because I was interested in implementing distractless and quick fallback with the following desired capabilities :
- When one service is not available go the provided alternative.
- If there is failure by тхе first or second service I do not want to retry it explicitly - it should be retried internally by the CS.
- If the problem is not resolved by retrying - null should be returned instead of exception. Then the caller is in charge. Just fail silently.
- When an exception does occur it must be logged by the CS through logging service. Not exception should be thrown over the hedge.
- I do not want my code to be littered with try/catches. The code becomes unreadable when I use try/catches 2-4 times in a single method. That is why I prefer to return null - I know already that this situation can not be handled by retries or alternative code paths.
- I want it to be testable and not an obstacle to the testability of consuming classes.
- I want it to be thread safe because I plan to use it in classes/service which have singleton lifetime.
- I want to stack multiple services as alternative paths.
- I want it to be async.
- Get the stock quotes from Yahoo if it fails - retry X times with Y seconds configurable back-off
- otherwise from Google with retry and back-off
- otherwise from cache (Redis?, Apache.Ignite?) with retry and back-off ,
- otherwise return null.
it became not a true circuit breaker so I decided to call it a Circuit Switch. If you find it interesting I will be glad to discuss it.
I found some useful articles and blog posts along the way.