Design principles transactional systems

High concurrency principles

1.1 Stateless

If the application is designed to be stateless, application easier to horizontal expansion. However, in the actual production environment, the application is stateless, the configuration file is a state, such as different rooms need to access different data sources, at this time needs to be specified by the profile or distribution center.

1.2 Split

In the early establishment of the system, it is to be a large and comprehensive system or split system according to its function, according to the environmental trade-offs, such as online private school users and the amount of orders is not particularly large, less developed, with limited resources, under such circumstances can be considered to be a large and comprehensive system; a spike-like systems, usually larger in volume, traffic is relatively large, we can consider split by function.
Split mainly the following situations:
System dimensions : splits on system functions / business analysis: such as shopping carts, billing, order systems.
Functional dimensions : for a split system again: as a coupon system can be split into the background to create a coupon system, leading securities system, with the coupon system.
Read and write dimensions : Read a system tends to be somewhat larger than the write module, we can now be split into read and write system system, read when we can use the cache to improve the system, when writing large data, we can consider sub-library sub-table.
AOP dimensions : according to access characteristics, in accordance with the AOP split, for example, product details page can be split into CDN, page rendering system. CDN itself belongs to an AOP system.
Module dimensions : for example, based on, or in accordance with code maintenance split, basic sub-library sub-table, database connection pools; code typically divided according to three-tier architecture (web, service, dao).

1.3 Service of

In-process service - "Stand-alone remote service - a" cluster manually register the service - "Service auto-discovery and registration -" Packet / isolation / routing service - "Service Management as limiting / black and white lists.

1.4 Message Queuing

Message queues for decoupling something or subscribe to the service system does not require synchronous calls their attention. Message Queuing service can be implemented using decoupling (consumer-to-many), asynchronous processing, traffic clipping / buffering, etc., but when too many subscribers, a single message queue will become a bottleneck, this time, to consider the message queue and more a mirror copy.
Note that the message failed to use the production, consumption order message, repeat, transactional messaging messages and so on.

1.5 Cache silver bullet

13280099-1b908aeb83d0ad20.png
Pictures .png

Browser cache : expiration time setting request, as a response to the first Expires, Cache-control control, this mechanism is suitable for real-time data is less demanding high real-time requirement does not apply, such as inventory and the like.
APP client cache : cache in the big promotion is to prevent traffic impact can be issued in advance (js / css / image, etc.) to the client.
CDN caching : Some pages, images, pages, and other activities can be considered from the user pushed to the CDN node close, when the user gets near acquired, there are two mechanisms: push and pull mechanism and other mechanisms.

1.6 Heterogeneous Data

Heterogeneous data : Order-library sub-table is divided in accordance with the general order id, if you want to query a user's list of orders, you need to aggregate data from multiple tables to return, this will result in reduced read performance of the Orders table, this time need orders heterogeneous set of tables. For heterogeneous data of little significance, consider using asynchronous loading, or merge concurrent requests.
Data loop : too many data sources, many factors affect the stability of the service, so the best way is to use the data to heterogeneous storage, forming a closed loop data is usually divided into three steps: heterogeneous data, data aggregation, front-end display.


Heterogeneous data and the data is actually a closed loop concept, the goal is to achieve self-control data, and when a problem does not affect other systems themselves, or do not affect other system problems themselves, to achieve general data distribution through the message queue.

1.7 of concurrent

The serialized data exchange in multi-threaded execution, this time to consider the security thread

Availability principle

2.1 Downgrade

For high-availability service is very important to design a switch that downgrade, downgrade in the design of the switch, the main basis for ideas:

1. Centralized management switch: by pushing the switch mechanism pushed to each application.
2. The downgrade of multi-level reading services: such as service call local cache downgraded to read-only, read-only distributed cache, the default read-only data downgraded (such as inventory stock status by default).
3. Switch of the front: As Nginx → tomcat time architecture, the switch can be prepended to the Nginx access layer, as switching in Nginx layer flow back to the source of the request or only a small rear end portion of the application flow back to the source.
4. Business Downgrade: When high concurrent incoming traffic, you can talk about some synchronous calls into asynchronous calls. Data priority or high priority data specific characteristic, a reasonable allocation of traffic into the system to ensure that the system is available.

2.2 limiting

Limiting purpose is to prevent malicious traffic request, malicious attacks or prevent the flow exceeds the system peak

1. malicious traffic only request access to the cache.
2. For the flow penetrates into the rear end of the application may consider the use of Nginx limit module for processing.
3. For use Nginx deny ip malicious shield.

2.3 cut traffic

1.DNS: switching room entrance
2.HttpDNS: inlet flow rate at the assigned client, bypassing operator LocalDNS traffic scheduling and achieve more precise.
3.LVS / HaProxy: Nginx access layer switch failure.
4.Nginx: application layer handover failure.

2.4 can be rolled back

When a program or data problems, you can roll back by version to the correct version of the most recent version to ensure the correctness of the program

Content Source "one hundred million website traffic with open architecture core technology to build highly available high concurrency Tao school system."

Guess you like

Origin blog.csdn.net/weixin_34320724/article/details/90843262