1. Basic Concepts

1. Single service

All service services and application components are deployed on one service to save costs. This single-service architecture is suitable for scenarios with low concurrency and single services.

2. Cluster mode

The business volume increases gradually, the concurrency is high, the level expansion of a service, do a service group, request pressure dispersed to different services to deal with, each service is called a node of the cluster, to this is the cluster service.

3. Distributed architecture

Distributed structure is divided into independent sub-services according to business functions, independent library table, can run independently, and communication and interaction between services, bringing benefits to reduce the degree of coupling between services, convenient development and maintenance, horizontal expansion, high reuse and so on.

4. Technical system

Service infrastructure: Dubbo framework, SpringCloud framework;

Container operation and maintenance: Docker, Kubernetes;

Data storage: relational MySQL, NoSQL database, OLAP engine;

Common components: Zookeeper coordination, MQ asynchronous, Redis cache;

Second, distributed framework

1. Dubbo framework

With the increasing number of vertical applications, interaction between applications is inevitable. Core businesses are extracted as independent services, gradually forming a stable service center, so that front-end applications can respond to changing market demands more quickly. At this point, the distributed Services framework (RPC) for business reuse and integration is key. Core capabilities of the Dubbo framework: interface-oriented remote method invocation, intelligent fault tolerance and load balancing, and automatic service registration and discovery.

2. SpringCloud Framework

The most mature framework for distributed architectures, SpringCloud is an ordered collection of frameworks. It makes use of SpringBoot’s development convenience to subtly simplify the development of distributed system infrastructure, such as service discovery registration, configuration center, message bus, load balancing, circuit breakers, data monitoring, etc., can be started and deployed with one click with SpringBoot’s development style.

https://github.com/cicadasmile/spring-cloud-base
Copy the code

Core components

Registry: with service discovery, service record, query, dynamic management mechanism. Common registries, Zookeeper, Eureka, Consul, Nacos, etc.

Fuse degrade: Prevents sudden and concurrent traffic from flushing the system and ensures that such packets are sent at a relatively uniform speed to protect the stability of the system. Commonly used to calculate the law card bucket, funnel; Common components Nginx, CDN, Hystrix and Sentinel control traffic through different nodes.

Service Gateway: Also a service on the whole architecture, acting as a unique entry point for requests, very similar to the facade pattern, handling all non-business functions at the gateway layer and providing custom apis for clients. Commonly used components Zuul, Tyk, Kong.

https://github.com/cicadasmile/husky-spring-cloud
Copy the code

3. Business components

Message middleware: RocktMQ, Kafka, RabbitMQ, etc.

Cache middleware: Redis, Eache, etc.

Distributed transaction: Seata, Hmily, TCC-Transaction, etc.

3. Architectural details

1. Global ID policy

All data generated by business scenarios need a unique ID as the core identification for process management. Common examples include UUID, snowflake algorithm, auto-increment primary key, ID container, etc.

2. Interface idempotency

Idempotent operations are characterized by the fact that any number of executions have the same effect as a single execution. That is, one request for a resource has the same effect as multiple requests. Idempotent operations are especially important in interface, retry, and compensation scenarios.

3. Cache processing

In the business system, the module that is most prone to performance problems when querying faces a large amount of data and complex screening conditions. Therefore, it is very necessary to introduce a cache layer in the system architecture, which is used to cache hot data, archived data, home page query, etc., to achieve the purpose of fast response.

4. Asynchronous processing flow

Asynchronism is a design concept. Asynchronous operations are not equal to multithreading, MQ middleware, or message broadcasting. These are the ways in which asynchronous processing can be implemented.

5. High concurrency and resource locking

The core of high-concurrency business is flow control. It is a relatively complicated process to control the sinking speed of flow or the size of the container to undertake flow. On the one hand, the request volume can be solved by traffic shaping; on the other hand, the problem of concurrent access to resources can be solved by locking.

Distributed transactions

More details of different service database operations, these no perception of detail distribution on the different service operation, even belong to different areas and application of participant in the transaction, support transaction server, the server resources and transaction manager respectively located in different different nodes of a distributed system, how to ensure the operation all succeed or all fail, That is to ensure data consistency between different databases, which is the core problem to be solved in distributed transactions.

https://github.com/cicadasmile/data-manage-parent
Copy the code

Data source component

1. Relational databases

A database that uses a relational model to organize data in rows and columns, such as MySQL and Oracle. In distributed systems, in order to ensure the stability of core processes, relational databases are basically used for key services. When services are completed, if there is a large amount of data, the data will be synchronized to other components with high query performance.

NoSQL database

NoSQL means “more than SQL”. A general term for database management systems that are different from traditional relational databases. NoSQL is used to store very large scale data. These types of data stores do not require fixed schemas and can scale horizontally without unnecessary operations. For example, MongoDB, Cassandra, etc.

3. Data management strategy

Read and write library separation, query data sub-library sub-table, distributed service sub-library, based on user traffic sub-library.

https://github.com/cicadasmile/data-manage-parent
Copy the code

5. Service monitoring

1. Production failure

In the distributed complex architecture, problems at any level of application service, software service, and hardware service may lead to incomplete execution of requests, resulting in a series of effects. It is critical to do a good job in monitoring the whole link and quickly locate problems.

2. Application layer monitoring

The application layer is the service logic service that is developed, and it is also the layer that is most prone to sudden problems. The application layer monitors the system in terms of request traffic, service link meltdown, and system exception logs to check whether the system is stable.

3. Software layer monitoring

This usually means database level, like Druid’s monitoring analysis; Common middleware, such as RocketMQ’s console; Redis cache: provides commands to obtain relevant monitoring data, etc.

4. Hardware layer monitoring

At the hardware level, it focuses on three core contents: CPU, memory and network. If a fault breaks out in underlying hardware resources, it is triggered by upper-layer application services or middleware services. Mature monitoring frameworks such as Zabbix, Grafana, etc.