当前位置:网站首页>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
边栏推荐
- Zhiniu stock project -- 05
- Cesium entity (entities) entity deletion method
- Code management tools
- 2022年华东师范大学计科考研复试机试题-详细题解
- error C2017: 非法的转义序列
- In depth analysis of kubernetes controller runtime
- 100000 bonus is divided up. Come and meet the "sister who braves the wind and waves" among the winners
- MATLAB如何修改默认设置
- YOLOV1学习笔记
- The dynamic analysis and calculation of expressions are really delicious for flee
猜你喜欢
Selenium - by changing the window size, the width, height and length of different models will be different
Numerical method for solving optimal control problem (I) -- gradient method
这两种驱蚊成份对宝宝有害,有宝宝的家庭,选购驱蚊产品要注意
In depth analysis of kubernetes controller runtime
SQL实现将多行记录合并成一行
IE browser flash back, automatically open edge browser
Ruoyi interface permission verification
数值法求解最优控制问题(一)——梯度法
Fluentd facile à utiliser avec le marché des plug - ins rainbond pour une collecte de journaux plus rapide
SQL implementation merges multiple rows of records into one row
随机推荐
Project summary --2 (basic use of jsup)
Condition annotation in uni-app realizes cross segment compatibility, navigation jump and parameter transfer, component creation and use, and life cycle function
ssh链接远程服务器 及 远程图形化界面的本地显示
Unittest attempt
【LeetCode】Day93-两个数组的交集 II
Openresty best practices
error C2017: 非法的转义序列
Operation principle of lua on C: Foundation
Selenium - 改变窗口大小,不同机型呈现的宽高长度会不一样
Zhiniu stock project -- 04
Decision tree of machine learning
POI dealing with Excel learning
简易密码锁
第8章、MapReduce 生产经验
Use @data in Lombok to simplify entity class code
Time format record
【C#/VB.NET】 将PDF转为SVG/Image, SVG/Image转PDF
“我为开源打榜狂”第一周榜单公布,160位开发者上榜
Migrate data from Amazon aurora to tidb
Creating postgre enterprise database by ArcGIS