编辑
2023-05-02
👨‍🎓 无限进步
00
请注意,本文编写于 779 天前,最后修改于 225 天前,其中某些信息可能已经过时。

目录

CHAPTER 3: A FRAMEWORK FOR SYSTEM DESIGN INTERVIEWS 系统设计访谈的框架
A 4-step process for effective system design interview 有效系统设计访谈的 4 步流程
Step 1 - Understand the problem and establish design scope 第 1 步 - 了解问题并建立设计范围
Example
Step 2 - Propose high-level design and get buy-in 第二步▁-▁提出高水平设计并获得认可
example(有点不太懂)
Design deep dive 深度设计
example
Step 4 - Wrap up 圆满完成
Time allocation on each step

CHAPTER 3: A FRAMEWORK FOR SYSTEM DESIGN INTERVIEWS 系统设计访谈的框架

You have just landed a coveted on-site interview at your dream company. The hiring coordinator sends you a schedule for that day. Scanning down the list, you feel pretty good about it until your eyes land on this interview session - System Design Interview. System design interviews are often intimidating. It could be as vague as “designing a wellknown product X?”. The questions are ambiguous and seem unreasonably broad. Your weariness is understandable. After all, how could anyone design a popular product in an hour that has taken hundreds if not thousands of engineers to build? 您刚刚在您梦想的公司获得了令人垂涎的现场面试。招聘协调员会向您发送当天的时间表。向下扫描列表,您对此感觉很好,直到您的眼睛落在这个面试环节 - 系统设计面试。 系统设计面试往往令人生畏。它可能像“设计一个知名的产品X?这些问题模棱两可,似乎不合理地宽泛。你的疲倦是可以理解的。毕竟,怎么可能在一小时内设计出一个受欢迎的产品,而这个产品需要数百甚至数千名工程师才能构建出来?
The good news is that no one expects you to. Real-world system design is extremely complicated. For example, Google search is deceptively simple; however, the amount of technology that underpins that simplicity is truly astonishing. If no one expects you to design a real-world system in an hour, what is the benefit of a system design interview? The system design interview simulates real-life problem solving where two co-workers collaborate on an ambiguous problem and come up with a solution that meets their goals. The problem is open-ended, and there is no perfect answer. The final design is less important compared to the work you put in the design process. This allows you to demonstrate your design skill, defend your design choices, and respond to feedback in a constructive manner. 好消息是没有人期望你这样做。现实世界的系统设计极其复杂。例如,Google 搜索看似简单;然而,支持这种简单性的技术数量确实令人惊讶。如果没有人期望您在一个小时内设计出一个真实世界的系统,那么系统设计面试有什么好处呢? 系统设计面试模拟现实生活中的问题解决,两个同事合作解决一个模棱两可的问题,并提出一个满足他们目标的解决方案。这个问题是开放式的,没有完美的答案。与您在设计过程中投入的工作相比,最终设计并不那么重要。这使您能够展示您的设计技能,捍卫您的设计选择,并以建设性的方式回应反馈。
Let us flip the table and consider what goes through the interviewer’s head as she walks into the conference room to meet you. The primary goal of the interviewer is to accurately assess your abilities. The last thing she wants is to give an inconclusive evaluation because the session has gone poorly and there are not enough signals. What is an interviewer looking for in a system design interview? Many think that system design interview is all about a person's technical design skills. It is much more than that. An effective system design interview gives strong signals about a person's ability to collaborate, to work under pressure, and to resolve ambiguity constructively. The ability to ask good questions is also an essential skill, and many interviewers specifically look for this skill. 让我们翻转桌子,考虑一下面试官走进会议室与您会面时脑子里在想什么。面试官的主要目标是准确评估您的能力。她最不想做的就是给出一个不确定的评估,因为会议进展不佳,没有足够的信号。面试官在系统设计面试中寻找什么? 许多人认为系统设计面试完全是关于一个人的技术设计技能。它远不止于此。有效的系统设计访谈会发出强烈的信号,表明一个人的协作能力、在压力下工作的能力以及建设性地解决歧义的能力。提出好问题的能力也是必不可少的技能,许多面试官专门寻找这项技能。
A good interviewer also looks for red flags. Over-engineering is a real disease of many engineers as they delight in design purity and ignore tradeoffs. They are often unaware of the compounding costs of over-engineered systems, and many companies pay a high price for that ignorance. You certainly do not want to demonstrate this tendency in a system design interview. Other red flags include narrow mindedness, stubbornness, etc. In this chapter, we will go over some useful tips and introduce a simple and effective framework to solve system design interview problems. 一个好的面试官也会寻找危险信号。过度工程是许多工程师的真正疾病,因为他们喜欢设计纯度而忽略权衡。他们往往没有意识到过度设计的系统的复合成本,许多公司为这种无知付出了高昂的代价。你当然不想在系统设计面试中展示这种倾向。其他危险信号包括心胸狭窄、固执等。 在本章中,我们将介绍一些有用的技巧,并介绍一个简单有效的框架来解决系统设计面试问题。

A 4-step process for effective system design interview 有效系统设计访谈的 4 步流程

Every system design interview is different. A great system design interview is open-ended and there is no one-size-fits-all solution. However, there are steps and common ground to cover in every system design interview. 每个系统设计面试都是不同的。一个伟大的系统设计面试是开放式的,没有一刀切的解决方案。但是,在每个系统设计面试中都有步骤和共同点需要涵盖。

Step 1 - Understand the problem and establish design scope 第 1 步 - 了解问题并建立设计范围

"Why did the tiger roar?" A hand shot up in the back of the class. "Yes, Jimmy?", the teacher responded. "Because he was HUNGRY". "Very good Jimmy." Throughout his childhood, Jimmy has always been the first to answer questions in the class. Whenever the teacher asks a question, there is always a kid in the classroom who loves to take a crack at the question, no matter if he knows the answer or not. That is Jimmy. Jimmy is an ace student. He takes pride in knowing all the answers fast. In exams, he is usually the first person to finish the questions. He is a teacher's top choice for any academic competition. “老虎为什么吼?” 一只手在教室后面伸了过来。 “是的,吉米?”老师回答道。 “因为他饿了”。 “很好,吉米。” 在他的整个童年时期,吉米一直是第一个在课堂上回答问题的人。每当老师问问题时,教室里总有一个孩子喜欢回答问题,无论他是否知道答案。那就是吉米。 吉米是一名王牌学生。他为快速知道所有答案而感到自豪。在考试中,他通常是第一个完成问题的人。他是任何学术竞赛的教师首选。
DON'T be like Jimmy. In a system design interview, giving out an answer quickly without thinking gives you no bonus points. Answering without a thorough understanding of the requirements is a huge red flag as the interview is not a trivia contest. There is no right answer. So, do not jump right in to give a solution. Slow down. Think deeply and ask questions to clarify requirements and assumptions. This is extremely important. 不要像吉米一样。 在系统设计面试中,不假思索地快速给出答案不会给你加分。在没有彻底了解要求的情况下回答是一个巨大的危险信号,因为面试不是琐事比赛。没有正确的答案。 因此,不要直接跳进去给出解决方案。慢点开。深入思考并提出问题以澄清要求和假设。这一点非常重要。
As an engineer, we like to solve hard problems and jump into the final design; however, this approach is likely to lead you to design the wrong system. One of the most important skills as an engineer is to ask the right questions, make the proper assumptions, and gather all the information needed to build a system. So, do not be afraid to ask questions. When you ask a question, the interviewer either answers your question directly or asks you to make your assumptions. If the latter happens, write down your assumptions on the whiteboard or paper. You might need them later. 作为一名工程师,我们喜欢解决难题并跳入最终设计;但是,这种方法可能会导致您设计错误的系统。作为一名工程师,最重要的技能之一是提出正确的问题,做出正确的假设,并收集构建系统所需的所有信息。所以,不要害怕问问题。 当你问一个问题时,面试官要么直接回答你的问题,要么要求你做出假设。如果后者发生,请在白板或纸上写下您的假设。以后可能需要它们。
What kind of questions to ask? Ask questions to understand the exact requirements. Here is a list of questions to help you get started: • What specific features are we going to build? • How many users does the product have? • How fast does the company anticipate to scale up? What are the anticipated scales in 3 months, 6 months, and a year? • What is the company’s technology stack? What existing services you might leverage to simplify the design? 问什么样的问题?提出问题以了解确切的要求。以下是帮助您入门的问题列表: • 我们将构建哪些特定功能? • 产品有多少用户? • 公司预计扩大规模的速度有多快?3个月、6个月和一年的预期规模是多少? • 公司的技术堆栈是什么?您可以利用哪些现有服务来简化设计?

Example

If you are asked to design a news feed system, you want to ask questions that help you clarify the requirements. The conversation between you and the interviewer might look like this: Candidate: Is this a mobile app? Or a web app? Or both? Interviewer: Both. Candidate: What are the most important features for the product? Interviewer: Ability to make a post and see friends’ news feed. Candidate: Is the news feed sorted in reverse chronological order or a particular order? The particular order means each post is given a different weight. For instance, posts from your close friends are more important than posts from a group. Interviewer: To keep things simple, let us assume the feed is sorted by reverse chronological order. Candidate: How many friends can a user have? Interviewer: 5000 Candidate: What is the traffic volume? Interviewer: 10 million daily active users (DAU) Candidate: Can feed contain images, videos, or just text? Interviewer: It can contain media files, including both images and videos. Above are some sample questions that you can ask your interviewer. It is important to understand the requirements and clarify ambiguities 如果你被要求设计一个新闻提要系统,你想问一些有助于你澄清需求的问题。你和面试官之间的对话可能是这样的: 候选人:这是一个移动应用程序吗?还是网络应用程序?或两者? 面试官:都有。 候选人:产品最重要的特性是什么? 面试官:能够发布帖子并查看朋友的动态消息。 候选人:新闻提要是按时间倒序排序还是按特定顺序排序?特定的顺序意味着每个帖子都有不同的权重。例如,来自您密友的帖子比来自群组的帖子更重要。 采访者:为了简单起见,让我们假设提要是按时间倒序排列的。 考生:一个用户可以有多少个好友? 面试官:5000 考生:流量是多少? 面试官:1000 万日活跃用户 (DAU) 候选人:Feed 可以包含图片、视频还是仅包含文本? 采访者:它可以包含媒体文件,包括图像和视频。 以上是一些您可以问面试官的示例问题。了解需求并澄清歧义很重要

Step 2 - Propose high-level design and get buy-in 第二步▁-▁提出高水平设计并获得认可

In this step, we aim to develop a high-level design and reach an agreement with the interviewer on the design. It is a great idea to collaborate with the interviewer during the process. • Come up with an initial blueprint for the design. Ask for feedback. Treat your interviewer as a teammate and work together. Many good interviewers love to talk and get involved. • Draw box diagrams with key components on the whiteboard or paper. This might include clients (mobile/web), APIs, web servers, data stores, cache, CDN, message queue, etc. • Do back-of-the-envelope calculations to evaluate if your blueprint fits the scale constraints. Think out loud. Communicate with your interviewer if back-of-the-envelope is necessary before diving into it. 在这一步中,我们的目标是开发一个高级设计,并与面试官就设计达成一致。在此过程中与面试官合作是个好主意。 • 提出设计的初始蓝图。寻求反馈。把面试官当成队友,一起工作。许多优秀的面试官喜欢交谈和参与。 • 在白板或纸上绘制包含关键组件的框图。这可能包括客户端(移动/Web)、API、Web 服务器、数据存储、缓存、CDN、消息队列等。 • 执行粗略计算,以评估蓝图是否符合缩放约束。大声思考。在深入研究之前,如果需要粗略的信封,请与您的面试官沟通。
If possible, go through a few concrete use cases. This will help you frame the high-level design. It is also likely that the use cases would help you discover edge cases you have not yet considered. Should we include API endpoints and database schema here? This depends on the problem. For large design problems like “Design Google search engine”, this is a bit of too low level. For a problem like designing the backend for a multi-player poker game, this is a fair game. Communicate with your interviewer. 如果可能,请浏览一些具体的用例。这将帮助您构建高级设计。这些用例也可能会帮助您发现尚未考虑的边缘情况。 我们是否应该在此处包含 API 端点和数据库架构?这取决于问题。对于像“设计谷歌搜索引擎”这样的大型设计问题,这有点太低了。对于像为多人扑克游戏设计后端这样的问题,这是一个公平的游戏。与面试官沟通。

example(有点不太懂)

Let us use “Design a news feed system” to demonstrate how to approach the high-level design. Here you are not required to understand how the system actually works. All the details will be explained in Chapter 11. 让我们使用“设计新闻源系统”来演示如何处理高级设计。在这里,您不需要了解系统的实际工作原理。所有细节将在第11章中解释。
At the high level, the design is divided into two flows: feed publishing and news feed building. • Feed publishing: when a user publishes a post, corresponding data is written into cache/database, and the post will be populated into friends’ news feed. • Newsfeed building: the news feed is built by aggregating friends’ posts in a reverse chronological order. Figure 3-1 and Figure 3-2 present high-level designs for feed publishing and news feed building flows, respectively. 在高级别,设计分为两个流程:提要发布和新闻提要构建。 • 提要发布:当用户发布帖子时,相应的数据被写入缓存/数据库,帖子将被填充到朋友的新闻提要中。 • 新闻源构建:新闻源是通过按时间倒序聚合朋友的帖子来构建的。 图 3-1 和图 3-2 分别显示了源发布和新闻源构建流的高级设计。

image.png

image.png

Design deep dive 深度设计

At this step, you and your interviewer should have already achieved the following objectives: • Agreed on the overall goals and feature scope • Sketched out a high-level blueprint for the overall design • Obtained feedback from your interviewer on the high-level design • Had some initial ideas about areas to focus on in deep dive based on her feedback 在此步骤中,您和您的面试官应该已经实现了以下目标: • 就总体目标和功能范围达成一致 • 勾勒出整体设计的高级蓝图 • 从面试官那里获得对高级设计的反馈 • 根据她的反馈,对深入研究中需要关注的领域有一些初步想法
You shall work with the interviewer to identify and prioritize components in the architecture. It is worth stressing that every interview is different. Sometimes, the interviewer may give off hints that she likes focusing on high-level design. Sometimes, for a senior candidate interview, the discussion could be on the system performance characteristics, likely focusing on the bottlenecks and resource estimations. In most cases, the interviewer may want you to dig into details of some system components. For URL shortener, it is interesting to dive into the hash function design that converts a long URL to a short one. For a chat system, how to reduce latency and how to support online/offline status are two interesting topics. 您应该与面试官一起确定架构中的组件并确定其优先级。值得强调的是,每次采访都是不同的。有时,面试官可能会暗示她喜欢专注于高级设计。有时,对于高级候选人面试,讨论可能是系统性能特征,可能侧重于瓶颈和资源估算。在大多数情况下,面试官可能希望您深入了解某些系统组件的详细信息。对于 URL 缩短器,深入研究将长 URL 转换为短 URL 的哈希函数设计很有趣。对于聊天系统,如何减少延迟以及如何支持在线/离线状态是两个有趣的话题。
Time management is essential as it is easy to get carried away with minute details that do not demonstrate your abilities. You must be armed with signals to show your interviewer. Try not to get into unnecessary details. For example, talking about the EdgeRank algorithm of Facebook feed ranking in detail is not ideal during a system design interview as this takes much precious time and does not prove your ability in designing a scalable system. 时间管理是必不可少的,因为它很容易忘记那些不能证明你的能力的微小细节。你必须携带信号来展示你的面试官。尽量不要谈到不必要的细节。例如,在系统设计面试中,详细讨论Facebook feed排名的EdgeRank算法并不理想,因为这将花费大量宝贵的时间,也不能证明你设计可伸缩系统的能力。

example

At this point, we have discussed the high-level design for a news feed system, and the interviewer is happy with your proposal. Next, we will investigate two of the most important use cases: 1. Feed publishing 2. News feed retrieval Figure 3-3 and Figure 3-4 show the detailed design for the two use cases, which will be explained in detail in Chapter 11. 在这一点上,我们已经讨论了新闻提要系统的高级设计,面试官对您的建议感到满意。接下来,我们将研究两个最重要的用例: 1. 提要发布 2.新闻提要检索 图 3-3 和图 3-4 显示了这两个用例的详细设计,将在第 11 章中详细解释。

image.png

image.png

Step 4 - Wrap up 圆满完成

In this final step, the interviewer might ask you a few follow-up questions or give you the freedom to discuss other additional points. Here are a few directions to follow: • The interviewer might want you to identify the system bottlenecks and discuss potential improvements. Never say your design is perfect and nothing can be improved. There is always something to improve upon. This is a great opportunity to show your critical thinking and leave a good final impression. • It could be useful to give the interviewer a recap of your design. This is particularly important if you suggested a few solutions. Refreshing your interviewer’s memory can be helpful after a long session. • Error cases (server failure, network loss, etc.) are interesting to talk about. • Operation issues are worth mentioning. How do you monitor metrics and error logs? How to roll out the system? • How to handle the next scale curve is also an interesting topic. For example, if your current design supports 1 million users, what changes do you need to make to support 10 million users? • Propose other refinements you need if you had more time. 在这最后一步中,面试官可能会问您一些后续问题,或者让您自由讨论其他附加问题。以下是一些要遵循的方向: • 面试官可能希望您确定系统瓶颈并讨论潜在的改进。永远不要说你的设计是完美的,没有什么可以改进的。总有一些地方需要改进。这是展示您的批判性思维并留下良好最终印象的绝好机会。 • 向面试官简要回顾一下您的设计可能很有用。如果您提出了一些解决方案,这一点尤其重要。在长时间的会议之后,刷新面试官的记忆可能会有所帮助。 • 错误情况(服务器故障、网络丢失等)很有趣。 • 运营问题值得一提。您如何监控指标和错误日志?如何推出系统? • 如何处理下一个刻度曲线也是一个有趣的话题。例如,如果您当前的设计支持 100 万用户,那么您需要进行哪些更改才能支持 1000 万用户? • 如果您有更多时间,请提出您需要的其他改进。
To wrap up, we summarize a list of the Dos and Don’ts. Dos • Always ask for clarification. Do not assume your assumption is correct. • Understand the requirements of the problem. • There is neither the right answer nor the best answer. A solution designed to solve the problems of a young startup is different from that of an established company with millions of users. Make sure you understand the requirements. • Let the interviewer know what you are thinking. Communicate with your interview. • Suggest multiple approaches if possible. • Once you agree with your interviewer on the blueprint, go into details on each component. Design the most critical components first. • Bounce ideas off the interviewer. A good interviewer works with you as a teammate. • Never give up. Don’ts • Don't be unprepared for typical interview questions. • Don’t jump into a solution without clarifying the requirements and assumptions. • Don’t go into too much detail on a single component in the beginning. Give the highlevel design first then drills down. • If you get stuck, don't hesitate to ask for hints. • Again, communicate. Don't think in silence. • Don’t think your interview is done once you give the design. You are not done until your interviewer says you are done. Ask for feedback early and often. 最后,我们总结了一个“禁忌的清单。 可以做的 * 总是要求核对你的问题。不要假设你的假设是正确的。 •了解问题的要求。 •这里既没有正确的答案,也没有最好的答案。一种旨在解决年轻初创公司问题的解决方案不同于一家拥有数百万用户的成熟公司。确保你理解了这些要求。 •让面试官知道你在想什么。与你的面试对象进行沟通。如果可能的话, •建议采用多种方法。•一旦你同意面试官的蓝图,请详细了解每个组件。首先设计最关键的组件。 •拒绝了采访者的想法。一个好的面试官作为队友和你一起工作。 •永不放弃。 不可做的: * 不要对典型的面试问题毫无准备。 •不要在没有澄清需求和假设之前直接进入解决方案。 •不要在开始时过多单个组件的细节。先进行高级设计,然后向下钻取。 •如果你被卡住了,请不要犹豫地寻求提示。 •再次,沟通。不要默默地思考。 •不要认为一旦你的设计,面试就完成了。直到面试官说你已经完成了,你才会被完成。尽早并经常寻求反馈。

Time allocation on each step

System design interview questions are usually very broad, and 45 minutes or an hour is not enough to cover the entire design. Time management is essential. How much time should you spend on each step? The following is a very rough guide on distributing your time in a 45- minute interview session. Please remember this is a rough estimate, and the actual time distribution depends on the scope of the problem and the requirements from the interviewer. Step 1 Understand the problem and establish design scope: 3 - 10 minutes Step 2 Propose high-level design and get buy-in: 10 - 15 minutes Step 3 Design deep dive: 10 - 25 minutes Step 4 Wrap: 3 - 5 minutes 系统设计面试问题通常非常广泛,45分钟或一个小时不足以涵盖整个设计。时间管理至关重要。您应该在每个步骤上花费多少时间?以下是在 45 分钟的面试中分配时间的非常粗略的指南。请记住,这是一个粗略的估计,实际的时间分布取决于问题的范围和面试官的要求。 步骤 1 了解问题并确定设计范围:3 - 10 分钟 步骤 2 提出高级设计并获得支持:10 - 15 分钟 步骤 3 设计深入探讨:10 - 25 分钟 步骤 4 包装:3 - 5 分钟

本文作者:Eric

本文链接:

版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!