当前位置:网站首页>How to prepare for the system design interview
How to prepare for the system design interview
2020-11-06 21:04:00 【Jawajid】
System design in the interview must be one of the most troublesome things for the interviewer . Because the problems associated with system design are usually open , So there's no standard answer . You will gradually optimize your system design in the communication and collision of ideas with the interviewer . In theory , System design interview is also the process of improving the original system design scheme step by step with the interviewer .
System design questions can also be used to examine the comprehensive ability of the interviewer , If you answer well , It's easy to stand out in an interview . Whether it is for the students who participate in social recruitment or school recruitment , It is necessary to pay attention to it .
Next , I'll take my friends and talk from my point of view : How to prepare for the system design part of an interview .
Because of the limited space of the article , Let's not list the actual examples , Some specific examples may be mentioned separately in the following articles .
Limited personal ability . If there is anything in the article that needs to be improved and perfected , Welcome to the comment area , Common progress !
System design interview how to ask ?
I've briefly summed up the system design interview related questions :
- Design a certain system, such as the second kill system 、 Microblog system 、 Grab the red envelope system 、 Short URL system .
- Design a function of XX system, such as Bili Bili like function .
- Design a framework like RPC frame 、 Message queue 、 Caching framework 、 Distributed file systems and so on .
- Technology selection of XX system, such as cache
Redis
stillMemcached
、 Gateway usesSpring Cloud Gateway
stillNetflix Zuul2
.
How to design the system ?
We summarize the steps as follows 4 Step .
Step1: Ask for specific system requirements
When the interviewer gives the system design question , Never start designing solutions immediately . You need to understand the requirements of the system design first : Functional and non functional requirements .
In order to avoid misinterpreting the problem you want to solve , You can start by briefly explaining your understanding to the interviewer ,
Why ask about the functional requirements of the system, that is, what functions are included in the system ?
After all , If the interviewer simply asks you to design a microblog system , You can't cover the functions of microblog system, such as recommendation information flow 、 The membership mechanisms are listed one by one , And then design ! You need to filter out the core functions that the system provides ( Narrow the boundaries )!
Why ask about the non functional requirements or constraints of the system, such as how much the system needs to achieve QPS Well ?
Let you design a 1w Micro blog system for people and 100w Can people use the same microblog system ? Different constraint systems have different design schemes .
Step2: Abstract design of the system
We need to be in a High Level To design the system .
You can draw the abstract architecture of the system , This abstract architecture diagram contains some components of the system and the connections between these components .
Step3: Consider the points that need to be optimized at present
After the abstract design of the system , You need to think about the current abstract system design which needs to be optimized , for instance :
- Is it enough to deploy the current system on one machine ? Is it necessary to deploy on multiple machines and load balance ?
- Can database processing speed support business requirements ? Whether the specified field needs to be indexed ? Is it necessary to separate reading from writing ? Whether cache is needed ?
- Whether the amount of data is large enough to need sub database and sub table ?
- Is there any potential safety hazard ?
- Does the system need a distributed file system ?
- ......
Step4: Optimize the abstract design of your system
according to Step 3 Medium “ Where the system needs to be optimized ” Further improve the abstract design of the system .
How to prepare for system design ?
Knowledge reserve
System design interview is a great way to examine your knowledge base , The improvement of system design ability needs a lot of theoretical knowledge . For example, you need to know the three axes necessary for large-scale website architecture design :
- High performance architecture design : Familiar with common performance optimization methods, such as introducing Read / write separation 、 cache 、 Load balancing 、 asynchronous wait .
- High availability architecture design :CAP Theory and BASE theory 、 Improve the overall stability of the system through clustering 、 Timeout and retry mechanisms 、 Dealing with interface level failures : Downgrade 、 Fuse 、 Current limiting 、 line up .
- High scalability architecture design : To put it bluntly, it is to know how to split the system . You split software systems in different ways , You'll get a different architecture .
actual combat
Although I understand the theory , But if you don't practice it yourself , A lot of things can't be realized !
therefore , You need more Constantly exercise their system design ability through actual combat projects .
Be curious
Think about how the websites you often visit are done . such as :
- When you brush microblogs, you can think about how microblogs record the number of likes ?
- When you look at Bili Bili, you can think about how the message alert system works ?
- When you use the short chain system, you can consider how the short chain system works ?
- ......
Technology selection
Implement the same functionality , There are usually multiple technology options , For example, cache uses Redis
still Memcached
、 Gateway uses Spring Cloud Gateway
still Netflix Zuul2
. A lot of times , In the process of system design, the interviewer will be specific to the selection of technology , thus , You need to distinguish between the pros and cons of different technologies .
System design interview must know
When designing a system, it is necessary to describe performance related indicators such as QPS.
Performance related indicators
response time
response time RT(Response-time) It is the time that the user sends out the request to the user to receive the processing result of the system .
RT Is a very important and intuitive indicator ,RT The numerical value directly reflects the speed of processing user requests .
Concurrency number
Concurrency number can be simply understood as how many people can access the system at the same time, that is to say, the number of requests that the system can handle at the same time .
The concurrency number reflects the load capacity of the system .
QPS and TPS
- QPS(Query Per Second) : The number of queries the server can execute per second ;
- TPS(Transaction Per Second) : The number of transactions processed by the server per second ( A transaction here can be understood as the process from a client sending a request to receiving a server );
The book describes QPS and TPS Different from .
QPS vs TPS:QPS It's basically like TPS, But here's the difference , A visit to a page , To form a TPS; But a page request , There may be multiple requests to the server , The server requests for these , You can count in “QPS” In . Such as , Visiting a page will request the server 2 Time , A visit , Produce a “T”, produce 2 individual “Q”.
throughput
Throughput refers to the number of requests processed by the system per unit time .
The throughput of a system is closely related to the resource consumption of requests to the system . The more requests consume system resources , Lower system throughput , On the contrary, the higher .
TPS、QPS They are all commonly used quantitative indicators of throughput .
- QPS(TPS) = Concurrency number / Mean response time (RT)
- Concurrency number = QPS * Mean response time (RT)
System activity
This paper introduces several common terms used to describe system activity , It is suggested to keep in mind . You're not only going to come across , You will often come across these nouns in your daily work .
PV(Page View)
Traffic volume , Page views or clicks , Measure the number of pages visited by website users ; Every time a user opens or refreshes a page in a certain statistical cycle, they will record 1 Time , If the same page is opened or refreshed multiple times, the total number of views will be accumulated .UV Number of opens from the web page / The number of times to refresh the angle of statistics .
UV(Unique Visitor)
Independent visitor , Statistics 1 Number of users visiting a site in days .1 The same visitor visited the website many times during the day , Only calculated as 1 An independent visitor .UV From the perspective of individual users .
DAU(Daily Active User)
Number of daily active users .
MAU(monthly active users)
Number of monthly active users .
give an example : A website DAU by 1200w, Average daily use time of users 1 Hours ,RT by 0.5s, Find concurrency and QPS.
Average concurrency = DAU(1200w)* Average daily usage time (1 Hours ,3600 second ) / The number of seconds in a day (86400)=1200w/24 = 50w
Real concurrency ( Considering that the number of users is relatively small in some time periods ) = DAU(1200w)* Average daily usage time (1 Hours ,3600 second ) / The number of seconds in a day - When the number of visits is relatively small, it is assumed that 8 Hours (57600)=1200w/16 = 75w
Peak concurrency = Average concurrency * 6 = 300w
QPS = Real concurrency /RT = 75W/0.5=100w/s
Common performance testing tools
The back end is often used
Since the system design involves the performance of the system , Then during the interview , The interviewer will probably ask : How do you test performance ?
recommend 4 A more commonly used performance testing tool :
- Jmeter :Apache JMeter yes JAVA Developed performance testing tools .
- LoadRunner: A commercial performance testing tool .
- Galtling : Based on a Scala The development of high-performance server performance testing tools .
- ab : Its full name is Apache Bench .Apache One of its testing tools , Very practical .
If I remember correctly , except LoadRunner Several other performance testing tools are open source and free .
The front end is often used
- Fiddler: Caught tools , It can modify the requested data , You can even modify the data returned by the server , Very powerful , yes Web A handy tool for debugging .
- HttpWatch: Can be used to record HTTP A tool for requesting information .
Common software QPS
What is given here QPS For reference only , The actual project needs pressure test to calculate .
- Nginx : In general , The performance bottleneck of the system will not be Nginx. stand-alone Nginx You can achieve 30w +.
- Redis: Redis Official performance test report :https://redis.io/topics/benchmarks . From the report , We can figure out Redis Stand alone QPS You can achieve 8w+(CPU Performance matters , It also has something to do with the order being executed, such as executing SET Orders can even achieve 10w+QPS).
- MySQL: MySQL Standalone QPS by In about 4k about .
- Tomcat : stand-alone Tomcat Of QPS stay 2w about . This and your Tomcat Configuration has a lot to do with , for instance Tomcat Supported connectors are NIO、NIO.2 and APR.
AprEndpoint
It's through JNI call APR Local library to achieve non blocking I/O Of , Better performance ,Tomcat To configure APR by If it's a connector ,QPS You can achieve 3w about . More relevant content can be searched by yourself Tomcat performance optimization .
System design principles
Appropriate is better than advanced > Evolution is better than one step > Simple is better than complex
Common performance optimization strategies
Before performance optimization, we need to analyze every link of the request , Identify potential performance bottlenecks , Location problem .
Here are some performance optimizations , Some of the questions I often ask myself :
- Of the current system SQL Whether there is a problem with the statement ?
- Whether the current system needs to upgrade hardware ?
- Whether the system needs cache ?
- Is there something wrong with the system architecture itself ?
- Whether there is a deadlock in the system ?
- Whether the use of database index is reasonable ?
- Whether there is a memory leak in the system ?(Java It's very convenient to recycle memory automatically , however , Sometimes bad code can really cause memory leaks )
- The time-consuming operation of the system is processed asynchronously ?
- ……
Performance optimization must know the law
SQL Optimize ,JVM、DB,Tomcat Parameter tuning > Hardware performance optimization ( Memory upgrade 、CPU The number of cores increases 、 Mechanical drive —> SSDs and so on )> Business logic optimization / cache > Read / write separation 、 Cluster etc. > Sub database and sub table
System design interview notes
Think about it
There's no need for the interviewer to ask questions , You're not ready to answer . It won't make a good impression on the interviewer ! The design of the system requires the interviewers to think based on their past experience , This process will take some time .
There is no absolute answer
There is no standard answer for system design . What matters is the process of communicating with the interviewer .
In general , You will be in the process of communicating with the interviewer , Complete the system design step by step . In the process , You will continue to improve your system design under the guidance of the interviewer .
therefore , You don't have to design a lot of questions before the interview , And then just remember their answers .
Don't be absolutely
There is no best design for system design , Only the most appropriate design . This is analogous to architecture design : There is no silver bullet in software development , The purpose of architecture design is to choose the right solution . What is a silver bullet ? In the legend of the werewolf , Only silver bullets ( Silver bullets ) To subdue these beasts . Corresponding to software development activities , Silver bullet refers to the kind of software developers are looking for to overcome the beast of software development “ Master key ”.
weigh the advantages and disadvantages
Know the pros and cons of using a technology for your system . For example, the benefits of using message queuing are decoupling and peak clipping , however , It also reduces system availability 、 Increased complexity , At the same time, there are consistency issues ( What to do if the message is lost or not consumed ).
Slowly optimize
The system you just designed doesn't need to be perfect , It can be optimized slowly .
Don't pursue new technology
Use stable 、 The right technology for the business , There's no need to pursue new technology too much .
Pursue simplicity and avoid miscellaneous things
System design should pursue simplicity and avoid complexity .KISS( Keep It Simple, Stupid) principle —— Keep it simple , Easy to understand .
summary
In this article, I take my friends to analyze the system design interview . If you want to learn more , You can refer to : https://github.com/donnemartin/system-design-primer .
Reference resources
- https://github.com/donnemartin/system-design-primer
- https://www.acecodeinterview.com/intro/
- https://gist.github.com/vasanthk/485d1c25737e8e72759f
Wechat search “JavaGuide” reply “ Fundamentals of computer ” You can get graphical computer basics + Personal original Java Interview manual .
版权声明
本文为[Jawajid]所创,转载请带上原文链接,感谢
边栏推荐
- ES6 learning notes (5): easy to understand ES6's built-in extension objects
- What are the common problems of DTU connection
- 消息队列(MessageQueue)-分析
- 递归、回溯算法常用数学基础公式
- StickEngine-架构11-消息队列(MessageQueue)
- Behind the first lane level navigation in the industry
- JVM内存分配 -Xms128m -Xmx512m -XX:PermSize=128m -XX:MaxPermSize=512m
- ERD-ONLINE 免费在线数据库建模工具
- 代码生成器插件与Creator预制体文件解析
- To teach you to easily understand the basic usage of Vue codemirror: mainly to achieve code editing, verification prompt, code formatting
猜你喜欢
An article will introduce you to HTML tables and their main attributes
An article will introduce you to CSS3 background knowledge
An article taught you to use HTML5 SVG tags
GitHub: the foundation of the front end
行为型模式之备忘录模式
Outsourcing is really difficult. As an outsourcer, I can't help sighing.
Share with Lianyun: is IPFs / filecoin worth investing in?
Basic usage of Vue codemirror: search function, code folding function, get editor value and verify in time
CCR coin frying robot: the boss of bitcoin digital currency, what you have to know
What are the criteria for selecting a cluster server?
随机推荐
GUI engine evaluation index
Live broadcast preview | micro service architecture Learning Series live broadcast phase 3
Elasticsearch Part 6: aggregate statistical query
What if the front end doesn't use spa? - Hacker News
统计项目代码行数
Basic usage of Vue codemirror: search function, code folding function, get editor value and verify in time
Zero basis to build a web search engine of its own
Details of dapr implementing distributed stateful service
检测证书过期脚本
行为型模式之备忘录模式
What are Devops
Application of restful API based on MVC
window系统 本机查找端口号占用方法
The legality of IPFs / filecoin: protecting personal privacy from disclosure
The method of realizing high SLO on large scale kubernetes cluster
What are the common problems of DTU connection
Introduction to the structure of PDF417 bar code system
StickEngine-架构11-消息队列(MessageQueue)
What knowledge do Python automated testing learn?
一路踩坑,被迫聊聊 C# 代码调试技巧和远程调试