To implement the microservice architecture pattern, we build a collection of APIs with specific responsibilities that work together and communicate through events. Let's see how we can do this.
Before we begin, it's important to know why we are implementing this pattern. To learn more about microservice architecture and its benefits, you can read the articles by Chris Richardson. There is also an article about microservices in the Microsoft documentation.
To show and learn together how we can implement the microservice architecture, I will work on a solution focused on the food retail business. This solution is an open source project called Storefront Community.
The business goal is to reduce the waiting time and offer convenience to the customers of the restaurants. As solution we will deliver a self-order kiosk (a.k.a. self-service terminal) where customers can order meals on their own. Techcnically, to build the backend of this solution by adopting the microservice architecture, I will essentially follow these three steps:
But to ensure the development of the project in a sustainable way, the following processes are very important and should be considered:
Once we decided to implement the microservice architecture pattern, we'll need an API gateway that will act as a single entry point responsible for routing all requests to the other services (other APIs).
To accomplish this task you can refer to a post I wrote about implementing an API gateway with ASP.NET Core and Ocelot. You can also find information about this topic in the Microsoft doumentation.
The services are intended to play a specific part of the business and encapsulate their implementation logic and persistence strategy. However, they need to communicate with each other in order to work together to meet business needs.
The communication between services will take place through events and, to be established, three agents are needed:
I will publish a post about how we can implement an event bus with RabbitMQ and ASP.NET Core. I also suggest you read the Microsoft's article implementing event-based communication between microservices (integration events) and articles related to RabbitMQ.
We'll plan our services to have single-responsibility, that way the teams can focus on developing, maintaining and deploying each independently.
Understanding and defining single responsibility for each service is a delicate task and we must do this in a planned way. Keep in mind that we will refactor and continually improve our strategy based on business requirements.
This project aims to meet a need of the food retail business. Technically, I will build a backend for a self-order kiosk and also a menu board. These two apps gives us a good ideia of what we intend to achieve.
In the next posts I'll write about the planned microservice architecture and how it will be built.