The Path to Microservices: What are Microservices?
Microservices architecture is a popular architectural style in the backend world. Developers love to use this architectural style to develop a large-scale system and solve complex problems. But, do you know why it is so popular? In this post, I am going to discuss Microservices and guide you to understand some high-level ideas about Microservices.
Why Microservices?
People always talk about microservices but why do we use microservices?
Microservices bring multiple benefits to your product/team as follows:
Better scalability
Split a large codebase
Deploy application fast and independently with CI/CD
High availability
Language/Technology diversity
Data security through the secure web API
…
What are Microservices?
In software development, microservices are an architectural style to develop a backend application. Since it brings different benefits to the team/product, developers always use it to create a Loosely Coupling architecture and scale the application fast and simply.
Here is a high-level idea to visualize what is happening inside a microservice architecture. It does not mean you can only use these technologies.
Look at the diagram above, we decouple the connection between Order and Statistic because the order service does not care how other services handle the business logic after the order is created. Here we use a Publish-subscribe pattern to decouple the dependency, whenever an order is created, the statistic service will consume the message to do some statistic work. It can make your API response faster because the statistic service’s execution time shouldn’t count into order creation. Now, if the statistic service gets any error, it will not affect the order creation flow.
Also, multiple replicas for each service can offer high availability to your services. If one goes down, still have other replicas available to serve your users. We can scale out or scale down depending on traffic or we can have multiple nodes (machines) to deploy the services.
Now, look at the database, each service contains a database. It secures data access because the data related to that service can only be accessed through the API. The data is isolated by different service domains. Order service cannot access the payment database directly. It needs to go through the wallet service API. We can also scale the database by creating a cluster or data sharding but it depends on your scenario. In this post, we will not dive into this topic.
Since each service is independent, we can adopt different programming languages or technologies for different services. The microservices can communicate through API or Pub/Sub. It offers you language diversity and you can choose the right language to solve the right problem.
To sum up, microservices bring you multiple benefits to solve the pain points from monolith architecture but microservices also bring some disadvantages to you like architecture complexity, data consistency, cost, etc., so consider your scenario to choose the best technology.