Java programmer resume "plus points", how much do you know about microservice architecture technology?

Before opening the article, I will state a few attitudes towards microservices:

  1. There are many architectural patterns, and microservices are not the only option nor a silver bullet. The vast majority of domestic small and medium-sized companies are blindly pursuing the introduction of microservices. It can also be seen that the quality of the infrastructure of the engineers who do this kind of technology selection is insufficient.
  2. "You must be tall enough to use microservices." The microservice infrastructure, especially container technology, automated deployment, and automated testing, is incomplete, and microservices are in vain and will not bring any qualitative improvement.
  3. The key to the microservice architecture is not the specific implementation, but how to reasonably divide the service boundary and whether the organizational structure matches. Blindly uploading microservices regardless of the size and composition of the R&D team is a bad technology selection.
  4. Spring Boot is the upper encapsulation of Spring's family bucket. It is not a brand-new technology, nor is it a technology worthy of becoming its own killer.
  5. The components of Spring Cloud Netflix in Spring Cloud have been verified in the production environment, while others are recommended to be chosen carefully.

 

What is a microservice

Microservices originated from the Micro-Web-Service (Micro-Web-Service) proposed by Dr. Peter Rodgers at the Cloud Computing Expo in 2005. The fundamental idea is similar to the Unix pipeline design concept. In 2014, Martin Fowler and James Lewis jointly proposed the concept of microservices, and defined that the microservice architecture style is a method of developing a single application through a set of small services. Each service runs in its own process and passes Lightweight mechanism for communication (HTTP API). The three key points are small, automated and lightweight .

Compared with SOA, microservices can be regarded as a subset of SOA, a lightweight SOA, with finer-grained services, independent processes, data separation, and more emphasis on agility, continuous delivery, DevOps, and decentralized practices . The common architecture principle :

  • Single responsibility
  • Separation of Concern: Separation of Control and Logic
  • Modularity and divide and conquer

Features :

  • Componentization with services
  • Organize around business capabilities
  • Is a product, not a project
  • Endpoint intelligence and dumb pipes: The control logic is at the end point, and the pipe is just transmission
  • Fully automated deployment
  • Decentralized control of language and data
  • Design for failure
  • Progressive design

Taken together, its advantages and disadvantages are as follows:

Advantages :

 

  • Strong boundaries of modules
  • Independent deployment
  • Diversity of technology selection

Disadvantages :

  • Distributed brings programming complexity and consumption of remote calls
  • Abandon strong consistency and achieve ultimate consistency
  • Operational complexity requires a mature operation and maintenance team or operation and maintenance infrastructure

Why adopt microservices

Whether to choose microservices depends on the complexity of the system you want to design. Microservices are used to control complex systems, but with it comes the introduction of the complexity of microservices. The problems faced by other distributed systems, including automated deployment, monitoring, fault-tolerant processing, and eventual consistency, need to be solved. Even if there are some commonly used solutions, there are still significant costs.

 

 

The relationship between productivity and complexity is shown in the figure. It can be seen that the more complex the system, the greater the benefits brought by microservices. In addition, whether it is a monolithic application or a microservice, the team's skills need to be able to be controlled.

One of Martin Fowler's point of view is: Unless the cost of managing a single application is already too complicated (too large makes it difficult to modify and deploy), don't consider microservices. Most applications should choose a monolithic architecture, and do a good job of modularizing monolithic applications rather than splitting them into services.

Therefore, at the beginning , the system adopts a monolithic architecture and is well modularized. Later, as the system becomes more and more complex and the boundaries between modules/services become clearer, it is a reasonable architecture to restructure into a microservice architecture. path.

Four situations can be considered for microservices :

  1. Many people develop a module/project, and there are a lot of conflicts frequently when submitting code.
  2. The modules are severely coupled and depend on each other. Each change needs to involve multiple teams. There are too many requirements for a single launch and the risk is high.
  3. The main business and the secondary business are coupled, and the horizontal expansion process is complicated.
  4. Fuse downgrade depends on if-else.

The three stages of microservices :

 

  1. Microservice 1.0: Only use registration discovery and develop based on SpringCloud or Dubbo.
  2. Microservice 2.0: uses service governance strategies such as circuit breaker, current limit, and downgrade, and is equipped with complete service tools and platforms.
  3. Microservice 3.0: Service Mesh takes service governance as a general component and is implemented at the platform layer. The application layer only focuses on business logic. The platform layer can automatically schedule and adjust parameters according to business monitoring to achieve AIOps and intelligent scheduling.

Microservice architecture

 

prerequisites

 

  • Rapid environment provision capabilities: rely on cloud computing and container technology to quickly deliver the environment.
  • Basic monitoring capabilities: including basic technical monitoring and business monitoring.
  • Rapid application deployment capability: The deployment pipeline is required to provide rapid deployment capability.
  • Devops culture: It needs to have good continuous delivery capabilities, including full-link tracking, rapid environment provision and deployment, etc. It also needs rapid response capabilities (quick response to problems and failures), and collaborative work of development and operation and maintenance.

In addition, according to Conway's law and inverse Conway's law (technical structure forces organizational structure improvement), organizational structure is also a very critical factor. Corresponding to the microservice architecture, the organizational structure needs to follow the following principles:

  1. A microservice is maintained by a team, and the team members are preferably three.
  2. The tasks and development of a single team are independent and not affected by other factors.
  3. The team is fully functional, full stack, autonomous, flat and self-managed.

infrastructure

The implementation of microservices needs to rely on many underlying infrastructures, including the provision of microservices compilation, integration, packaging, deployment, configuration, etc., using the PaaS platform to solve the full lifecycle management of microservices from development to operation, while providing a heterogeneous environment Management, container resource isolation and intercommunication, service scaling drift, service upgrade and rollback, service fuse and downgrade, service registration and discovery.

  1. The most basic infrastructure
  • Inter-process communication mechanism: Microservices are independent processes, and the communication method between them needs to be determined.
  • Service discovery + service routing: Provide a service registry, service providers and consumers obtain service information through service discovery to call services, and achieve service load balancing.
  • Service fault tolerance: In the microservice architecture, because there are many services, one service is often down, and the entire request link service is affected. Therefore, service fault tolerance is required. When the service call fails, it can handle errors or fail quickly, including circuit breakers. , Fallback, retry, flow control and service isolation, etc.
  • Distributed transaction support: As the business is split into services, sometimes it is inevitable that cross-service transactions, that is, the problem of distributed transactions. The principle is to avoid distributed transactions as much as possible. If it is unavoidable, then you can use the message system or CQRS and Event Sourcing solutions to achieve eventual consistency. If strong consistency is required, there are distributed transaction solutions such as two-phase commit, three-phase commit, and TCC.
  1. Improve external service docking efficiency and internal development efficiency
  • API Gateway: Responsible for access to external systems, and for cross-sectional public level work, including security, logging, permission control, transmission encryption, request forwarding, flow control, etc. The typical gateway function is to expose a domain name xx.com to the outside, and do reverse routing xx.com/user, xx.com/trade according to the first-level directory. Each level of directory, such as user and trade corresponds to a service domain name. In addition, the API gateway can also have a service orchestration function (not recommended).
  • Interface framework: Standardize the data format, parsing package, and self-explanatory document used in communication between services, so that service users can quickly get started.
  1. Improve testing and operation and maintenance efficiency
  • Continuous integration: This part is not specific to microservices. For the previous monolithic applications, this part is generally necessary. Mainly refers to the continuous compilation and construction of the code process and automated testing through automated means to obtain fast and effective quality feedback, thereby ensuring the smooth delivery of the code. Automated testing includes code-level unit testing, integration testing of a single system, and interface testing between systems.
  • Automated deployment: Micro-service architecture, the number of nodes can be hundreds or thousands, and automated deployment can increase deployment speed and deployment frequency, thereby ensuring continuous delivery. Includes functions such as version management, resource management, deployment operations, and rollback operations. The deployment methods for microservices include blue-green deployment, rolling deployment, and canary deployment .
  • Configuration Center: Run-time configuration management can solve the problem of dynamically modifying configurations and taking effect in batches. Including configuration version management, configuration item management, node management, configuration synchronization, etc.
  • Continuous delivery: including continuous integration, automated deployment and other processes. The goal is to iterate in small steps and deliver quickly.
  1. Further improve operation and maintenance efficiency
  • Service monitoring: There are a large number of nodes under the microservice architecture, and the number of machines, networks, processes, interfaces, etc. that need to be monitored is greatly increased. A powerful monitoring system is needed that can provide real-time collection of information for analysis and early warning on real-time analysis. Including monitoring service request times, response time distribution, maximum/minimum response value, error code distribution, etc.
  • Service tracking: Tracking the complete path of a request, including request initiation time, response time, response code, request parameters, return results and other information, also called full link tracking. Normal service monitoring can be done together with service monitoring, macro information is presented by service tracking, and micro information about a single service/node is presented by service monitoring. The current implementation theory of service tracking is basically Google's Dapper paper.
  • Service security: In principle, microservice calls between intranets should be able to access and write to each other. Generally, permission control is not required, but sometimes limited to business requirements, there are security control requirements for interfaces and data. This part can exist in the service registry in a configurable manner, bind to the service, and be controlled by the security policy of the service node as the service provider when requested. The configuration can be stored in the configuration center to facilitate dynamic modification.
  1. In the case of a small number of microservices, the priority of the above infrastructure decreases from top to bottom. Otherwise, relying only on manual operation will result in a very low input-output ratio.

Also need to mention is the Docker container technology. Although this is not necessary for microservices, container technology is lightweight, flexible, application-dependent, and shielding environmental differences . The characteristics of the continuous delivery are crucial to the realization of continuous delivery, even for traditional single applications. Brings a substantial increase in delivery efficiency.

Architecture design pattern

After the introduction of microservices, traditional monolithic applications have become a service. The previous architecture in which an application directly provides an interface for client access is no longer applicable. Under the microservice architecture, the interfaces for different devices are used as the BFF layer (Backend For Frontend), also called the user experience adaptation layer, which is responsible for aggregating and orchestrating the data of the microservices and converting them into the data required by the front end. Calls between services use asynchronous messaging as much as possible when allowed (allowing delay), thus forming a user experience-oriented microservice architecture design pattern . As shown below:

 

Client -> API Gateway -> BFF(Backend For Frontend) -> Downstream Microservices

 

 

  • The backend adopts a microservice architecture, and the microservices can adopt different programming languages ​​and different storage mechanisms.
  • The front desk adopts the BFF mode to adapt to different user experiences (such as desktop browsers, Native App, and tablet responsive Web).
  • BFF, API Orchestration Layer, Edge Service Layer, Device Wrapper Layer are the same concepts.
  • BFF can't be too much, too much will cause code logic duplication and redundancy.
  • The functions undertaken by the gateway, such as Geoip, current limiting, and security authentication, can be placed on the same layer as BFF. Although the complexity of the BFF layer is increased, performance advantages can be obtained.

Service split

The core link of the microservice architecture is mainly the horizontal division of services . Service splitting refers to the decoupling of a complete business system into services. Services require single responsibilities, no coupling relationship between them, and independent development and maintenance .

Service splitting is not accomplished overnight, and the boundaries need to be continuously cleared during the development process. Before completely sorting out the service, try to postpone the split of the service, especially the split of the database.

The split method is as follows:

  • Split based on business logic
  • Based on scalable split
  • Split based on reliability
  • Split based on performance

Among them, for legacy systems that cannot be modified, the strangling mode is adopted: adding new functions outside the legacy system to make microservices, instead of directly modifying the original system, and gradually replacing the old system.

The specifications that need to be followed during the splitting process are as follows:

  • First less then more, first coarse then fine (granularity)
  • The service can be split up to three layers vertically, and called twice: Controller, composite service, basic service
  • Only one-way call, cyclic call is prohibited
  • Serial calls are changed to parallel calls or asynchronous
  • Interface should be idempotent
  • Interface data definition is strictly prohibited to be embedded and transparently transmitted
  • Standardized project name
  • Split the service first, and then split the database after the service granularity is determined.

Microservice framework

The above describes the many infrastructures of the microservice architecture. If each infrastructure needs to be developed by itself, it is a very huge development work. There are already many open source microservice frameworks on the market to choose from.

  1. Spring Boot

Spring Boot is used to simplify the initial setup and development process of new Spring applications. Although it is not a microservice framework, its original intention is essentially the underlying framework of microapplications, so it is very suitable for the development of microservice infrastructure and microservice application development. Especially for the Spring technology stack team, it is a natural choice to develop microservice frameworks and applications based on Spring Boot.

  1. Dubbo&&Motan

Dubbo Ali's open source service governance framework. It appeared before the rise of the concept of microservices and can be regarded as a masterpiece of the SOA framework. But it only includes part of the functions of the microservice infrastructure, such as circuit breakers, service tracking, gateways, etc. are not implemented.

Motan is an open source RPC framework similar to Dubbo on Weibo, which is more lightweight than Dubbo.

  • Service discovery: service publishing, subscription, notification
  • High availability strategy: failed retry (Failover), fast failure (Failfast), resource isolation-load balancing: least active connection, consistent hash, random request, polling, etc.
  • Extensibility: support SPI extension (service provider interface)
  • Others: call statistics, access logs, etc.

 

  1. Spring Cloud

Spring Cloud is a microservice framework based on Spring Boot, and can also be seen as a set of microservice implementation specifications. It basically covers all aspects of microservice infrastructure, including configuration management, service discovery, circuit breakers, intelligent routing, micro-agents, control buses, global locks, decision-making campaigns, distributed sessions, and cluster state management. It is based on the Spring ecology and the community support is very good. However, many of its components have not been verified in the production environment and need to be carefully selected.

 

Spring Cloud Netflix is ​​a sub-project of Spring Cloud and is Spring's integrated implementation of Netflix OSS. Based on the large-scale use of Netflix, the components that have been widely used include:

 

In addition, another sub-project, Spring Cloud Alibaba, is Alibaba's open source Spring Boot-based microservice framework, which mainly supports Alibaba Cloud services.

  • Eureka: Service registration and service discovery
  • Ribbon: Flexible and intelligent inter-process and service communication mechanism, client load balancing
  • Hystrix: Fuse, provides delay and fault tolerance isolation during operation
  • Zuul: Service Gateway

 

  1. Service Mesh

 

The aforementioned microservice frameworks are all intrusive, and the process of servicing requires code transformation. Service Mesh is the next-generation microservice architecture, the most obvious feature is non-intrusive. The sidecar model is used to solve the communication and governance problems between services after the system architecture is micro-serviced. As shown below:

 

 

The current mainstream open source implementations include:

 

Limited to the cost of performance delay caused by Service Mesh and the increase in distribution complexity of sidecars, it brings about large-scale deployment (large number of microservices), heterogeneous complex (multiple types of interaction protocols/development languages) microservice architecture The benefits will be greater.

  • Linkerd and Envoy: Take sidecar as the core, focus on how to do a good proxy, and complete some general control plane functions. Lack of management and control of these sidecars.
  • Istio and Conduit: Currently the most popular Service Mesh implementation solutions focus on more powerful control plane (sidecar is called data plane) functions. The former is a collaboration between Google and IBM, and uses Envoy as the implementation of the sidecar part; the latter is the work of the author of Linkerd. In comparison, Istio has a giant background and is powerful, but its usability and ease of use have not been high, while Conduit is relatively simple and features focused.

 

  1. Sofastack

Ant Financial opens a set of middleware to build a financial-level distributed architecture. Including a set of distributed application development tools such as microservice development framework, RPC framework, service registry, full link tracking, service monitoring, and Service Mesh.

 

Especially worth mentioning is SOFAMesh. In fact, the practice of large-scale implementation of the next-generation microservice architecture Service Mesh, based on the improvement and expansion of Istio, should be the most mature open source Service Mesh solution in China.

 

In addition, we need to mention Kubernetes (K8s) , which itself provides part of the microservice feature support (service discovery through the domain name), without intrusion into the code. But service calls and circuit breakers need to be implemented by themselves.

In summary, the current technology stack of the company's technical team is Spring, and the implementation of existing services is based on Dubbo, so Spring Cloud Netflix is ​​selected as the basic microservice framework. For the immature or lacking components, the industry is more mature. The components can be replaced.

  • API Gateway: Zuul
  • Service Registry: Dubbo
  • Configuration Center: disconf
  • Service monitoring && full link tracking: CAT
  • Service development framework: Spring Boot
  • Log monitoring and warning: ELK + Elasalert
  • Flow control: Sentinel
  • Message queue: Kafka

Guess you like

Origin blog.csdn.net/baidu_39322753/article/details/104494583