Distributed base (1) - a large site architecture evolution

In this paper, a reference from "large-scale Web Site Technology Framework: Core Principles and Case Studies," a book first chapters and other online articles, if any omission or mistake, forgive us and pointed. Thank you!

Here Insert Picture Description

The world is no large sites from the site since birth; there is no one on site first release has a huge user, high concurrent access to vast amounts of data; large sites are evolved from small sites. Value of the site is that it provides little value to users, is what the site can do, not for how it was done, so when the site was still very young and went to pursue architecture of the site is by the end of this round, worth the candle. Most small sites need to do is to provide users with good services to create value, get user acceptance, live, barbaric growth.
- "large-scale Web Site Technology Framework: Core Principles and Case Studies"

It features a Large website system

Internet development in the past two decades, more and more sites is on the rise, many small flow from the development of the site, a small concurrent mode now beginning to huge traffic and high concurrency mode, there are many technical architecture during evolution, typical examples include Taobao, FaceBook, Twitter and other sites and systems, so research and study the evolution of large-scale site technical architecture is very necessary.

To Taobao, for example, such a large-scale site system has the following characteristics:

1. Large flow

Taobao year 2018 the number of active 580 million people, there are ten million to one hundred million users in everyday use, great all traffic.

2. high concurrency

In an example two-eleven, only the open two-eleven seconds to produce a flow of billions of money, the user great concurrent requests.

3. High Availability

Taobao all the time will have a lot of orders, if we can not guarantee 24 hours of continuous service, it would have a significant impact on the user and stores such as Taobao, this time requires a server with high availability, 99.9999% (the year 99.99999% of the time) of the available time.

4. Mass data

Daily order data or user data, store data, and so thoroughly great to P as the basic unit, we need thousands of servers to store the data.

5. Users are widely distributed

Taobao has a large number of domestic and overseas users, the user profile is very broad.

6. Network complicated

The network of the affected area, for example, domestic users can not access some foreign server resources, each operator also has a network interworking problems.

7. agile development and rapid iteration

Due to the needs of users or industry, and other hot spots will change at any time, so large sites need agile development and rapid iteration.

8. harsh security environment

Because the tree attracts the wind, the more large sites and systems, the more hackers, security environment in which the more harsh, so how to deal with security issues it is also a very important point.

II. Large site architecture evolution

May simply be a large site architecture evolution process is divided into several "Time", each era are resolved current problems need to be resolved.

1. Stand-alone era

In the early creation of the site, because users of the order, less request, low concurrency, it is generally taken to applications, file services (such as photo storage) and databases on a single server, for example, now many small sites We have adopted the LAMP technology architecture (Liunx + Apache + MySQL + PHP) to deploy a stand-alone system. This time using this single architecture that can hold up, the general personal website or enterprise systems architecture widespread use of this technology, which is the simplest kind of technical architecture.

Here Insert Picture Description

2. Multi-era machine

With the development of the site, more and more data on a single server, resulting in slow disk IO, it appears the applications and file storage system, the database is divided into multiple servers to deploy architecture, so that you can let different server roles, such as deploying applications on the CPU better, faster processing speed of the server, and deploy databases on fast disk IO servers, large disk space in the file system server deployment.

Here Insert Picture Description

3. Cache era

When the site just keep getting better, more and more requests for a long time, a large number of requests, but to even make the database processing is blocked, downtime, delayed more and more, this time to introduce the practice of caching.

We must first be clear that the requesting system is also consistent with twenty-eight law, that request will most probably focus on two percent of the data sets, such as Taobao, most of the requests are browsing request goods, while a small part of the request to buy modify house, so in this case to distinguish between hot data and cold data, the request for the most heat is sent to the data cache, rather than directly to the database requests, thereby improving the speed and reducing the access request response pressure of the database .

Cache can be divided into local and remote caches caches, e.g. Redis can be deployed as a dedicated remote cache in the cache server, and the technique can be used as ehcache local cache, the cache is located on a portion of the application server.

Here Insert Picture Description

4. Cluster era

When the cache solve the problem, the database no longer withstand much pressure, but for the application server, but still need to continue under a lot of pressure, this time there has been a bottleneck in a large number of concurrent requests an application, perhaps because the bandwidth of the server itself limited or not the server itself can handle the connection request, then there are two options:

Vertical expansion: Continue to select the bandwidth bigger, better processor server to deploy the application, but no matter how good the configuration server, eventually there will be enough time to configure, so you can choose the level of expansion.

Horizontal expansion: the request since a server can handle is limited, then why can not handle more requests to expand by more machines? At this time there has been such a cluster solution, distribute requests to multiple servers to handle by adding servers to take the load balanced manner, then it can handle more requests

Here Insert Picture Description

The separate read and write Times

To further reduce the pressure write cache database or the database can read and write requests to different machines distributed processing, thus creating the separate read and write architecture, which is often used in the MySQL and Redis, so We do have two advantages:

  1. The separate read and write, load balancing request
  2. Loss of data backup and disaster recovery, preventing data

Here Insert Picture Description

6. reverse proxy and content delivery network

Since the development of the site is getting better, users located around the world, at this time if our resources such as images, documents, CSS are all deployed on the server a fixed position, then farther away from this server users, its access resources will be slower speed.

The turnover rate of the site access speed and response speed is inversely proportional relationship with the user, then the need to improve the access speed of the user's different regions

Content Delivery Network (CDN) is essentially the deployment and the cloud service provider's server resources, when a user requests a resource on the CDN, priority will forward the request to the server closest to the user, so that you can increase the user's access speed.

The reverse proxy server role is forwarded to the user's request, if found to have been cached, then the cache will return directly.

CDN and reverse proxy role here is to be able to respond faster to user resources needed

Here Insert Picture Description

7. The underlying services cluster

Now this site architecture have been more perfect, but we found the database and caching services exist only two machines: a write providing server, a service provided to read, but then there will be a problem, is a table in the database there a lot data or the server's cache memory is occupied full, separate read and write at this time in any case, due to the always synchronized with the main library, so will be filled from the library from the library, and thus can not provide the underlying services of external or responds slowly, then practice and expand the level of the beginning of the same application server, which is adding more underlying services.

Horizontal expansion: by adding more machines underlying services to the database or cached data and pressure distribution continues, so that data can be shared equally to solve the problem of excessive monomer pressure on different underlying service machines.

Here Insert Picture Description

8. Search engine technology and NoSQL

At this site architecture has been thoroughly improved, but such as keyword search, product data storage and other commodities will be some problems in certain services.

Product keyword search service, if you use common database with fuzzy query to achieve it, because the query does not go fuzzy index, when the amount of data when the query process is very slow and time-consuming computing resources, hence the search engine technology, such as Solr, ES, etc. to solve this problem, on the one hand to optimize the efficiency of keyword search, on the other hand you can share part of the data to Solr or ES database.

Data storage of goods, if you use the database to do the words of each data field and will occupy a lot of space, then you can use such as MongoDB NoSQL database to store these data can greatly improve query speed and reduce the space occupied.

Here Insert Picture Description

9. Split Service Services of micro

When the site's business more and more, more and more developers, at this time there have been some problems:

  1. More complex operations, coupled together across different services, difficult to modify
  2. Application code increasingly large pack for a long time
  3. Single business there is a problem entire service have led to the collapse, affecting the normal operation of other services

So, there are architects made the following recommendations:

1. business complex, the ability to split the team in the future by business line, line of business will be split into as payment services, home services, customer service and other business, and then let go a different team responsible for the development, when you need to rely on the service by calling a remote way calling

2. Place a large application is split into small applications deployed separately, so as not to produce an application hangs up the problem can not cause other applications to provide services

So in recent years there has been a very popular way of website architecture: Micro service of

Of micro-services, i.e. by application of a large split into small application service module, and then use that mutual cooperation between the small RPC application, thus constituting a large application.

Here Insert Picture Description

Published 309 original articles · won praise 205 · Views 300,000 +

Guess you like

Origin blog.csdn.net/pbrlovejava/article/details/104841457