当前位置:网站首页>How to design a seckill system?

How to design a seckill system?

2022-06-23 17:32:00 User 7353950

Seckill system mainly has three characteristics High performance High concurrency High availability .

Starting from the process of a second kill , Consider the three characteristics of seckill system , Then you can design a seckill system .

1. Seckill page access

Optimization plan :

  1. Dynamic and static separation . Deploy the static resources of the page to Nginx perhaps CDN, This can speed up the seckill page acquisition .
  2. Static resource merge acquisition . By merging multiple requests into a single request , Get multiple static resources at a time , This can speed up the seckill page acquisition .
  3. service degradation . The seckill page is degraded , List the recommended products 、 Downgrade comments, etc , Show less or no . You need to log in to view the seckill page , Return to the login interface directly for users who are not logged in .
  4. Service monitoring . Monitor the flow , Use the token bucket algorithm and other flow limiting algorithms to control the flow . Fuse some tasks if necessary .
  5. Page data cache . Cache page data to Redis in , Reduce database operations .
  6. Second kill connection adding salt . send URL Dynamic , Illegal user operations can be reduced .

2. Order goods

Optimization plan :

  1. front end / Back end current limiting . front end / Client anti shake . Limit the number of orders placed within the time interval .
  2. Anti robot brushing . Add the step of filling in the verification code for the order placing operation , Such as :55+44=?、“ Hello ” Lowercase Pinyin of 、 Select all the aircraft and other questions , Filter out illegal requests .
  3. Withholding inventory when placing an order . When designing database tables, you need to set the lock inventory field . During the second kill , Inventory reduction will be Redis Using distributed locks in . Other subsequent operations can use RabbitMQ To operate .
  4. Withholding inventory when placing an order ( Stock preheating ) You can add delay queues . Forward the timeout goods to the dead letter route , And then operate .
  5. Asynchronous operation can be performed when placing an order , Multiple threads can be used for operations such as double price verification .

3. payment

Optimization plan :

  1. Divide payments into a separate system , Only the corresponding payment interface is opened . Because the payment system is financial sensitive , Therefore, the high availability of the payment system should be guaranteed .
  2. Rollback mechanism . Distributed transactions are recommended , For the payment business TCC Business , Because the payment system is financial sensitive .

therefore , Seckill system usually introduces MQ、Redis、MySQL、Nginx Such as middleware , Each middleware needs to be High performance High concurrency High availability Analysis of .

MQ

Optimization plan :

  1. Cluster deployment .MQ Systems are generally deployed in clusters , Deploy the image cluster , Can improve the availability of the system .
  2. Turn on persistence . Yes MQ The information in the system turns on persistence , Brush it into the hard disk , Prevent downtime .
  3. Turn off automatic consumption ACK, Manual operation is required ACK. Prevent abnormal information consumption .

Redis

Optimization plan :

  1. Redis Read and write separation ,Master Node to write , Read from other nodes .
  2. Redis Deploy sentinels , After a node goes down, it can be replaced by a machine .
  3. Redis Deploy the partitioned cluster , Distribute the requests to each server Redis On the machine .
  4. Enable persistent logging .AOF and RDB Adjust according to business conditions .
  5. A system can have multiple Redis colony , For example, page data and product order Redis You can use multiple clusters Redis.

MySQL

Optimization plan :

  1. Index based on business . unique index 、 General index 、 Joint index, etc .
  2. See if the business is optimized , Reduce the return operation .
  3. Sub database and sub table .MySQL Cluster deployment should be done , A single Redis Usually only 2000QPS about .
    1. sub-treasury . Use MyCat perhaps ShardingSphere And so on , Assign the operation to the corresponding machine by algorithm .
    2. table . There are two types of sub tables: vertical and horizontal . Vertical partitioning is to divide some fields into other tables . Horizontal partitioning is to divide data horizontally into different tables in the same database , Avoid too large data on a table .
    3. Generally speaking , Suggestion points 32 Databases , Each Treasury point 32 A watch , This can fully meet the needs of most enterprises .
  4. MySQL The bottleneck is disk IO, Solid state drives can be replaced .

Nginx

Optimization plan :

  1. Dynamic and static separation . Deploy static resources to Nginx in , No need to query in other middleware .
  2. Nginx The current limiting operation can be started . Both token bucket and exposed copper algorithm support .
  3. Nginx Turn on load balancing , Send the service request to different servers , Reduce the pressure on a single server .

Except for the ones listed above , There are many optimization operations .

Hot data separation

The systems used by hot goods and ordinary goods can be isolated , In this way, even if the secsha system goes down , There won't be any problem in ordering ordinary goods .

  1. Second kill products are put into the hot data system .
  2. Live broadcast products can also be put into the hot data system .
  3. Traffic monitoring . Products with more orders can be put into the hot data system .
  4. Merchant Report . Businesses can report commodities that may sell more in the future , Put it in the hot data system .
  5. Data analysis . Analyze past data , Some products that may sell more in the future , Put it in the hot data system .

performance optimization

Finally, you can optimize the performance of the machine .

  1. Replace CPU
  2. Replace memory
  3. Replace a faster hard drive
  4. to update Linux system kernel
  5. Update the stable version of the software system
  6. close Linux Some useless services above

Seckill system mainly has three characteristics High performance High concurrency High availability . Just think about these three points , Then we will gradually come up with a second kill system .

原网站

版权声明
本文为[User 7353950]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206231642464718.html