Series of articles
Micro service | Spring Cloud (a) : from monomer SSM to Spring Cloud
preface
In the case of micro-service in full swing, more and more projects began to try to transform into micro-service architecture, micro-service not only brings the convenience of project development, but also improves the difficulty of operation and maintenance and the probability of unreliable network.
When talking about the advantages and disadvantages of microservices, be sure to compare the single-unit organization, the comparison will be more obvious.
Let’s start with a monotype structure
Unitary architecture
In the singleton architecture, the system usually adopts the layered Architecture pattern (MVC), the persistence layer, the presentation layer, and the business logic layer. The architecture has the following problems:
- System internal access, tight coupling leads to difficult maintenance;
- It is difficult to quickly apply new technologies (for example, it is difficult to transform SSM using SSH) because different service areas need to use the same technology stack.
- Any changes to the system must be redeployed/upgraded as a whole;
- When the system load increases, it is difficult to scale horizontally.
- When a problem occurs in one part of the system, it affects the whole system.
When I participated in my first job, all the functions were written in the same project because the project was small and the users were small, and only one instance was deployed. Simplified the concurrency problems encountered in the development, but also perfectly hit some of the above problems, every time the function online needs to restart the project.
In common scheme, we can take apart the service, by configuring domain for communication between two service, this also reduces the size of a single project, the configuration of the domain name this way to hard every increase a service instance need to manually configure Nginx configuration, each adding a project, the need for further domain configuration, configuration is tedious and error-prone
In order to overcome the above shortcomings, the microservice architecture came into being. Microservices, also known as microservices architecture. Microservices are small, autonomous services that work together.
Microservices Architecture
advantages
1. Technical heterogeneity
In different services, different technologies can be used for individual development, as long as the services can cooperate with each other
2. The elastic
When one of the microservices is unavailable, the entire system will not be affected, but related functions will be unavailable
3. The extension
Easy to extend, with small multiple services, it is easier to extend new functionality
4. Simplify deployment
An updated deployment of a service does not require a redeployment of the entire application
5. Can be combined
By combining multiple services, you can provide some new functionality
6. Alternative
Because each microservice is small, it is feasible to re-implement a service or simply remove it
disadvantages
1. High complexity
Microservices interact with each other in the form of REST and RPC. Compared with the single mode, it is necessary to consider various exceptions such as the failure of the called party, overload, and message loss, and the code logic is more complex.
For transactional operations between microservices, because different microservices use different databases, the transaction mechanism of the database itself cannot be used to ensure consistency, so two-phase commit and other technologies need to be introduced.
At the same time, when there are a few shared functions among microservices but they cannot be extracted into microservices, each microservice usually needs repeated development for these functions, or at least code replication, to avoid the coupling between microservices and increase the development cost.
2. Complex operation and maintenance
When the microservice architecture is adopted, the system is composed of multiple independent microservices, and a well-designed monitoring system is needed to monitor the running status of each microservice. Operation and maintenance personnel need to have a detailed understanding of the system to be able to better operation and maintenance system.
3. Performance is affected
Compared with the single architecture, microservices interact with each other through REST and RPC, which greatly affects the communication delay.
Service discovery and elastic scaling
As mentioned earlier in the singleton architecture, when we want to extend a project, we can continue to add feature code on a single project, or we can create a new project based on the feature, assign a domain name to the project, and then call it back and forth through the domain name
To be continued
reference
- Microservice Design (Sam Newman)