当前位置:网站首页>Distributed common interview questions
Distributed common interview questions
2022-06-23 09:41:00 【Linging_ twenty-four】
1. How to prevent form from submitting repeatedly
- front end . Wait after each click X Seconds to click .
- Add a unique index to the database
- When the server returns to the form page , Mr. Hui becomes a subToken Keep in session or redis, When the form is submitted, carry token, If token Agreement , Follow up , And send the... In the server token Delete . If token non-existent , Then it indicates that it is a duplicate submission .
2. How to design a seckill system
front end .
Before the second kill , Button gray , The front-end request does not give the real address . Front end timing request back-end interface , If it's second kill time , Then return to the real address of the front end , Front release button , Wait after each click XX Seconds to click .The server : The service is used nginx Clustering 、redis Also do cluster
Current limiting : Before the second kill , Store the number of second kill tokens in redis in , It can be used list, Every time you ask, go redis Take out the token from , If you get it, it means that the second kill is successful , Then go to the database and place an order , If not , It means that the goods are sold out .
Message middleware . If the number of second kills is large , For example, tens of thousands , After the second kill is successful , Put successful requests into mq perhaps kafka Middleware , Then get the request from the message queue .
service degradation . Just in case , We still need to do service degradation .
3. Interface idempotent design of distributed system
- only id. Every operation , Both generate unique information based on actions and content id, Judge before execution id Whether there is , If not, follow up , And save to the database or redis etc. .
- The server provides sending token The interface of , Get before calling the service interface token, Then call the business interface request. , hold token Carry the past , Server judgment token Whether there is redis in , Presence indicates first request , You can continue to do business , After the completion of the business , Finally, we need to redis Medium token Delete .
- Create de duplication table . Save the uniquely identified fields in the business to the de duplication table , If... Exists in the table , It means it has been processed
- version control . Add version number , When the version number matches , To update the data .
- State control . For example, the order has status : Paid 、 Did not pay 、 In the payment 、 Failure to pay , It can be modified to medium payment only when it is in unpaid status .
4. Manage distributed session Four ways of ( Single sign on )
session Copy
Application server on Web Container of Session Copy function , Synchronization between several servers in the cluster Session object .The plan is simple , And read from this machine session It's also pretty quick , But there are very obvious defects : It can only be used when the cluster size is relatively small ( Enterprise application system , Few users , This pattern is relatively common ), When the cluster scale is large , Cluster servers need a lot of communication Session Copy , Take up a lot of resources from servers and networks , The system is heavily burdened . And because of the user's session Information is backed up on every server , Under a large number of user visits , There may be insufficient server memory session Usage .
session Conversation retention
Session persistence is using the original address of load balancing Hash Algorithm implementation , Load balancing servers will always come from the same IP The requests for are distributed to the same server .Although this scheme ensures that every user can get their own session, And a lot of users are not afraid to visit , But this session keeping does not meet the needs of high availability of the system . This scheme has a fatal flaw : Once a server goes down , All on this server session Information doesn't exist , The user requests to switch to another server , And other servers don't have their corresponding session Information makes it impossible to complete related business . So this approach is basically not going to be adopted .
cookie Record
take session perhaps token Record on the client side , Every time the server is requested, it will session perhaps token Send it to the server in the request , The server can verify whether to log in .utilize cookie Record session There are many shortcomings : such as cookie There is a limit to the size of information that can be recorded ; For example, every request must be transmitted cookie Affect performance ; such as cookie It can be modified or cracked , Lead to cookie Don't store important information , The safety factor is not enough . But because of cookie Simple and easy to use , Supports linear scaling of servers , And most of it session The information is relatively small , So in fact, many websites will use more or less cookie To record some of the unimportant session Information .
session share
Use redis Save all of the system session,redis As a storage center , Multiple machines of the distributed system can be shared , When requested , Go to redis To find out if there is session, You can determine whether the user logs in .This method is applicable to redis High availability of , Need to build redis colony .
5. How to guarantee the order of request execution
Generally speaking , In terms of business logic, it is best to design the system without the guarantee of this order , Because once the sequential guarantee is introduced , It will lead to the increase of system complexity , Efficiency will be reduced , There will be too much pressure on hot data .
First use consistency hash Load balancing strategy , Will be the same id All requests are distributed to the same machine for processing , For example, an order can be made according to the order id. If the processing machine is multithreaded , Memory queues can be introduced to process , Will be the same id The request was passed hash To the same queue , A queue only corresponds to one processing thread .
It is best to combine multiple operations into one operation .
————————————————
Copyright notice : This paper is about CSDN Blogger 「 A cat called a dog 」 The original article of , follow CC 4.0 BY-SA Copyright agreement , For reprint, please attach the original source link and this statement .
Link to the original text :https://blog.csdn.net/zgsxhdzxl/article/details/104414475
边栏推荐
- 云原生数据库-Amazon RDS
- 也无风雨也无晴
- Cesium loading orthophoto scheme
- Sun Tower Technology recruits PostgreSQL Database Engineer
- Three methods to find the limit of univariate function -- lobida's rule and Taylor's formula
- 12个球,有一个与其他不一样,提供一个天平,三次找出来
- Sequential representation and implementation of sequencelist -- linear structure
- Redis learning notes - client communication protocol resp
- Leetcode topic analysis contains duplicate II
- Redis learning notes - AOF of persistence mechanism
猜你喜欢
![[GXYCTF2019]BabyUpload](/img/82/7941edd523d86f7634f5532ab97717.png)
[GXYCTF2019]BabyUpload

微信小程序:点击按钮频繁切换,重叠自定义markers,但是值不改变

Set the CPU to have 16 address lines and 8 data lines, and use mreq as the access control line number Connection between memory and CPU

Ionic5 form input box and radio button
Redis learning notes - data type: string (string)

What is BFC? What problems can BFC solve
![[MRCTF2020]Ez_bypass](/img/cd/bd6fe5dfc3f1942a9959a9dab9e7e0.png)
[MRCTF2020]Ez_bypass

Redis learning notes RDB of persistence mechanism

Aiming at the overseas pet market, "grasshand" has developed an intelligent tracking product independent of mobile phones | early project

Redis学习笔记—客户端通讯协议RESP
随机推荐
Implementation of s5p4418 bare metal programming (replace 2ndboot)
JSP getting started summary
Redis learning notes - publish and subscribe
Thin film interference data processing
[极客大挑战 2019]HardSQL
Redis learning notes - single key management
利用华为云ECS服务器搭建安防视频监控平台
Redis learning notes - AOF of persistence mechanism
Redis learning notes - geographic information location (GEO)
Redis learning notes - redis cli explanation
Redis学习笔记—数据类型:有序集合(zset)
Redis学习笔记—客户端通讯协议RESP
Zone d'entrée du formulaire ionic5 et boutons radio
[plugin:vite:import-analysis]Failed to resolve import “@/“ from ““.Does the file exist
Form repeated submission problem
Redis learning notes - traverse key
[GXYCTF2019]BabyUpload
Neither rain nor sunshine
Jump game of leetcode topic analysis
16. system startup process