10 Microservices

 

This chapter covers:

  • The basics of microservices
  • The backend for frontend pattern
  • Using asyncio to handle microservice communication
  • Using asyncio to handle failures and retries

Many web applications are structured as monoliths. What do we mean when we say a monolith? A monolith generally refers to a medium to large sized application containing multiple modules that is independently deployed and managed as one unit. While there is nothing inherently wrong with this model (monoliths are perfectly fine, and even preferable for a majority of web applications as they are generally simpler), it does have its drawbacks.

As an example, if you make a small change to a monolithic application, you need to deploy the entire application, even parts that may be unaffected by your change. For instance, a monolithic e-commerce application may have order management and product listing endpoints in one application, meaning a tweak to a product endpoint would require a redeploy of order management code. A microservice architecture can help with such pain points. We could create separate services for orders and products, then a change in one service wouldn’t affect the other.

10.1  Why microservices?

10.1.1    How can asyncio help?

10.2  Introducing the backend for frontend pattern

10.3  Implementing the product listing api

10.3.1    Implementing the base services

10.3.2    Implementing the backend for frontend

10.3.3    Retrying failed requests

10.3.4    The circuit breaker pattern

10.4  Summary