by Zhia Hwa Chong
志華化
破解系統設計訪談:Twitter軟件工程師的提示 (Crack the System Design interview: tips from a Twitter software engineer)
I recently wrote about how I landed offers from multiple top-tier tech companies. During my interview preparation process, I read up on a lot of material and prepared a set of notes on how to tackle system design problems. In this article, I’d like to share those tips with you all.
我最近寫了關于如何從多家頂級科技公司獲得報價的文章 。 在準備面試過程中,我閱讀了許多材料,并準備了有關如何解決系統設計問題的一組說明。 在本文中,我想與大家分享這些技巧。
If you’re a fresh graduate with no experience in large-scale distributed systems, or even a seasoned engineer with years of experience under your belt, this article will be useful for you.
如果您是沒有大規模分布式系統經驗的應屆畢業生,或者甚至是具有多年經驗的經驗豐富的工程師,那么本文對您都是有用的。
Update (3/24/2019): If you’d like to join a group of students to learn more about system design, I’m organizing a small class together! You can go to this link to learn more, or visit my website: zhiachong.com for more info.
更新(3/24/2019) :如果您想加入一組學生以了解有關系統設計的更多信息,我將一起組織一小堂課! 您可以轉到此鏈接以了解更多信息,或訪問我的網站zhiachong.com以獲取更多信息。
This article is broken down into the following four sections:
本文分為以下四個部分:
- Ask clarification questions 提出澄清問題
- Use your background 使用你的背景
- Tackle a problem systematically 系統地解決問題
- Keep your own notes 保留自己的筆記
提出澄清問題 (Ask clarification questions)
A core aim of a systems design interview is to give the candidate an opportunity to demonstrate their knowledge.
系統設計面試的核心目的是使應聘者有機會證明自己的知識。
There are no strictly right or wrong answers. A good system design question usually sounds very ambiguous, and the reason for that is it’s supposed to give you a chance to demonstrate the following:
沒有嚴格正確或錯誤的答案。 一個好的系統設計問題通常聽起來很模棱兩可,其原因是應該給您展示以下內容的機會:
- How you would think about the problem space 您如何看待問題空間
- How you think about bottlenecks 您如何看待瓶頸
- What you can do to remove these bottlenecks. 您可以采取哪些措施消除這些瓶頸。
Imagine that you’re being asked to design a black box. How would you tackle the problem? There are no clear directions on what you need to build here, aside from the box being able to hold some items within it.
想象您被要求設計一個黑匣子。 您將如何解決這個問題? 除了可以在其中容納一些物品的盒子之外,這里沒有明確的指示要建造什么。
One of the most useful strategies I personally employ is to ask clarification questions. What are “good” clarification questions, you ask?
我個人采用的最有用的策略之一是提出澄清問題。 您問什么是“好的”澄清問題?
A good clarification question helps you achieve one, or more, of several things:
一個好的澄清問題可以幫助您實現以下一項或多項目標:
- Helps you narrow the scope of what you’re supposed to do 幫助您縮小應該做的事情的范圍
- Helps clarify what the user expectation of the system is 幫助闡明用戶對系統的期望
- Gives you direction about where to proceed 指導您進行下一步
- Informs you of possible bottlenecks/problem areas 通知您可能的瓶頸/問題區域
In the black box example, you might ask, “well, what does the box hold? How many items does it hold? And who is the intended user?”
在黑匣子示例中,您可能會問:“那么,該箱子能容納什么? 它容納多少個物品? 誰是目標用戶?”
To that I might say, let’s build a yellow box with a smiley on it that should hold at most 1 tennis ball. This is not an ordinary tennis ball, however. It will be at least 0.5m in radius and weighs about 1kg. It is meant to be hugged, not held, so I don’t want any handle on it.
也許我會說,讓我們建立一個黃色的盒子,上面帶有一個笑臉,最多可容納1個網球。 但是,這不是普通的網球。 半徑至少為0.5m,重約1kg。 它應該被擁抱,而不是被握住,所以我不需要任何處理。
There you go, this is the box.
您去了,這是盒子。
Always ask clarification questions. You are not being judged on whether or not you asked a specific question during the interview, but you are judged on how you think about the problem space.
總是問澄清問題。 您不會在面試過程中被問到是否問過某個特定問題,而是會根據您對問題空間的看法來判斷您。
For example, if I were to ask you to design Twitter right now, how would you do it? Take a few minutes to think about it, and maybe even sketch it out on a piece of paper. Go as deeply and widely as you can, and then come back to this article. Better yet, you can leave your notes in the comments below and we can discuss further.
例如,如果我要您現在設計Twitter,您將如何做? 花幾分鐘考慮一下,甚至可以在一張紙上畫出草圖。 盡可能深入和廣泛地討論,然后再回到本文。 更好的是,您可以在下面的評論中留下您的筆記 ,我們可以進行進一步討論。
If you haven’t realized it yet, the end result of the exercise above would yield significantly different results. For my own specific background, I might delve really deeply into API design and backend infrastructure. I’d probably explore iPhone-specific problems as well, due to my experience. I’ll talk about how the client interacts with the middle-tier endpoints, how logging would work, how I’d design the backend to ensure uptime, and so on.
如果您尚未意識到這一點,那么上面練習的最終結果將產生明顯不同的結果。 對于我自己的特定背景,我可能會真正深入地研究API設計和后端基礎結構。 根據我的經驗,我可能還會探討特定于iPhone的問題。 我將討論客戶端如何與中間層端點交互,日志將如何工作,如何設計后端以確保正常運行時間,等等。
These are quite interesting discussions that you can have with a colleague, and that is a very strong signal an interviewer is looking for.
您可以與同事進行非常有趣的討論,這是面試官正在尋找的強烈信號。
利用您的背景優勢 (Use your background to your advantage)
Often times I see engineers trying to figure out what the interviewer is trying to ask, and then catering their responses to fit the expectations.
我經常看到工程師試圖弄清楚面試官要問的問題,然后根據他們的期望來滿足他們的要求。
I actually highly discourage anyone from doing this for several reasons:
實際上,出于以下幾個原因,我非常不鼓勵任何人這樣做:
- Everyone has a unique background. In a systems design interview, it’s an opportunity for you to demonstrate what your strengths are. Don’t waste the opporunity trying to figure out what someone else might expect of you. 每個人都有獨特的背景。 在系統設計面試中,這是您展示自己的優勢的機會。 不要浪費機會試圖弄清楚別人對你的期望。
- The interviewer might have been nodding along to your answers, but they might’ve known that you’re just bluffing your way through and not actually thinking about the problem. 面試官可能一直在回答您的答案,但他們可能已經知道您只是在虛張聲勢,沒有真正考慮問題。
Your experience and background can vary widely from the next candidate. You bring a set of values and expertise to the table that no one else can. That is what makes you valuable and irreplaceable. Regardless of what field you’re in, people care about what you can bring to the table.
您的經驗和背景可能與下一個候選人有很大差異。 您將一套價值和專業知識帶到了桌上,這是其他人所無法企及的。 那就是讓您變得寶貴和不可替代的原因。 無論您處于哪個領域,人們都在乎您可以帶到餐桌上的東西。
系統地解決問題 (Tackle the problem systematically)
Now, with my expertise in mind, there are several things that I think about when I’m tackling a new system. I highly recommend that you formulate a set of criteria or steps for yourself as well.
現在,考慮到我的專業知識,我在處理新系統時會考慮幾件事。 我強烈建議您也為自己制定一套標準或步驟。
Some of the things in my mind when I work on a new system are:
在新系統上工作時,我想到的一些事情是:
- What is the goal of the system? 系統的目標是什么?
- Who are the users of the system? 誰是系統的用戶?
- What is the scale we’re working with? 我們正在合作的規模是多少?
- Is this a new/old system? How do we handle versioning? 這是新舊系統嗎? 我們如何處理版本控制?
Among others…
其中...
See, my set of criteria will be different from a front-end engineer’s set of criteria. I use these criteria to formulate a picture in my head, and these will guide my decision-making process.
瞧,我的標準集將不同于前端工程師的標準集。 我用這些標準在腦海里畫一幅畫,這些將指導我的決策過程。
Armed with answers to those questions, I can start to tackle the problem at hand and then systematically break it down into individual components.
有了這些問題的答案,我可以開始解決當前的問題,然后系統地將其分解為各個部分。
A good exercise I like to do is how to design a coffee-ordering system. I thought of this while I was sitting at Starbucks one day, and realized that it would be nice if I could order a smoothie on my phone and pick it up at my local Starbucks.
我喜歡做的一個好練習是如何設計咖啡訂購系統 。 我有一天坐在星巴克時就想到了這一點,并意識到,如果可以在手機上訂購冰沙,然后在當地的星巴克拿起冰沙,那就太好了。
My mind started going in various directions:
我的想法開始朝各個方向發展:
- What does this coffee-ordering machine do? 這臺咖啡訂購機有什么作用?
- If I build one, can I sell it to Starbucks, or do I white-label it and sell it as a service? 如果我制造一個,可以將其出售給星巴克,還是將其貼上白標簽并作為服務出售?
- How many users do I need to support if I sell it to Starbucks? 如果將其出售給星巴克,需要支持多少用戶?
- Alternatively, if I white-label it, can I sell the interface to my coffee-ordering service, and then help the customers build out a backend so that they can store the orders on their local machines? 或者,如果我將其貼上白標簽,我可以將界面出售給我的咖啡訂購服務,然后幫助客戶構建后端以便他們將訂單存儲在本地計算機上嗎?
Once I get answers to these questions, I can finally form a full picture of what my coffee-ordering service does. Here’s what my version of the coffee-ordering service would look like:
一旦獲得這些問題的答案,我就可以完整地了解我的咖啡訂購服務的功能。 我的咖啡訂購服務版本如下所示:
My coffee-ordering service is a software as a service (SAAS). It offers an interface for various partners to plug into.
我的咖啡訂購服務是一種軟件即服務( SAAS )。 它為各種合作伙伴提供了插入接口。
It has an API, called addCoffeeForMerchant, that inserts coffee name, coffee price, and coffee ingredients.
它具有一個名為addCoffeeForMerchant的API,可插入咖啡名稱,咖啡價格和咖啡原料。
It has a GET API, called getCoffeesForMerchant, that returns a list of coffees for a given merchant ID.
它具有一個名為getCoffeesForMerchant的GET API,該API返回給定商家ID的咖啡列表。
- The merchant ID is a unique identifier (UUID) that is generated using some hashing mechanism, which can be further clarified with the customer. 商家ID是使用某種哈希機制生成的唯一標識符(UUID),可以與客戶進一步闡明。
- The software is optimized for read-only operations, because most of my customers create their menu once and read it multiple times throughout the day. 該軟件針對只讀操作進行了優化,因為我的大多數客戶一次創建菜單并全天閱讀多次。
It has a caching mechanism that uses Least-Recently-Used (LRU) eviction strategy, because if the menu item hasn’t been ordered in a while, my customer doesn’t care if it’s slightly slower in showing up on the menu.
它具有使用最近最少使用(LRU)驅逐策略的緩存機制,因為如果一段時間未訂購菜單項,那么我的客戶將不在乎它在菜單上顯示的速度是否稍慢。
- In case one of the data stores self-erupts, my coffee-ordering service will replicate data across different clusters across US west and US east coast because I am targeting the US market only for now. 萬一其中一個數據存儲設備自爆,我的咖啡訂購服務將跨美國西部和美國東海岸的不同集群復制數據,因為我目前僅針對美國市場。
Alternatively, any other coffee-ordering service that you can think of would be highly probable as well. It’s just a matter of what you’re optimizing for. I think these are very interesting problems, and it’s a great mental exercise to keep your mind engaged.
另外,您可能想到的任何其他咖啡訂購服務也很有可能。 這只是您要優化的問題。 我認為這些都是非常有趣的問題,這是使您保持頭腦活躍的一項很棒的心理鍛煉。
保留自己的筆記 (Keep your own notes)
As a software engineer, it’s a never-ending process of learning. I highly recommend that you use either Evernote or a Moleskin to keep notes. I personally carry a small notebook for quick ideas I need to jot down, and I keep various other things on Evernote whenever I can.
作為軟件工程師,這是一個永無止境的學習過程。 我強烈建議您使用Evernote或Moleskin進行筆記。 我個人隨身攜帶一個小筆記本,以記下我需要記下的快速想法,并盡可能地在Evernote上保存其他各種內容。
I have a Notebook named “Programming” in my Evernote. Whenever I run into something new, or something interesting, I jot it down within my notebook for further reference.
我的Evernote中有一個名為“編程”的筆記本。 每當遇到新事物或有趣事物時,我都會將其記在筆記本上以備參考。
I go through and assign labels to these new notes on a monthly or quarterly basis to make sure the notes are organized. For example, I have a “Design” label for anything that has to do with system design. It could be something like a link to a YouTube video that I found interesting, or an interesting argument my coworker put forth that I hadn’t thought about.
我逐月檢查并為這些新筆記分配標簽,以確保筆記井井有條。 例如,對于與系統設計有關的任何事情,我都有一個“設計”標簽。 可能是我發現有趣的YouTube視頻鏈接,或者是我的同事提出的我從未想過的有趣論點。
This is a sample of what one of my notes looks like:
這是我的注釋之一的示例:
One of the things I learned recently from a coworker is that NoSQL is great for prototyping, because there’s no need to undergo schema discussions with other teams. If I wanted to change the schema, I can do that really quickly with a NoSQL database. That was a key learning from work that I inserted into my “Programming” notebook.
我最近從一位同事那里了解到的一件事是NoSQL非常適合進行原型設計,因為無需與其他團隊進行架構討論。 如果要更改架構,則可以使用NoSQL數據庫快速完成。 這是我從“編程”筆記本中插入的工作中的關鍵經驗。
I break down my notes into:
我將筆記分解為:
- Systems designs 系統設計
- Interviewing (experience + review of different interviews I’ve had in the past, grouped by company name) 面試(經驗+對我過去進行過的不同面試的審查,按公司名稱分組)
- Random tid-bits, CS good-to-know, like useful bash scripts or command-line tricks 隨機的tid位,CS眾所周知,例如有用的bash腳本或命令行技巧
- Readings / YouTube videos 閱讀資料/ YouTube視頻
All of the notes above go under “Programming”. Over time, I find that I have a pseudo-organized collection of things I’ve either read or explored in the past.
以上所有注釋都在“編程”下。 隨著時間的流逝,我發現我擁有過去已經閱讀或探索過的偽組織的東西。
As anyone who knows me on a personal level, I’m not a very organized person. Thus, I’ve only collected maybe 10 - 15% of things, so there’s much more left to do there.
就個人而言,認識我的人不是一個有條理的人。 因此,我只收集了大約10%到15%的東西,因此還有更多要做的事情。
Knowledge and practice go hand-in-hand in getting better at systems designs. If you feel that your current work doesn’t afford you the opportunity to do systems designs, then you should either find one that does, or try to design one small part of an existing architecture such that it’s either faster, cheaper, more robust, or easier to modify in the future.
知識和實踐是攜手并進的,以便更好地進行系統設計。 如果您認為當前的工作沒有給您提供進行系統設計的機會,那么您應該找到一個可以做的設計,或者嘗試設計現有體系結構的一小部分,以使其更快,更便宜,更可靠,或者將來更容易修改。
我推薦的資源 (Resources I recommend)
Intro to: Architecture and Systems Designs - Great Youtube tutorial from an ex-Facebook-engineer about how to approach systems design problems.
簡介:體系結構和系統設計 -前Facebook工程師提供的有關如何解決系統設計問題的Great Youtube教程。
Designing data-intensive applications - Another good resource for learning how to design for scale. It talks about various things a typical software engineer takes for granted — how databases (mySQL and noSQL) work, when to use each, pros and cons of various techniques for handling scale etc. I highly recommend it ?
設計數據密集型應用程序 -學習如何按比例設計的另一個很好的資源。 它討論了典型軟件工程師理所當然的各種事情-數據庫(mySQL和noSQL)如何工作,何時使用每種數據庫以及處理規模等各種技術的利弊。我強烈推薦它嗎?
Mock Interviews - A simulated environment that mimics the actual interview is extremely helpful in preparing for interviews. If you can find a friend to do it for you, then I highly recommend it. I also run mock interviews, so if you’re interested, feel free to reach me at zhiachong.com!
模擬面試-模擬實際面試的模擬環境對于準備面試非常有幫助。 如果您可以找到一個朋友幫您做,那么我強烈推薦。 我還會進行模擬面試,因此,如果您有興趣,請隨時訪問zhiachong.com與我聯系 !
What every software engineer should know about real-time data’s unifying abstraction - A very lengthy and technical discussion about logs, trade-offs. I haven’t finished it yet, but it comes highly recommended from a coworker.
每個軟件工程師應該了解的有關實時數據統一抽象的知識 -有關日志,權衡取舍的冗長而技術性的討論。 我還沒有完成,但是強烈推薦給同事。
Evernote - The best ? note-keeping app I’ve used. There are many tutorials on how to best utilize Evernote. I haven’t gone through them yet, simply because I use it as just a notebook. I log everything I learn on there, and then occasionally go through and reorganize them.
印象筆記 -最好的? 我使用過的記事應用程序。 有很多關于如何最好地利用Evernote的教程。 我還沒有經歷過這些,僅僅是因為我只是將其用作筆記本。 我將在此學習的所有內容記錄下來,然后偶爾進行整理和整理。
Moleskin notebook - I really enjoy this one. The quality of it is extremely high. The price is slightly higher, but since I use it on a daily basis, I consider it a good investment. Holding a beautiful notebook in my hands everyday makes me more excited to write more notes.
Moleskin筆記本 -我真的很喜歡這一本。 它的質量非常高。 價格略高,但是由于我每天使用它,因此我認為這是一筆不錯的投資。 每天我手里拿著一個漂亮的筆記本使我更加興奮地寫下更多筆記。
Pilot G2 (Black) - Easily the best pens I’ve ever used, and the only pens I’ll use. I buy them in bulk from Amazon and keep them around everywhere I go. I have one in my backpack, one in the office, and one in my home office so that I always have a pen around. It writes great, the ink flows smoothly, and I just love the feel of writing with it. Coupled with the Moleskin, sometimes I just want to pick up the G2 to jot random things on there because these two are so perfect together.
G2飛行員(黑色) -輕松獲得我曾經使用過的最好的筆,并且是我唯一會使用的筆。 我從亞馬遜大量購買它們,并隨處攜帶。 我的背包里有一個,辦公室里有一個,家庭辦公室里有一個,所以我周圍總是有一支筆。 它書寫出色,墨水順暢流動,我只是喜歡用它書寫。 加上Moleskin,有時候我只想拿起G2在那兒隨意玩,因為這兩者非常完美。
Grokking the System Design Interview — This one comes as a recommendation from friends. It’s an online course that teaches how to design distributed system in detail. It’s a $79 course, however. There’s a team-pricing. If there’s any interest, I’ll check with them to see if it’s possible to form a group for group-discount.
探索系統設計面試 -這是朋友的推薦。 這是一門在線課程,教您如何詳細設計分布式系統。 然而,這是一門79美元的課程。 有團隊定價。 如果有興趣,我會與他們核對,看看是否有可能組建團體折扣團體。
Follow me on Twitter, Facebook, and LinkedIn. Sign up for my mailing list where I regularly send tips, tricks and industry learnings.
在Twitter , Facebook和LinkedIn上關注我。 注冊我的郵件列表 ,我在那里定期發送提示,技巧和行業知識。
If you enjoyed this article, comment below: what is your tip for building a scalable, reliable system?
如果您喜歡本文,請在下面評論: 構建可擴展,可靠系統的提示是什么?
翻譯自: https://www.freecodecamp.org/news/how-to-system-design-dda63ed27e26/