Guli Mall Study Notes (1): Distributed Basic Concepts

1. Microservices

The microservice architecture style is to split a single architecture into multiple service modules according to the business. Each module is independently deployed and operated without affecting each other, and uses a lightweight mechanism for communication, usually HTTP API.

2. Cluster & Distributed & Node

Cluster is a physical form, and distributed is a way of working.
As long as it is a bunch of machines, it can be called a cluster. No one knows whether they work together or not;

"Distributed System Principles and Generics" defines:

"A distributed system is a collection of independent computers that appear to users as a single related system." A distributed system is a software built on a network system.

Distributed means that different services are distributed in different places.
Clustering refers to bringing together several servers to achieve the same business.

For example: Jingdong is a distributed system, many businesses run on different machines , and all businesses form a large business cluster. For each small business, such as user systems, one server is not enough when the access pressure is high. We should deploy the user system to multiple servers, that is, each business system can also be clustered. The user will feel that he is using one system rather than a bunch of computers.

Every node in the distributed system (node: a server in the cluster) can be a cluster. The cluster does not have to be distributed.

3. Remote call

In a distributed system, each service may be located on different hosts, but it is inevitable that the services need to call each other, which we call remote calls.

In Spring Cloud , HTTP+JSON is used to complete remote calls , because HTTP and JSON naturally support cross-platform.

image_name

4. Load balancing

Load balancing means that service A sends requests to service B. In order to ensure that the number of requests that each machine in the cluster can handle is as even as possible, some operations performed by service B are load balancing algorithms.

Common load balancing algorithms:

  • Polling : The first request is selected and handed over to the first backend server in the connection pool for processing, and then selected in turn until the last one, and then looped.
  • Minimum connection : Prioritize the server with the least number of connections, that is, the server with the least pressure. In the case of a long session, this method can be considered.
  • s hash : Select the server to be forwarded according to the hash (hash) of the IP address of the request source. Requests from the same IP address (that is, the same user) will be sent to the same server . Consider this approach if your application needs to handle state and requires the user to be able to connect to the same server as before.

5. Service Registration/Discovery & Registration Center

Service A calls service B. Service A does not know which servers currently have service B, which servers are normal, and which servers are offline. To solve this problem, the registration center can be introduced:

image_name

If some services go offline, the rest of us can sense the status of other services in real time, avoiding unavailable services.

6. Configuration Center

Each service ends up with a lot of configuration, and each service may be deployed on multiple machines. But we often need to change the configuration, so we can design a configuration center to let the server automatically go to the configuration center to obtain its own configuration.

image_name

7. Service circuit breaker & service downgrade

In the microservice architecture, microservices communicate through the network and there is interdependence. When one of the services is unavailable, there may be a chain effect that causes all services to be unavailable, resulting in an avalanche effect. To prevent such a situation, fault-tolerant mechanisms must be in place to protect the service.

image_name

1) Service fusing
a. Set the timeout of the service. When the called service often fails to reach a certain threshold , we can enable the circuit breaker protection mechanism, and subsequent requests will not call this service. The local directly returns the default data.
2) Service downgrade
b. During the operation and maintenance period, when the system is at its peak and the system resources are tight, we can downgrade the non-core business. Server resources are used in more important places. Downgrade: Some services do not handle, or simply handle (throw exception, return NULL, call Mock data, call Fallback processing logic)

8. API Gateway

API Gateway abstracts the public functions required in microservices, and provides rich functions such as client load balancing, automatic service fuse, grayscale publishing, unified authentication, current limiting and flow control, log statistics, etc., helping us solve many API management problems problem.

This project adopts front-end and back-end separation, and needs to communicate through HTTP. When the request is sent from the client to the server, the HTTP request will first pass through the gateway. This gateway is equivalent to the security check entrance to check whether the request is legal. If it is legal , you can let go. When the amount of requests increases sharply, the gateway can also allow requests to be released at a constant speed.

image_name

Guess you like

Origin blog.csdn.net/e2788666/article/details/130988627