Spike system

1. Large amount of concurrency:

1) Request distribution, distribute to different servers, use cluster, Nginx or Apache to distribute.

2) Generally, cache (local cache or third-party cache) is used, and commodity information and remaining amount are stored in the cache, but for specific deduction operations, the database inventory must be locked and verified. The locked products are discarded and put back into the cache to update the cache.

3) In addition to placing the cache, you can also add a flag (such as volatile boolean hadEnd = false) to prevent the activity from ending, or frequently call interface verification. Therefore, in order to prevent other services from being dragged down, the seckill system is generally set up as a service.

4) The page is static

5) Cache to CDN

2. Anti-theft brushing: limit ip, limit the number of clicks, limit the number of requests, limit the designated users and other restrictions.

3. Find out some users with fast speed: you can put them in the ArrayBlockingQueue (blocking queue) to specify the length of the queue, but it is best to use the ConcurrentLinkedQueue concurrent queue (the CAS comparison of the queue may fail, but it is quite fast...), and then Users are taken out of the queue to purchase items one by one. Or a combination of the two, first use the ConcurrentLinkedQueue to receive the request, then take the request out of it and put it into the ArrayBlockingQueue, and then use a single thread for the "inventory database service" to deduct the inventory operation. In addition, it is best to use optimistic locking (that is, the version number update method), and the failure will be returned immediately to prevent too many dead links from being blocked.

 

to be continued. . .

 

Learnable articles:

1. Large-scale concurrency of web systems - e-commerce spikes and snap-ups

2. Detailed explanation of Taobao big second system design

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326529026&siteId=291194637