Microservices are gaining popularity among developers, they are good for large Internet services serving a large number of users. If there is a failure in one service, the others will continue their work: this is very important for large and complex systems. In case of innovations, you can simply write a new service, it will easily fit into the whole system, you won’t have to deal with compatibility problems. Moreover, you can include several independent teams using different programming languages in the work: microservices allow you to do this.
The microservice approach has both advantages and disadvantages. In this article we will consider in detail the essence of microservice architecture, its differences from monolithic architecture, advantages and disadvantages, as well as peculiarities of operation of applications built on the principle of microservices.
What is microservice architecture
Microservice architecture is a style of software development that consists in dividing the monolith of a system into separate components that represent independent services. Each individual service is designed to perform relatively simple functions, the work of the application is tested in real time with the tracking of technical elements and business characteristics. The services have clear physical boundaries, which makes them scalable and makes it possible to use different programming languages. Required changes are made without affecting the entire application.
Microservice architecture and monolith
Monolithic systems combine all the services of an application into a single process, and then duplicate that system across multiple servers. Microservice architecture has a separate package for each service, and they are stored on different servers as well – isolated from each other, duplicating if necessary. This allows you to work with each functional element separately.
Benefits of microservice architecture
The benefits of microservices have been strong enough for major corporate players like Amazon, Netflix or eBay to implement them in their systems.
- High fault tolerance: if one of the services goes down, all the others remain up and running. Thus, failures in individual services will not interfere with the entire workflow;
- Flexibility: you can try to implement a new technology with little blood. It will be much faster and, in case of failure, to roll back changes simply. By changing one of the services locally, we do not risk the entire system and the time required for changes is less;
- Simplicity: the less code (and each individual service is a complete system, so you do not need to understand a huge number of details that do not relate to this particular function), the easier it is for programmers to understand what and how it works. In addition, it will take less time;
- Ease of putting the written code to work: a small amount of code provides a fast deploy;
- Scalability: the most necessary and necessary services can be added and expanded when the need arises. The whole system remains the same.
Compared to the monolithic, microservice architecture has greater flexibility and the ability to independently scale individual services. It is easier to make local changes to the code without risking the whole system, but instead the complexity of interaction between services increases.
Disadvantages of microservice architecture
Despite the trendiness and a large number of advantages of microservice architecture, it has some disadvantages as well.
- Communication between the services themselves is complex. Since each functional element is isolated, special care is required when building competent communication between them, because they will have to exchange requests and responses with each other in any case. It is clear that as the number of services increases, the complexity in building their message will increase.
- The growth of the number of services also entails the growth of the number of databases with which these services relate, because, unlike monolithic architecture, microservices use more than one common database.
- The complexity of testing is expressed in the fact that first you need to deal with each service separately, and then test the correct interaction of it with other microservices.
- Microservices are worse suited for use within individual organizations, for them they may be unreasonably difficult to use, while for mass Internet services they are perfect.
Microservice Architecture Application Exploitation
- Monitoring
Over time, small problems can lead to major ones. Therefore, timely, and in the case of microservices, continuous, monitoring is essential. Monitoring a microservice architecture is much more complex to set up and more expensive to maintain than monitoring a monolithic application. - Realization of fault tolerance
Both monolithic and microservice architectures cannot avoid application failures. An important principle in building an application on microservices is to assume that system failures will happen sooner or later. And with this initial assumption, the application is created.
The code must be thoroughly tested before it is released to production. Nevertheless, there is always a chance that some error will be missed. It is for such cases that the chaos testing system is invented. Errors and problems are created automatically and intentionally – to study them in advance and come up with a quick solution or a way to prevent them. - Scaling
The cloud-based nature of microservices and the virtualization that underlies them have scalability as their main advantage. Each service performs a specific function, all services are relatively small – all these characteristics of the architecture are what make scaling easier and more painless.
When it is appropriate to use microservice architecture
Microservice architecture is especially relevant for companies that provide online services to a large number of users at the same time. Such services include large online stores, streaming platforms, and social networks.
The possibility of independent scaling of different system components is important for them. For example, on sale days the load on the order placement service increases greatly, while other services work in normal mode. Microservices allow you to flexibly increase computing power and bandwidth specifically for the checkout service without affecting other subsystems.
Fault tolerance is also critical for online services with a large audience – if a service fails, the rest of the application must continue to operate normally. Separation into independent microservices provides just such isolation of failures.
In addition, microservices are convenient for large distributed development teams – each team can deal with its own service, which simplifies coordination and speeds up the release process.
At the same time, microservices can be a redundant solution for small projects or internal systems of companies. In such cases, it is preferable to use monolithic architecture due to its greater simplicity and cheapness in development and support.
Microservice architecture use cases
Amazon
One of the first companies to adopt microservices. Amazon’s entire infrastructure is built from hundreds of independent services – for product catalog, user accounts, search, recommendations, and so on. This allows Amazon to easily scale resources to meet increasing workloads and quickly roll out new products through microservice development.
Netflix
Netflix’s streaming service is broken down into more than 800 microservices. They are responsible for video transcoding, recommendations, A/B testing of interfaces and other tasks. The flexibility of the microservices allows Netflix to quickly expand its server fleet when traffic surges and experiment with UI/UX without jeopardizing the system.
Uber
The company uses hundreds of microservices – for geolocation, mapping, payment processing, logistics, and more. This ensures system reliability and resilience under huge loads, and allows Uber to scale quickly and enter new markets.
Conclusions
Microservices are worse suited to be used as an architecture for developing enterprise information systems. In such a variant we will get an excessively complex system from the point of view of operation and maintenance. And the increase in operating costs will not pay for the advantages of using microservice architecture, because they will not be fully manifested within one, even a large organization.
The main area of effective application of microservices is large Internet services operating in real time for a large number of users.