7 Service implementation patterns for microservices
This chapter covers
- How hexagonal architecture helps us design loosely coupled services
- Implementing the business layer for a microservice
- Implementing database models using SQLAlchemy
- How the Repository pattern helps us decouple the data layer from the business layer
- How the Unit of Work pattern helps us ensure the atomicity of all transactions
- How the dependency inversion principle helps us build software which is resilient to changes
- How the inversion of control principle and the dependency injection pattern help us decouple components which are dependent on each other
In this chapter, we’ll learn how to implement the business layer of a microservice. In previous chapters, we learned how to design and implement REST APIs. In those implementations, we used an in-memory representation of the resources managed by the service. We took that approach to keep the implementation simple and allow ourselves to focus on the API layer of the service.
In this chapter, we’ll complete our implementation of the orders service by adding a business layer and a data layer. The business layer will implement the capabilities of the orders service, such as taking orders, processing their payments, or scheduling them for production. For some of these tasks, the orders service requires the collaboration of other services, and we’ll learn useful patterns to handle those integrations.