Circuit Breaker with Microservices

Suppose that you have implemented the microservices architecture. The microservices interact with each other when requests occur. When a synchronous microservice invokes another, there is always the possibility that the other is unavailable or is suffering from very high latency making it unusable. The failure of one microservice can potentially cascade to another through the entire mesh. Then resilience is that we need.

Cascading failures at microservices mesh

What is Resilience?

Resilience in microservices is the ability of recover from failures and return to the fully functional state. It’s not about avoiding failures but responding to failures in a way that avoids downtime and data loss.
There are much reliability patterns that helps us with this and today i will talk about the Circuit Breaker Pattern.

What does the Circuit Breaker Pattern?

It works similarly to an electrical circuit breaker. When the number of consecutive faults exceeds a limit, the circuit breaker trips and during a timeout period, all attempts to invoke the service will fail immediately. After the timeout expires, the circuit breaker allows a limited number of test requests to pass. If these requests are successful, the circuit breaker resumes normal operation. Otherwise, if there is a failure, the timeout period will start again.

Circuit Breaker Schema Diagram

Circuit Breaker with .NET and Polly

Polly is a .NET library focused on resilience and treatment of transient failures that allows developers to express policies in a fluent and thread-safe manner, where each policy can be used individually or combined with others to provide customer resilience.
The main Polly features are Circuit Breaker, Retry and Timeout control.

Circuit Breaker with AWS

AWS App Mesh is a service mesh that provides application-level networking to make it easy for your services to communicate with each other across multiple types of compute infrastructure. App Mesh gives end-to-end visibility and high-availability for your applications.
This feature is based on the Envoy Proxy tool, an open source proxy designed for native cloud applications.

References

Circuit Breaker
https://martinfowler.com/bliki/CircuitBreaker.html

Book: Hands-On RESTful Web Services with ASP.NET Core 3
Resca, Samuele. Packt. 2019. ISBN 10: 9781789537611

AWS App Mesh
https://aws.amazon.com/pt/app-mesh/

Envoy Proxy
https://www.envoyproxy.io/

Polly .NET
https://github.com/App-vNext/Polly
http://www.thepollyproject.org/

Implement resilient applications
https://docs.microsoft.com/en-us/dotnet/architecture/microservices/implement-resilient-applications/

Circuit Breaker Pattern
https://microservices.io/patterns/reliability/circuit-breaker.html

.NET Microservices: Architecture for Containerized .NET Applications
https://docs.microsoft.com/pt-br/dotnet/architecture/microservices/

Implement the Circuit Breaker pattern
https://docs.microsoft.com/pt-br/dotnet/architecture/microservices/implement-resilient-applications/implement-circuit-breaker-pattern

Implementando o Circuit Breaker Pattern
https://rafaelcruz.azurewebsites.net/2018/05/22/implementando-o-circuit-breaker-pattern-parte-1/

Conheça meu projeto!

https://4devs.net.br

Hi, I’m a software engineer and want to share curiosities about the world of programming with you. Fell free to interact and share my stories!!!