当前位置:网站首页>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
边栏推荐
猜你喜欢
[nanopi2 trial experience] the first step of bare metal
Redis learning notes - publish and subscribe
Redis learning notes pipeline

云原生数据库-Amazon RDS

Gesture recognition based on mediapipe
![[极客大挑战 2019]HardSQL](/img/73/ebfb410296b8e950c9ac0cf00adc17.png)
[极客大挑战 2019]HardSQL

基于mediapipe的手势数字识别
![[極客大挑戰 2019]HardSQL](/img/73/ebfb410296b8e950c9ac0cf00adc17.png)
[極客大挑戰 2019]HardSQL

Use Base64 to show pictures

Bioinformatics | 基于相互作用神经网络的有效药物-靶标关联预测
随机推荐
Mysql database introduction summary
[网鼎杯 2020 青龙组]AreUSerialz
Redis learning notes RDB of persistence mechanism
Gstore weekly gstore source code analysis (IV): black and white list configuration analysis of security mechanism
Redis learning notes pipeline
[SUCTF 2019]CheckIn
我被提拔了,怎么和原来平级的同事相处?
web--信息泄漏
快速排序的简单理解
2022 gdevops global agile operation and maintenance summit - essence playback of Guangzhou station (with PPT download)
Redis learning notes master-slave copy
高性能算力中心 — NVMe/NVMe-oF — NVMe-oF Overview
ionic5錶單輸入框和單選按鈕
Redis learning notes - data type: ordered set (Zset)
Bioinformatics | 基于相互作用神经网络的有效药物-靶标关联预测
Redis学习笔记—数据类型:哈希(hash)
安装typescript环境并开启VSCode自动监视编译ts文件为js文件
Cesium loading orthophoto scheme
【CTF】bjdctf_ 2020_ babyrop
Jump game of leetcode topic analysis