Today, Lao Li is talking with us about the pattern of distributed system architecture. Before we start talking about patterns, let’s start with the question, why do we do distributed architecture?

Most developers and most systems have probably never touched distributed systems, and there is no need for a distributed system architecture. Why? There is no need for distributed architecture when traffic or QPS are not at the performance bottleneck of a single machine. Then if the volume of business up, how to solve the general?

The first consideration is to upgrade the machine. Vertical expansion of machine configuration, first of all to find the current performance bottleneck point, is CPU, is memory, is hard disk, or bandwidth. Throwing money at cpus, throwing money at SSDS, throwing money at 1TB of RAM is usually the most straightforward and efficient way to solve the problem. Not enough bandwidth? Plus bandwidth, 1 gb is not enough for 100 GB. CPU 8 cores not enough? 32 cores 96 cores. This is the first solution that most companies can think of, and it is also the most efficient, fastest and safest way to achieve immediate results.

Secondly, the system is split. The main process and branch process of the service provided are sorted out and the system is split according to the process. Like a tree, the core business serves as the backbone process, and other systems are divided as needed, just like the branches and leaves of the tree. There are a number of ways that you can split it up by front and back, split it up by domain, split it up by team, and of course in general these splits are basically following the organization structure.

At the end of the day, the technology can be upgraded to be more efficient or suitable for the scene. For example, from Oracle to HBase. The database connection pool A is changed to database connection pool B. Technological change is also very huge to support the volume of business, the same machine with different technology, the degree of efficiency can be said to have a world of difference.

A distributed architecture is a last resort, it’s really not going to cost that much money, it’s really not going to work. Because distributed architecture is bound to bring very much very much consistency problem, originally only need access to a machine, now need to access the N units, so that how to ensure the consistency of the N machine, support dead before having a master-slave backup is gone, it is good to sync the data, how now N equipment data management, and even how to manage the cluster itself, Can be a fatal problem.

So only such as business volume to a certain extent, a single machine can not carry, will begin to pile money upgrade machine, system split, change technology, continue to pile money upgrade machine, system split… Go round and round and find out that the cost is too high or the technology has already come online. In the end, we chose distributed architecture.

However, the advantages of distributed architecture are also obvious. A group of inexpensive devices are used to provide a stable system with high performance and high throughput. Let’s start with the common distributed cluster architecture.

1. Pure load balancing.

In front of the cluster, there is a traffic distribution component for traffic distribution, and the entire cluster of machines provides undifferentiated services, which is the most common in a common Web server. At present, the more mainstream way is the cloud on the whole cluster machine, according to the real-time volume of cloud server elastic scaling. Common load balancers include HARDWARE level F5, software level NGINX and so on.

2, leadership election type

Messages from the entire cluster are forwarded to the cluster leader, which is a master-slavers mode. The difference is that the master is temporarily elected. Once the master fails, the cluster immediately elects a new leader to continue providing services. Examples of applications that use leader-elected architectures are ElasticSearch and ZooKeeper.

3. Block chain

Each node in the cluster can be recorded, but the recorded content must be approved by the entire cluster N machines to be valid. Typical applications are Bit Coin and Hyperledger.

4, master – slaver

The entire cluster uses a master as the hub to schedule the cluster. Generally, all management data is stored on the master and specific data is stored on slaver. In actual invocation, the client first calls the master to obtain information about the server where the data is stored and then interacts with the slave. A typical system is Hadoop. Cluster, HBase cluster, Redis cluster, etc.

5. Regular consistency Hash

This type of architecture usually appears in the design of database subtables. According to the rules, the library and table are divided, and the rules engine is used to confirm the library and table before the query, and then the specific application is accessed. Why consistent Hash? You can use anything, but consistency hashes are common for these types of applications.

Ok, so far, I have covered most of the distributed cluster routines I know, to summarize.

1. Upgrading machine configuration is the most direct way to upgrade. Don’t use distribution unless you have to

2. The core of distribution is service separation and traffic distribution.

Recommend a networking group: 650385180, which will share some videos recorded by senior architects: Spring, MyBatis, Netty source code analysis, high concurrency, high performance, distributed, microservice architecture principle, JVM performance optimization these become architects necessary knowledge system, we explain the knowledge system here in the group also have free download. You can also receive free architect learning resources:

Come to. Leave a message and let me know someone else is watching