When a project is started to implement basic functions, as versions and functions go through iterations, big data and high concurrency become a must for software design!

The essence is very simple, one is slow, one is waiting. The two are interrelated, because slow, so wait, because wait, so slow, solve the slow, also solve the wait, solve the wait, also solve slow.

The key is how to solve the slow and equal core, one is short, one is less, one is shunting, and the last one is clustering/horizontal expansion/read/write separation/establish master/slave

short

Page static – the user can fetch the page directly without having to go through a lot of process, which works well with less frequent page updates. Use cache – The first fetch is quasi-fetched from the database, then stored in the cache, and the data can be fetched directly from the cache later. However, there needs to be a mechanism to maintain consistency between the cache and the database.

Use stored procedures – Operations that require multiple database accesses to process a single request can be consolidated into stored procedures so that only one database access is required.

Batch reads – In high concurrency cases, multiple requests can be consolidated into one query to reduce the number of database accesses

Delayed modification – In the case of high concurrency, multiple modification requests can be saved in the cache first and then the data in the cache can be periodically saved to the database. The risk is that the data in the cache may be lost due to power outages.

Use indexes – Indexes can be considered special caches, and the maximum use of indexes requires the exact values of the index columns in the WHERE clause.

less

1, table – the original content of the same table, can be divided into multiple tables according to the region, category, etc., a very simple idea, but to try to avoid points out of the multi-table associated query.

2, separate the active data – for example, the login user service, there are many registered users, but the active login users are very few, you can save a special table for active users, query is to query the active table first, if not, then check the total table, which is similar to the cache.

3, block – database level optimization, is transparent to the program, query big data only to find the corresponding block; For example, transaction module

shunt

1. Cluster – Distributes concurrent requests to different servers, either a business application server APP or a database server.

2. Distributed – Distributed is to distribute multiple business logic of a single request to multiple servers, so that a lot of logic can be processed synchronously, generally used with particularly complex business requests.

3. CDN – At the domain name resolution level, for example, the user requests in South China are allocated to the server in South China and the user requests in central China are allocated to the server in central China.

4, sub-library sub-table –

Horizontal split [sub-table] :

For very frequent access and a large amount of data in a single table, the first thing to do is to reduce the number of records in a single table, in order to reduce the time required for data query, improve the database throughput, this is called split table [horizontal split]

Vertical split [library] :

According to the business coupling, different tables with low correlation are stored in different databases, and the database is split, so as to improve the ability of database writing, namely, vertical split.

The primary database handles transactional queries, while the secondary database handles select queries. Database replication is used to change changes caused by transactional queries. Synchronizes with millisecond updates to the secondary database in the cluster.