当前位置:网站首页>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
边栏推荐
- Interface test weather API
- Shell conditional statement
- In depth analysis of kubernetes controller runtime
- 堆排序和优先队列
- Fluentd is easy to use. Combined with the rainbow plug-in market, log collection is faster
- 【code】偶尔取值、判空、查表、验证等
- Important knowledge points of redis
- YOLOV3学习笔记
- PMP notes
- Ruoyi interface permission verification
猜你喜欢

ruoyi接口权限校验

輕松上手Fluentd,結合 Rainbond 插件市場,日志收集更快捷
![[set theory] relational closure (relational closure solution | relational graph closure | relational matrix closure | closure operation and relational properties | closure compound operation)](/img/a4/00aca72b268f77fe4fb24ac06289f5.jpg)
[set theory] relational closure (relational closure solution | relational graph closure | relational matrix closure | closure operation and relational properties | closure compound operation)

YOLOV3学习笔记

Kubesphere - build MySQL master-slave replication structure

数值法求解最优控制问题(一)——梯度法

Advanced technology management - do you know the whole picture of growth?

使用conda创建自己的深度学习环境

Summary of UI module design and practical application of agent mode

2022年华东师范大学计科考研复试机试题-详细题解
随机推荐
A letter to graduating college students
Time format record
The difference between CONDA and pip
利用C#实现Pdf转图片
使用conda创建自己的深度学习环境
如何迁移或复制VMware虚拟机系统
Opencv mouse and keyboard events
Creating postgre enterprise database by ArcGIS
有意思的鼠標指針交互探究
. Net program configuration file operation (INI, CFG, config)
100000 bonus is divided up. Come and meet the "sister who braves the wind and waves" among the winners
“我为开源打榜狂”第一周榜单公布,160位开发者上榜
学习笔记 -- k-d tree 和 ikd-Tree 原理及对比
Cannot get value with @value, null
ROS+Pytorch的联合使用示例(语义分割)
Migrate data from Mysql to tidb from a small amount of data
Docker advanced learning (container data volume, MySQL installation, dockerfile)
[leetcode] day93 - intersection of two arrays II
论文笔记 VSALM 文献综述《A Comprehensive Survey of Visual SLAM Algorithms》
Advanced technology management - do you know the whole picture of growth?