The definition and pros and cons of microservices

The definition and pros and cons of microservices

1. What is a microservice

There are many problems with the monolithic architecture, and the emergence of microservices is to solve the difficulties faced by the monolithic architecture. For now, there is no strict definition of microservices. Martin Fowler defines microservices in this way.

In short, the microservice architectural style [1] is an approach to developing a single application as a suite of small services, each running in its own process and communicating with lightweight mechanisms, often an HTTP resource API. These services are built around business capabilities and independently deployable by fully automated deployment machinery. There is a bare minimum of centralized management of these services, which may be written in different programming languages and use different data storage technologies.

Original address: https://martinfowler.com/articles/microservices.html

Translation: The microservice architecture style is a method of developing a single application into a set of small services, each service runs in its own process, and the service-to-service communication uses a lightweight communication mechanism (usually HTTP resource APT). These services are built around business capabilities and can be independently deployed through a fully automated deployment mechanism. These services share a minimal centralized management. Services can be developed in different languages ​​and use different data storage technologies.

Second, the characteristics of microservice architecture

  • Each microservice can run independently in its own process.
  • A series of independently operating microservices together build the entire system.
  • Each service is an independent business development, and a microservice only focuses on a specific function, such as order management, user management, etc.
  • Microservices communicate through some lightweight communication mechanisms, such as calling through RESTful APIs.
  • Different languages ​​and data storage technologies can be used.
  • Fully automatic deployment mechanism.

Take the movie ticketing system as an example. The application is structured using microservices. The architecture diagram is as follows:
Insert picture description here
The entire application is decomposed into multiple microservices, and each microservice runs independently in its own process, and has its own database and one of the microservices. Use REST or other protocols to communicate between.

Third, the advantages of microservice architecture

  • Easy to develop and maintain: A microservice will only focus on a specific business function, so its business is clear and the amount of code is small. It is relatively simple to develop and maintain a single microservice. The entire application is built by several microservices, so the entire application will remain in a controllable state.
  • A single microservice starts faster: a single microservice has a small amount of code, so the startup will be faster.
  • Partial modification is easy to deploy: As long as a single application is modified, the entire application has to be redeployed. Microservices solve this problem. Generally speaking, to modify a microservice, you only need to redeploy the service.
  • Unrestricted technology stack: In the microservice architecture, the technology stack can be selected reasonably according to the characteristics of the project business and team. For example, some services can use the relational database MySQL; some services have graph computing requirements, and Neo4j can be used; even as needed, microservices can be deployed using java development, and some microservices can be developed using Node.js.
  • Scale on demand: Fine-grained expansion can be achieved according to demand. For example, if a certain microservice in the system encounters a bottleneck, you can combine the business characteristics of this microservice to pull out the memory, upgrade the CPU, or add nodes.

Taken together, the shortcomings of the monolithic application architecture are precisely the advantages of microservices, and these advantages make microservices look perfect. However, there is no perfect thing. Let's take a look at the challenges faced by microservices.

Fourth, what are the challenges of microservice architecture

  • Higher operation and maintenance requirements: more services mean more investment in operation and maintenance. In the monolithic architecture, only the normal operation of an application needs to be guaranteed. In microservices, it is necessary to ensure the normal operation and collaboration of dozens or even hundreds of services, which brings great challenges to operation and maintenance.
  • The inherent complexity of distributed: the use of microservices to build a distributed system. For a distributed system, system fault tolerance, network delay, distributed transactions, etc. will bring huge challenges.
  • Interface adjustment costs are high: microservices communicate through interfaces. If you modify the API of a certain microservice, all microservices that use the interface may need to be adjusted.
  • Duplicated work: Many services may use the same function, but this function has not reached the level of decomposition into a microservice. At this time, each service may develop this function, which leads to code duplication. Although you can use shared libraries to solve this problem (for example, you can encapsulate this function into a common component, and the microservices that need this function can reference the component), the shared library may not work in a multilingual environment.

Guess you like

Origin blog.csdn.net/qq_42647711/article/details/109217672