System design must be one of the most frustrating things in an interview. Because system design-related questions are often open-ended, there is no standard answer. You will refine your system design as you interact with the interviewer’s ideas. In theory, the system design interview is also a process of working with the interviewer to improve the original system design proposal step by step.

System design questions are often very able to investigate the comprehensive ability of the interviewer, good answers, it is easy to stand out in the interview. Whether it is to participate in the club or the school of small partners, it is necessary to pay attention to.

Next, I will take my friends to talk about how to prepare for the system design part of the interview from my perspective.

Due to the limited space of this article, I will not list practical examples. Some specific examples may be mentioned separately in a later article.

Personal ability is limited. If there is any improvement or improvement in the article, please point it out in the comments section and make progress together!

System design interview general how to ask?

I briefly summarized the system design interview related questions to ask the method:

  1. Design a certain system such as second kill system, microblog system, red envelope system, short url system.
  2. Design a function in the system such as bilibili like the function.
  3. Design a framework such as RPC framework, message queue, caching framework, distributed file system, etc.
  4. The technology selection of such and such system is used for cachingRedisorMemcached, gateway to useSpring Cloud Gatewayor Netflix Zuul2

How do you design the system?

We’ve boiled this down to the following four steps.

Step1: ask the specific requirements of the system

When the interviewer gives you a system design problem, don’t immediately start designing solutions. You need to understand the requirements of the system design: functional and non-functional.

To avoid misinterpreting what the question is asking for, you can give the interviewer a brief explanation of your understanding.

Why ask for the functional requirements of the system in other words what functionality does the system contain?

After all, if an interviewer asks you to design a twitter system out of the blue, you can’t list all the features that a twitter system has — like a recommendation stream or a membership mechanism — and then design it. You need to narrow down the core functionality that the system provides!

Why ask for non-functional requirements or constraints such as how many QPS the system needs to achieve?

Can you design a microblog system for 1W people be the same as a microblog system for 100W people? The system design scheme corresponding to different constraint systems must be different.

Step2: Abstract design of the system

We need to design the system at a High Level.

You can draw an abstract architecture diagram of the system, which contains the components of the system and the connections between them.

Step3: Consider the points that the system needs to be optimized at present

After abstracting the system, you need to think about what needs to be optimized in the current abstract system design. For example:

  1. Is the current system deployed on one machine enough? Do you need to deploy on multiple machines and then load balance?
  2. Can the database processing speed support the business requirements? Do YOU want to index the specified field? Do I need read/write separation? Do you need caching?
  3. Is the data volume large enough to require separate databases and tables?
  4. Are there security risks?
  5. Does the system require a distributed file system?
  6. .

Step4: optimize your system abstraction design

The abstract design of the system is further improved according to the “points that the system needs to be optimized” in Step 3.

How should the system design be prepared?

Knowledge reserves

The system design interview examines your knowledge reserve very much, the improvement of system design ability needs a lot of theoretical knowledge reserve. For example, if you want to know the necessary three boards for large website architecture design:

  1. High performance architecture design: Familiar with common system performance optimization methods such as the introduction of read/write separation, caching, load balancing, asynchronous, etc.
  2. High availability architecture design: CAP theory and BASE theory, improving overall system stability through clustering, timeout and retry mechanism, coping with interface level faults: degradation, fusing, traffic limiting, queuing.
  3. High scale architecture design: Basically, knowing how to break systems apart. You break up software systems in different ways, and you get different architectures.

In actual combat

Although understand the theory, but their own practice, a lot of things can not be realized!

Therefore, you need to constantly practice your system design skills through field projects.

Be curious

Think about how the sites you visit often are done. Such as:

  1. When you check your Micro blog, think about how the micro blog keeps track of the number of likes.
  2. While you’re watching Bilibili, can you think about how the message alert system works?
  3. When you use a short chain system you can think about how does a short chain system work?
  4. .

Technology selection

There are many technical options to implement the same functionality, such as Redis versus Memcached for cache, Spring Cloud Gateway versus Netflix Zuul2 for Gateway. Many times, the interviewer will be specific about the technology selection during the system design process, so you need to distinguish the advantages and disadvantages of different technologies.

System design interview must know

Systems must be designed to describe performance related metrics such as QPS.

Performance related indicators

The response time

Response time (RT) is the time between a user sending a request and receiving the system processing result.

RT is a very important and intuitive index. The value of RT directly reflects the speed of the system to process user requests.

concurrency

Concurrency can be simply defined as how many people can access the system at the same time, i.e. the number of requests the system can handle at the same time.

Concurrency reflects the load capacity of the system.

QPS and TPS

  • Query Per Second (QPS) : indicates the number of queries that a server can execute Per Second.
  • TPS (Transaction Per Second) : the number of transactions processed by the server Per Second.

This is how the book describes the difference between QPS and TPS.

QPS vs TPS: QPS is basically similar to TPS, except that one visit to a page forms a TPS; However, a page request may result in multiple requests to the server, and the server can count these requests into the “QPS”. For example, accessing a page will request the server twice, and one visit will generate a “T” and two “Q”.

throughput

Throughput refers to the number of requests processed by the system per unit of time.

The throughput of a system is closely related to the resource consumption of the system by requests. The more requests consume system resources, the lower the system throughput, and vice versa.

TPS and QPS are commonly used quantitative indicators of throughput.

  • QPS (TPS) = Number of concurrent requests/Average response time (RT)
  • Concurrency = QPS * Average response time (RT)

System activity

Here are some common terms to describe system activity that you should keep in mind. It’s not just when you’re answering system design interview questions, you’ll often come across these terms in your everyday job.

PV(Page View)

Page views, or clicks, measure the number of pages a site’s users visit; Within a certain statistical period, the user will open or refresh a page for 1 time, and open or refresh the same page for many times will accumulate the page views. UV is measured in terms of the number of pages opened/refreshed.

UV(Unique Visitor)

Independent visitors: collects statistics on the number of users who access a site within one day. If the same visitor visits the site more than once within a day, only one unique visitor will be counted. UV is calculated from the perspective of individual users.

DAU(Daily Active User)

Number of daily active users.

MAU(monthly active users)

Number of monthly active users.

For example, a website with a DAU of 1200W, an average daily usage time of 1 hour, and RT of 0.5s are calculated as the concurrency and QPS.

Average number of concurrent users = DAU (1200W) x Daily usage duration (1 hour, 3600 seconds)/number of seconds per day (86400) = 1200W /24 = 50W

Actual number of concurrent users (considering the low number of users in certain periods) = DAU (1200W) * Daily usage duration (1 hour, 3600 seconds)/seconds of a day – Assume that the time period with low traffic is 8 hours (57600) = 1200W /16 = 75W

Peak concurrency = average concurrency * 6 = 300w

QPS = actual concurrency /RT = 75W/0.5=100w/s

Common performance testing tools

The back-end commonly used

Since system design involves performance issues, it is likely that during the interview, the interviewer will ask: How did you perform performance testing?

Four commonly used performance testing tools are recommended:

  1. Jmeter: Apache Jmeter is a performance testing tool developed in JAVA.
  2. LoadRunner: A commercial performance testing tool.
  3. Galtling: A high-performance server performance testing tool developed in Scala.
  4. Ab: Apache Bench. Apache under a test tool, very practical.

If MEMORY serves, LoadRunner is an open source and free performance testing tool.

The front-end commonly used

  1. Fiddler: a packet capture tool that modifies requested data and even the data returned by the server. It is a powerful tool for Web debugging.
  2. HttpWatch: A tool that can be used to record HTTP request information.

QPS for common software

The QPS given here is for reference only, and the actual project needs to be calculated by pressure measurement.

  • Nginx: In general, the performance bottleneck of a system is rarely Nginx. Stand-alone Nginx can reach 30W +.
  • Redis: Redis official Performance test report: Redis. IO /topics/benc… . From the report, we can conclude that the single-machine QPS of Redis can reach 8W + (it is related to the CPU performance and the command executed, for example, the SET command can even reach 10W +QPS).
  • MySQL: QPS for MySQL standalone is around 4K.
  • Tomcat: QPS of stand-alone Tomcat is about 2W. This depends a lot on your Tomcat configuration. For example, Tomcat supports connectorsNIO,NIO.2APR.AprEndpointIs through JNI call APR local library to achieve non-blocking I/O, better performance, Tomcat configuration APR connector, QPS can reach about 3W. You can search for more information about Tomcat performance tuning.

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 each link of the request experience, identify possible performance bottlenecks and locate problems.

Here are some of the questions I often ask myself when tuning performance:

  1. Is there a problem with SQL statements in the current system?
  2. Do you need to upgrade the system hardware?
  3. Does the system need caching?
  4. Is there a problem with the system architecture itself?
  5. Are there deadlocks in the system?
  6. Is database index usage reasonable?
  7. Is there a memory leak in the system? (Java’s auto-reclaim memory is convenient, but sometimes poorly written code can cause memory leaks.)
  8. Are time-consuming operations of the system processed asynchronously?

Performance optimization must know the rules

SQL optimization, JVM, DB, Tomcat parameter tuning > Hardware performance optimization (memory upgrade, CPU core number increase, mechanical disk – > SSD, etc.) > business logic optimization/cache > read/write separation, cluster, etc. > sub-library sub-table

System design interview considerations

To:…

There’s no need to start answering questions when you’re not ready. This will not impress the interviewer! The system design originally requires the interviewees to combine their previous experience to think, this process is to take some time.

There are no absolute answers

There is no standard answer to system design. What matters is how you communicate with the interviewer.

Typically, you will complete the system design step by step during the conversation with the interviewer. In this process, you will continue to improve your system design under the guidance of the interviewer.

As a result, you don’t have to pick up a lot of questions before the system design interview and just memorize their answers.

Don’t want to absolute

System design there is no best design scheme, only the most appropriate design scheme. This is analogous to architectural design: there is no silver bullet in software development; the goal of architectural design is to choose the right solution. What is a silver bullet? According to werewolf legend, only silver bullets can subdue these beasts. In software development, the silver bullet refers specifically to a “master key” that developers seek to overcome the formidable beast of software development 🔑.

Weigh the pros and cons

Know the pros and cons that using a technology might bring to the system. The benefits of using message queues, for example, are decoupling and peak peaking, but they also lead to less availability, more complexity, and consistency issues (whether messages are lost or not consumed).

Slowly optimization

You don’t have to design a perfect system from the beginning, you can refine it over time.

Don’t chase new technology

Use technology that is stable and business-appropriate, not necessarily new.

After Jane to avoid noise

System design should strive for simplicity and avoid complexity. KISS (Keep It Simple, Stupid) — Keep It Simple and easy to understand.

conclusion

This article briefly analyzes the system design interview with friends. If you still want to learn more, you can check out github.com/donnemartin… .

reference

  1. Github.com/donnemartin…
  2. www.acecodeinterview.com/intro/
  3. Gist.github.com/vasanthk/48…

WeChat search”JavaGuide“Reply”Computer Fundamentals“To get the illustrated Computer Basics + personal original Java interview Manual.