当前位置:网站首页>Personally design a highly concurrent seckill system
Personally design a highly concurrent seckill system
2022-07-03 06:37:00 【Bright in snow】
One 、 demand
- There are a number of products , Every product has 100 Pieces of , You can buy at most one item per person .
- stay X month X Japan X when X branch 0 Seconds to start buying . Before the appointed time , You can only see the product page , The buy button is grayed out .
Two 、 Activity estimates
- It is estimated that tens of thousands of people will participate in each commodity
- Within half a minute of the start of the activity , Expect each item to receive 10W This transaction request , Estimated total TPS:20W/s
- Half a minute after the activity started , Most of the goods are expected to be sold out , The rest of the products still support seckill , Estimated total TPS:2000/s
3、 ... and 、 System status
- The system can maintain a long-term stable operation of the maximum TPS:1000/s
- short time 「1 Within minutes 」 The highest number of system non denial of service TPS:1500/s
Four 、 Design pre research
Scheme 1 : Revamp the existing system , The overall number of micro service systems has increased significantly TPS
advantage :
- A substantial increase TPS after , The business system can directly carry a large number of transaction requests , It's easier to deal with the second kill demand .
shortcoming :
- The number of second kill activities is less , Transformation cost 、 Risk is bigger , Low cost performance
- After transformation , The system architecture will be more complex , Reduced maintainability
Option two : Develop new applications , Carrying the demand ; Transform existing applications to support new ones
advantage :
- The transformation of the existing business system is small , The cost is low .
- Use the new application to carry the second kill transaction request , High flexibility , Don't think too much about backward compatibility .
shortcoming :
- The user experience needs to be sacrificed to a certain extent .
Conclusion
Based on cost and feasibility considerations , Scheme 2 is adopted
5、 ... and 、 Architecture design
5.1 Existing architecture design
- The foreground application directly undertakes user access 、 Transaction request , nothing CDN service .
- After the foreground application receives the transaction request , direct RPC Synchronous request middle application
- After the middle application receives the transaction request , Synchronous completion of order creation 、 payment 、 Number of goods deducted 、 Complete business processes such as transactions
- The front application receives the processing result of the middle application , Show users the logistics information of trading goods .
5.2 Latest architecture design
5.2.1 Architecture design at a glance

5.2.2 Service module design
1. front end 、 The client discards the transaction request randomly
- According to the number of times users view the product details page , Estimate the popularity of the product , Set different discard ratios for different products , Design fields :discard, The value is [0, 100), As a commodity attribute .
- front end 、 client , When a user submits a transaction request , Generate [0, 100] Random numbers in the range ,discard < Orders with random numbers are discarded directly , But show users the queuing page , line up 10 Seconds later, the transaction failed .
2. Provide CDN service
- Static resources are preserved CDN In service
- Special seckill page displayed on the front end , except 「 The deal was initiated 」 Out of request , No user's operation will be requested to the company's microservice business system .
3. Develop specialized 「 Second kill app 」, Provide fusing service
- The seckill application directly carries the front end 、 Transaction request from client , The authorization request is sent to the foreground application for processing , Authorization denied requests are intercepted directly , Return transaction failed .
- Second kill application through configuration center , Get the latest configuration in real time . Configurable discard ratio for transactions , Development colleagues in the second kill period , Adjust configuration , Guarantee transaction requests to business systems ,TPS Stay in 10000/s within .
- Seckill application has no database , No state , After horizontal expansion, the throughput can be increased proportionally .
4. The existing business system optimizes throughput
- The front desk 、 In the middle of the application , Optimize the throughput by optimizing the design , There are the following optimization methods :
- Adopt the horizontal splitting method of sub database and sub table , Scale out the database , It can also be greatly increased at this time POD Count
- Static data is cached in Redis in , Data from Redis To take , Ensure that the database will not be read , Background scheduled task update cache .「 Ensure that the cache is updated regularly without cache breakdown 」
- Library sub-table policy :
- Split database and application according to commodity
- According to the user id Second split database and application
- After the above optimization , At least the short-term development of the middle platform business system can be realized 「1 Within minutes 」 The highest number of system non denial of service TPS, from 2000/s Up to the 4000/s
- Because the foreground application logic is simple ,TPS It can be promoted to 10000/s, No need to optimize .
- Because of the barrel effect , The short time of the whole business system 「1 Within minutes 」 The highest number of system non denial of service TPS, by 4000/s
5. Asynchronous queues
- The foreground application efficiency is high , Just optimize the mid platform application here .
- The foreground application sends all the second kill transaction requests to Kafka, The application of the middle platform is through Kafka News consumption , Carry out the actual business processing .
- As the peak period of business is only half a minute at most ~ 1 minute , The middle platform is used in 2 It's acceptable to process all the transactions in about minutes .
- Kafka Of TPS For dozens of W/s, The front desk 5000/s ~ 10000/s Of TPS No pressure .
- After this optimization , The short time of the whole business system 「1 Within minutes 」 The highest number of system non denial of service TPS, Can be obtained from 4000/s Up to the 10000/s
shortcoming : In extreme cases , The deal will be slow .
6. service degradation
- Half an hour before the start of the second kill to half an hour after the end of the second kill , In this time period , Some services are degraded
- Within the time frame , Don't show logistics information 、 Invoice generation and display are not supported , Ensure the stability of the core business system
边栏推荐
- SSH link remote server and local display of remote graphical interface
- 机械观和系统观的科学思维方式各有什么特点和作用
- The mechanical hard disk is connected to the computer through USB and cannot be displayed
- 第8章、MapReduce 生产经验
- 【5G NR】UE注册流程
- The most classic 100 sentences in the world famous works
- Scripy learning
- [system design] proximity service
- 冒泡排序的简单理解
- Page text acquisition
猜你喜欢
随机推荐
輕松上手Fluentd,結合 Rainbond 插件市場,日志收集更快捷
Zhiniu stock project -- 05
Creating postgre enterprise database by ArcGIS
Selenium ide installation recording and local project maintenance
Mysql database
2022 CISP-PTE(三)命令执行
Summary of the design and implementation of the weapon system similar to the paladin of vitality
Paper notes vsalm literature review "a comprehensive survey of visual slam algorithms"
Reinstalling the system displays "setup is applying system settings" stationary
Unit test framework + Test Suite
【code】if (list != null && list.size() > 0)优化,集合判空实现方式
Project summary --2 (basic use of jsup)
How to scan when Canon c3120l is a network shared printer
error C2017: 非法的转义序列
Create your own deep learning environment with CONDA
Floating menu operation
Common interview questions
堆排序和优先队列
Numerical method for solving optimal control problem (I) -- gradient method
Fluentd facile à utiliser avec le marché des plug - ins rainbond pour une collecte de journaux plus rapide









