Soft Examination Senior System Architecture Designer (9) Composition Template - Microservice Architecture (to be improved)

Table of contents

Drawing inferences from one instance - on microservice architecture and its application

ps: more microservice information

ps: The difference between microservices and SOA

Example of microservice architecture

Landing Technology of Microservices

Microservice technologies can be roughly divided into five categories


Drawing inferences from one instance - on microservice architecture and its application

On Microservice Architecture and Its Application
Microservice advocates dividing a single application program into a group of small services, and the services coordinate and cooperate with each other to provide users with ultimate value. Each service runs in its own independent process, and services communicate with each other using a lightweight communication mechanism. In the microservice architecture, each service is a relatively independent individual, and each service can choose its own technology to implement. The deployment of each service is independent, so that specific parts of the code can be deployed faster.
Please focus on the topic of "On Microservice Architecture and Its Application", and discuss it from the following three aspects in turn.
1. Briefly describe the software projects you have participated in the management or development of, and the main work you have undertaken in them.
2. Briefly describe the advantages of microservices.
3. Explain in detail how to design and implement software based on the microservice architecture.
 

Question 1: Same as above. available for public use

Question 2: 

 Advantages overview:

Flexible technology selection

In the microservice architecture, each service is a relatively independent individual, and each service can choose its own technology to realize;

Because for a single system, adopting a new language, database or framework will have a huge impact on the entire system, which makes us discouraged when trying new technologies.

Microservices are different. We can only adopt new technologies in one microservice, and then promote them to other services after they mature.

Easy to fault tolerance, the system is more stable

A problem in one part of the monolithic system may lead to problems in the entire system;

In the microservice architecture, each service can have built-in availability solutions and functional degradation solutions, so it is more powerful than a monolithic system

Easier to extend/modify/refactor

In a single-block system, if we want to expand the system, we must expand it as a whole;

In an architecture using microservices, it is possible to scale for a single service.

In a microservice architecture, we can easily rewrite services when needed, or delete services that are no longer used

Deployable independently

For a large single-block system, even if a line of code is modified, it must be re-deployed as a whole. Big impact, high risk.

In microservices, each service is deployed independently, and automated deployment can also be achieved, so that specific parts of the code can be deployed faster.

When a microservice changes, there is no need to compile and deploy the entire application.

Controllable complexity

        For traditional monolithic systems, the larger the system and the larger the code base, the more difficult it is to manage, and there will be a series of management problems.

        Each microservice focuses on a single function and clearly expresses the service boundary through a well-defined interface. Due to its small size and low complexity, each microservice can be fully controlled by a small-scale development team (avoiding an excessively large code base), which is easy to maintain high maintainability and improves development efficiency. 

ps: more microservice information

Disadvantages of microservices:

1. Developers must deal with the complexities of creating distributed systems

2. Complexity of deployment

Operating a system composed of many different service types is complex to deploy and manage

3. Increase memory consumption

The microservices architecture replaces a single application instance with multiple service instances. If each service runs in its own JVM, then as many service instances as there are, there will be memory overhead at runtime for how many instances

ps: The difference between microservices and SOA

 common ground:

Both are splits of the single architecture

the difference:

Example of microservice architecture

The business service system performs its own duties , and each system is only responsible for the responsibilities within its own business scope. For example, the commodity system only serves commodity-related services, such as creation, update, query, loading and unloading, and the entire life cycle and is relied on by the shopping cart system. The logical relationship between service systems is clear, and different systems can only be accessed through the interface provided by the other party, which is convenient for management. Each system has its own independent deployment server and its own storage database. Faults can be isolated. Cooperate with logs, messages, The monitoring and configuration center equally divides and deploys the cooperating components under the microservice to achieve a service system that can be monitored, isolated, and communicated

 ps: The core business service layer is also the implementation of microservices.

Landing Technology of Microservices

Reference: Overview of Microservice Technology_Fall_Flower's Blog-CSDN Blog

Microservice technology stack:

  • Service cluster. When splitting microservices, a single project will be split into functionally independent projects according to the business function modules. Each project will complete a part of the business functions and will be independently developed and deployed in the future. We call each independent project a service , a large-scale Internet project often contains hundreds or thousands of services, and finally forms a service cluster
  • Registration center and configuration center. When a request comes, service a may call service c, and service c will call service e. When the business becomes more and more complicated, the call relationship between services will be chaotic, and it is necessary to rely on people to record and maintain It is impossible, and the registration center will be led out at this time . 

The registration center can record the ip, port, and what it can do of each microservice, so that when a service needs to call another service, it does not need to record the other party's ip and port information, just go to the registration center to pull it .

The configuration center can manage the configuration of all services in the service cluster in a unified manner. If you need to update the configuration of a certain service, you only need to modify the corresponding configuration in the configuration center, and it will notify the relevant services to modify the configuration to achieve hot update of the configuration .

  • service gateway. After the service is running, when the user comes to visit, which microservice should be accessed? At this time, a gateway component is needed, and the gateway component can also prevent the microservice from being exposed to the outside world. Some load balancing will also be done during access.

  • Distributed cache and distributed search. The database will definitely not be able to withstand high concurrency in the future, so we will also add distributed caching.

  • message queue. A message queue component for asynchronous communication is also required in microservices . When a request comes, suppose service a is called and it takes 10ms, but service a calls service c and it takes another 10ms, and service a can no longer process new requests when it calls c, which reduces the overall service efficiency.

  • Distributed logging and system monitoring link tracing. In such a huge cluster, if a problem occurs somewhere, it is difficult to locate, so at this time, a distributed log is introduced. The distributed log can store, count, and analyze all service logs in a unified way, and it will be easier to locate problems in the future. up.

  • Continuous integration.

    Such a huge microservice cluster may have tens of thousands of services, and deployment has become a problem. It is definitely not realistic to rely on manual deployment, so automated deployment will be performed in the future. You can use the Jenkins tool to automatically compile microservice projects, do some packaging based on docker , form a mirror, and then implement automated deployment based on k8s technology. This set of tools is called: continuous integration

Combined with microservice technology and continuous integration, this is the complete microservice technology stack.

Microservice technologies can be roughly divided into five categories

Practice 1 - service communication: The way of remote network communication calling function is RPC (Remote Process Call) remote procedure call.

An RPC framework basically needs to solve the three problems of protocol agreement, network transmission, and service discovery.

①Protocol agreement problem (Stub) refers to how to specify the syntax of remote calls, how to pass parameters, etc.

②Transmission protocol problem (RPCRuntime) refers to what to do when network errors, retransmissions, packet loss or performance problems occur?

③Service discovery problem (plug-in such as: etcd) refers to how to know which services can be called on the server side and from which port to access?

rpc call process:

1. The caller (client) initiates the call in the form of a local call;
2. After receiving the call, the client stub (client stub) is responsible for packaging and encoding the called method name, parameters, etc. into a specific format that can be used for network The transmitted message body;
3. The Client stub sends the message body to the server through the network;
4. The Server stub (server stub) unpacks and decodes the message according to the corresponding format after receiving the message received through the network, and obtains the method name and parameters;
5 , The Server stub makes a local call according to the method name and parameters;
6. The callee (Server) returns the result to the server stub after the local call is executed;
7. The Server stub packages and encodes the return value into a message, and sends it to the client through the network;
8. After receiving the message, the Client stub unpacks and decodes it, and returns it to the Client;
9. The Client gets the final result of this RPC call.
 

gRPC is a high-performance, open-source RPC framework produced by Google, developed based on the ProtoBuf serialization protocol, and supports multiple languages. (ps: rpc is a protocol, and grpc is a framework based on the rpc protocol)

Advantages of grpc

  • Protocol Buffers are highly compressible and fast.
  • HTTP 2.0 streaming.
  • Support multiple languages.

grpc disadvantages

  • Poor readability.
  • Browser support is limited.
  • Poor support for external components

ps : 

  • RPC is mainly used for service calls within the company, with low performance consumption, high transmission efficiency, and convenient service management.
  • HTTP is mainly used for external heterogeneous environments, browser interface calls, APP interface calls, third-party interface calls, etc.

Practice 2— Asynchronous service communication: RPC belongs to synchronous service communication. If we need to use asynchronous service communication, we can use message middleware such as rocketmq or kafka.

Kafka is a distributed stream processing platform. What exactly does this mean?

Streaming platforms have three key functions:

1. Message queue: Publish and subscribe to message streams. This function is similar to message queues, which is why Kafka is also classified as message queues.
2. Store and record message streams in a fault-tolerant and persistent manner: Kafka will persist messages to disk, effectively avoiding the risk of message loss.
3. Stream processing platform: To process messages when they are published, Kafka provides a complete stream processing library.

Kafka has two main application scenarios:

Message Queues: Build real-time streaming data pipelines to reliably get data between systems or applications.
Data Processing: Build real-time streaming data processing programs to transform or process data streams.


Compared with other message queues, what are the advantages of Kafka?

1. Extreme performance: Based on Scala and Java language development, batch processing and asynchronous ideas are widely used in the design, and it can process up to tens of millions of messages per second.
2. Unmatched ecosystem compatibility: Kafka has the best compatibility with surrounding ecosystems, especially in the fields of big data and stream computing.

Practice 3 - service current limiting: add a current limiter at the service entry level. Google's guava rateLimit can provide it. Once there is a problem or abnormality in the service under high concurrency, it will affect a large amount of traffic and a large number of users. rateLimit is thread-safe, so it can be used directly in a concurrent environment without additional synchronization. Each URL uses its own RateLimiter instead of a common one, and it does not take up much memory.

In actual use, you usually use tryAcquire() to detect and try to obtain a license first, and then execute the request if it is feasible; otherwise, you can wait for a period of time until the license is available, or refuse it appropriately.

Guess you like

Origin blog.csdn.net/wodeyijia911/article/details/131405267