当前位置:网站首页>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
边栏推荐
- Opencv mouse and keyboard events
- Naive Bayes in machine learning
- Use abp Zero builds a third-party login module (I): Principles
- The difference between CONDA and pip
- ssh链接远程服务器 及 远程图形化界面的本地显示
- JMeter performance automation test
- [untitled] 5 self use history
- Cesium Click to obtain the longitude and latitude elevation coordinates (3D coordinates) of the model surface
- 【C#/VB.NET】 将PDF转为SVG/Image, SVG/Image转PDF
- Cannot get value with @value, null
猜你喜欢

Une exploration intéressante de l'interaction souris - pointeur

In depth analysis of kubernetes controller runtime

Project summary --2 (basic use of jsup)

【无标题】

JMeter performance automation test

Support vector machine for machine learning

Yolov2 learning and summary

Zhiniu stock project -- 05

YOLOV2学习与总结

Time format record
随机推荐
Print time Hahahahahaha
Read blog type data from mysql, Chinese garbled code - solved
机械观和系统观的科学思维方式各有什么特点和作用
Heap sort and priority queue
JMeter linked database
Difference between shortest path and minimum spanning tree
Scripy learning
Mysql
DNS forward query:
Selenium - 改变窗口大小,不同机型呈现的宽高长度会不一样
The difference between CONDA and pip
Zhiniu stock project -- 04
Numerical method for solving optimal control problem (I) -- gradient method
Advanced technology management - do you know the whole picture of growth?
輕松上手Fluentd,結合 Rainbond 插件市場,日志收集更快捷
Migrate data from Amazon aurora to tidb
这两种驱蚊成份对宝宝有害,有宝宝的家庭,选购驱蚊产品要注意
scroll-view指定滚动元素的起始位置
(翻译)异步编程:Async/Await在ASP.NET中的介绍
Cesium entity (entities) entity deletion method