Building Resilient Microservice Using Circuit Breaker Pattern
Anand Moorthy J (~anand_moorthy) |
Given the scale of data that is dealt with in today’s world, everyone is moving away from monolithic architecture and adopting microservices architecture. A microservices architecture consists of a collection of small, autonomous services. Each service is self-contained and should implement a single business capability.
Advantages of microservices architecture are :
- Independent and faster deployments
- Independent developments in small and focused teams
- Option to adopt mixed technology stacks
Challenges of microservices architecture are :
- Inter service communication
- Isolating failures
- Network congestion and latency
In this workshop, we will be learning how to handle the challenges in a microservices architecture and how to use resiliency strategies to prevent failures within a service from cascading to cause a catastrophic failure. If this occurs, then it will escalate throughout our system and the whole infrastructure will come down.
Circuit Breaker Pattern can prevent an application from repeatedly trying to execute an operation that's likely to fail. Allowing it to continue without waiting for the fault to be fixed or wasting CPU cycles while it determines that the fault is long lasting. The Circuit Breaker pattern also enables an application to detect whether the fault has been resolved. If the problem appears to have been fixed, the application can try to invoke the operation.
- Introduction to microservices architecture
- Types of patterns which improve availability and resilience of the components
- Implementation of Circuit Breaker Pattern(CBP) to perform graceful degradation in the microservice
Topics will be covered in this workshop:
- Why microservices architecture?
- How communication within microservices works?
- Write a simple microservice to perform a task
- Request Timeout pros & cons
- Request Retries pros & cons
- How CBP works?
- Different states of CBP
- How to prevent service failures from cascading to other services?
What are we going to build:
A Microservice to get the latest trends based on the region. In this application we use redis as in-memory caching system to deliver the content faster. Once the application is written and configured in local we take down the Twitter API internally to implement the Circuit Breaker Pattern to avoid the failure by delivering the content from the redis in the downtime and application it self deliver the latest content from Twitter once the API up.
Understanding of REST and working knowledge of python request library
Laptop with python 3.5+, flask 1+, pybreaker, tweepy, redis installed
Naveen P G, Platform Engineer at Mad Street Den
Anand Moorthy J, Full Stack Developer at Mad Street Den
Adithya N J, Full Stack Developer at Mad Street Den