当前位置:网站首页>Is there anyone who plans to open source an industrial "seckill" system architecture?
Is there anyone who plans to open source an industrial "seckill" system architecture?
2022-06-23 09:46:00 【58 Shen Jian】
Want to figure out a set of architectural solutions , The most fundamental way , Is to go practice it .
But , Most programmers , There is no such business , I can't touch such a scene , What shall I do? ?
A friend set up a set automatically , can Let everyone instantly experience and tune the seckill architecture with high concurrency , Share with you !
For seckill business , On the system How can it be optimized ?
In the direction of , There are two main points :
First of all , Try to intercept the request upstream of the system , Don't let lock conflicts fall on the database .
The reason why the traditional seckill system hangs , It's because the requests are pushed to the back-end data layer , Data read-write lock conflict is serious , High concurrency and slow response , Almost all requests time out , High traffic , The effective flow of successful orders is small .
second , Make the most of the cache .
Second kill buy tickets , This is a typical business scenario with more reading and less writing :
(1) Train number inquiry , read , Large amount of ;
(2) Check the remaining tickets , read , Large amount of ;
(3) Order and pay , Write , Small quantity ;
Great for using caching to optimize .
Second kill business , How about the common system layered architecture ?

Second kill business , You can use a typical service layered architecture , How should these four layers be optimized ?
One 、 Request interception on end
JS level , You can restrict users to x Only one request can be submitted in seconds , So as to reduce the system load .
Voice over : Submit frequently , Friendly tips “ The frequency is too fast ”.
APP level , You can do something similar , Although users are crazily shaking wechat to grab red packets , But in fact x Seconds to send a request back .
Voice over : That's what's called “ Try to intercept the request upstream of the system ”, browser /APP Layer can intercept 80%+ Request .
Two 、 Site level request interception
How to resist programmers writing for Cycle call http Interface , The first thing to do is to identify the unique identity of the user , Block frequent users .
What to use as the unique identification of users ?
All ticket businesses need to log in , use uid Can identify users .
At the site level , To the same uid Request count and speed limit , for example : One uid,5 Seconds only pass through 1 A request , This will stop 99% Of for Loop request .
One uid,5s Only through a request , What about the rest of the requests ?
cache , Page caching ,5 Other requests to the site layer within seconds , All return to the last page .
3、 ... and 、 Request interception of service layer
Concurrent requests have reached the service level , How to intercept ?
The service level is very clear about the inventory of the business , Very clear about the database's ability to withstand pressure , According to these two, we can cut the peak and speed limit .
for example , Business services know very well , A train has nothing but 2000 Tickets , At this time, transmission through 10w Request to database , It doesn't make sense .
Voice over : If the database can only resist 500 Write a request , Just pass through 500 individual .
With what to cut the peak ?
Request queue .
For write requests , Make a request queue , Only a limited number of write requests are transmitted to the data layer at a time ( Place the order , Pay for writing business like this ).
Only 2000 Train tickets , Even if 10w Please come here , Only through transmission 2000 Go to the database :
(1) If all previous requests are successful , Put down another batch of ;
(2) If the previous request is out of stock , Then all subsequent requests return “ It's sold out ”;
For read requests , How to optimize the ?
cache resist , Whether it's memcached still redis, Single machine anti per second 10w There should be no problem .
Voice over : Expand the cache horizontally , It's easy to expand linearly .
Such peak clipping and current limiting , There are very few requests to write , And very little read caching mis The request will penetrate to the data layer , And then there is 99% Our request was stopped .
Four 、 Database layer
After the first three layers of optimization :
(1) The browser blocked 80% request ;
(2) The site layer intercepted 99% request , And do page caching ;
(3) Service layer according to business inventory , And the database's ability to withstand pressure , Write request queue and data cache are done ;
You'll find that , Every request that penetrates to the database layer is controllable .db Basically there's no pressure , walk .
Voice over : This kind of business data volume is not large , There's no need for sub Treasury , Make a highly available database .
According to the optimization scheme above , In fact, the most pressure is the site layer , Suppose that the number of real valid requests is... Per second 100w, How to deal with this part of the pressure ?
There are two ways to solve this problem :
(1) Site level expansion , Expand capacity by adding machines , A resistance 5W,20 It's done ;
(2) service degradation , Abandon the request , For example, abandon 50%;
The principle is to protect the system , Can't let all users fail .
How to experience the seckill business , Build a set of micro service layered seckill system architecture ?
(1) First , Buy hardware resources on the cloud ;
(2) next , Build the underlying foundation components : The storage system (MySQL、MongoDB、TiDB etc. )、 High performance cache system (Redis etc. )、 Highly reliable message system (RocketMQ、Kafka、Pulsar etc. )、 Search engine system (Elasticsearch、Solr etc. ) And many other basic components ;
(3) The third step , Build a microservice management platform :Docker Containers 、Kubernetes Management platform and other highly concurrent flexible container management platforms 、CI/CD And so on ;
(4) Step four , Build a micro service layered architecture : Low code microservice seckill business architecture design 、 Code landing 、 Test verification ;
(5) Step five , Optimize the three high design : Implement high performance 、 High availability 、 High reliability and other design guarantees , Ensure the robustness of seckill system ;
(6) Last , Set up a visual performance management background : It is convenient to see the throughput of the whole link of the system through three-dimensional and multi-dimensional visualization , Flow ;
Voice over : Put aside hundreds of thousands of machine costs , The whole stack 20 People build teams , One year can almost build a prototype .
Is there a quick way to experience ?
In order to make more children's shoes experience quickly “ seckill ” System architecture , My friend @ Xuanjie Founded Naixue , And lead the team through 2 Years of research and development , Created an exclusive set , Industrial grade “ Second kill architecture ” laboratory , It integrates all the above functions , The user only needs to open a web page , You can experience and code tuning “ Second kill architecture ”:
(1) left : Spike architecture knowledge points ;
(2) On the right side :terminal Direct connection server , Can operate ng,web-server,service etc. , You can modify the code directly , Tune the architecture ;
(3) meanwhile : There is also the background to manage the architecture , And visual monitoring .
Voice over : Details are shown below .

Figure 1 : left - Architecture diagram , On the right side - Practice environment

Figure 2 : left - Operation instructions , On the right side - One click automation architecture , Check the log

Figure 3 : left - Architecture description , On the right side - View and modify the code
Figure 4 : Visualization platform
How to apply for experience ?

1 Meta scan code , Apply for the experience now , Only 100 Accounts
1 Meta scan code , Apply for the experience now .
meanwhile , Free gift :
(1)6.27-6.29, Explanation of secsha core architecture ;
(2) Industrial grade “ Second kill architecture ” Introduction to laboratory functions ;
(3) Source code and courseware ;
Explain , Due to engineering grade “ Second kill architecture ” The server resources required are large , Limited account , Front only 100 people .
Read the original , Get involved right now , Pro automatic handwriting code optimization , Actual industrial grade “ Second kill architecture ”.
边栏推荐
- Correspondence between three-tier architecture and SSM
- 有没有人,计划开源一套工业级“秒杀”系统架构?
- Redis learning notes - redis cli explanation
- Playing with nanopi 2 bare metal tutorial programming-01 lighting user led difficulty analysis
- Jog sport mode
- 正则表达式
- Typora set up image upload service
- 2022 Gdevops全球敏捷运维峰会-广州站精华回放(附ppt下载)
- Redis learning notes master-slave copy
- Redis learning notes - redis and Lua
猜你喜欢
随机推荐
AI system frontier dynamics issue 38: Google has abandoned tensorflow?; Four GPU parallel strategies for training large models; Father of llvm: modular design determines AI future
[GYCTF2020]Blacklist
【CTF】 2018_rop
Subscript operator of map
正则表达式
mysql中innodb下的redo log什么时候开始执行check point落盘的?
什么是闭包函数
#gStore-weekly | gStore源码解析(四):安全机制之黑白名单配置解析
Go 单元测试
Go 字符串比较
Correspondence between three-tier architecture and SSM
Redis learning notes - data type: hash
UEFI 源码学习4.1 - PciHostBridgeDxe
cooding代码库的使用笔记
[SUCTF 2019]CheckIn
Alimentation des animaux de compagnie basée sur stm32
[geek challenge 2019] hardsql
XML related interview questions
mysql乐观锁与悲观锁
Thin film interference data processing
![[GXYCTF2019]BabySQli](/img/51/a866a170dd6c0160ce98d553333624.png)




![[MRCTF2020]Ez_bypass](/img/cd/bd6fe5dfc3f1942a9959a9dab9e7e0.png)

![[网鼎杯 2020 青龙组]AreUSerialz](/img/38/b67f7a42abec1cdaad02f2b7df6546.png)