当前位置:网站首页>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 :

  1. Design a certain system, such as the second kill system 、 Microblog system 、 Grab the red envelope system 、 Short URL system .
  2. Design a function of XX system, such as Bili Bili like function .
  3. Design a framework like RPC frame 、 Message queue 、 Caching framework 、 Distributed file systems and so on .
  4. Technology selection of XX system, such as cache Redis still Memcached、 Gateway uses Spring Cloud Gateway still Netflix 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 :

  1. Is it enough to deploy the current system on one machine ? Is it necessary to deploy on multiple machines and load balance ?
  2. 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 ?
  3. Whether the amount of data is large enough to need sub database and sub table ?
  4. Is there any potential safety hazard ?
  5. Does the system need a distributed file system ?
  6. ......

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 :

  1. High performance architecture design : Familiar with common performance optimization methods, such as introducing Read / write separation cache 、 Load balancing 、 asynchronous wait .
  2. 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 .
  3. 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 :

  1. When you brush microblogs, you can think about how microblogs record the number of likes ?
  2. When you look at Bili Bili, you can think about how the message alert system works ?
  3. When you use the short chain system, you can consider how the short chain system works ?
  4. ......

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 :

  1. Jmeter :Apache JMeter yes JAVA Developed performance testing tools .
  2. LoadRunner: A commercial performance testing tool .
  3. Galtling : Based on a Scala The development of high-performance server performance testing tools .
  4. 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

  1. 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 .
  2. 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 NIONIO.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 :

  1. Of the current system SQL Whether there is a problem with the statement ?
  2. Whether the current system needs to upgrade hardware ?
  3. Whether the system needs cache ?
  4. Is there something wrong with the system architecture itself ?
  5. Whether there is a deadlock in the system ?
  6. Whether the use of database index is reasonable ?
  7. 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 )
  8. The time-consuming operation of the system is processed asynchronously ?
  9. ……

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

  1. https://github.com/donnemartin/system-design-primer
  2. https://www.acecodeinterview.com/intro/
  3. 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]所创,转载请带上原文链接,感谢