Finish basic version

pull/60/head
Yang Wentao 2017-03-30 08:33:35 +08:00
parent 891d0b17c2
commit e23ad353f6
1 changed files with 283 additions and 186 deletions

View File

@ -5,6 +5,7 @@
> * 这个 [链接](https://github.com/xitu/system-design-primer/compare/master...donnemartin:master) 用来查看本翻译与英文版是否有差别(如果你没有看到 README.md 发生变化,那就意味着这份翻译文档是最新的)。 > * 这个 [链接](https://github.com/xitu/system-design-primer/compare/master...donnemartin:master) 用来查看本翻译与英文版是否有差别(如果你没有看到 README.md 发生变化,那就意味着这份翻译文档是最新的)。
# The System Design Primer # The System Design Primer
# 系统设计入门
<p align="center"> <p align="center">
<img src="http://i.imgur.com/jj3A5N8.png"> <img src="http://i.imgur.com/jj3A5N8.png">
@ -12,40 +13,61 @@
</p> </p>
## Motivation ## Motivation
## 目标
> Learn how to design large scale systems. > Learn how to design large scale systems.
> >
> Prep for the system design interview. > Prep for the system design interview.
> 学习如何设计大型系统
>
> 为系统设计面试做准备
### Learn how to design large scale systems ### Learn how to design large scale systems
### 学习如何设计大型系统
Learning how to design scalable systems will help you become a better engineer. Learning how to design scalable systems will help you become a better engineer.
学习如何设计大型系统将会帮助你成为一个更好的工程师。
System design is a broad topic. There is a **vast amount of resources scattered throughout the web** on system design principles. System design is a broad topic. There is a **vast amount of resources scattered throughout the web** on system design principles.
系统设计是一个很宽泛的话题。在互联网上,**关于系统设计原则的资源也是多如牛毛。**
This repo is an **organized collection** of resources to help you learn how to build systems at scale. This repo is an **organized collection** of resources to help you learn how to build systems at scale.
这个仓库就是这些资源的**有组织的集合**,它可以帮助你学习如果基于不同尺度构建系统。
### Learn from the open source community ### Learn from the open source community
### 从开源社区学习
This is an early draft of a continually updated, open source project. This is an early draft of a continually updated, open source project.
这是一个不断更新的开源项目的初期的版本。
[Contributions](#contributing) are welcome! [Contributions](#contributing) are welcome!
欢迎 [贡献](#contributing)
### Prep for the system design interview ### Prep for the system design interview
### 为系统设计面试做准备
In addition to coding interviews, system design is a **required component** of the **technical interview process** at many tech companies. In addition to coding interviews, system design is a **required component** of the **technical interview process** at many tech companies.
在很多科技公司中,除了代码面试,系统设计也是**技术面试过程**中的一个**必要环节**。
**Practice common system design interview questions** and **compare** your results with **sample solutions**: discussions, code, and diagrams. **Practice common system design interview questions** and **compare** your results with **sample solutions**: discussions, code, and diagrams.
**练习普通的系统设计面试题**并且把你的结果和**例子的答案**进行**比较**:讨论,代码和图表。
Additional topics for interview prep: Additional topics for interview prep:
面试准备的其他主题:
* [Study guide](#study-guide) * [Study guide](#study-guide)
* [How to approach a system design interview question](#how-to-approach-a-system-design-interview-question) * [How to approach a system design interview question](#how-to-approach-a-system-design-interview-question)
* [System design interview questions, **with solutions**](#system-design-interview-questions-with-solutions) * [System design interview questions, **with solutions**](#system-design-interview-questions-with-solutions)
* [Object-oriented design interview questions, **with solutions**](#object-oriented-design-interview-questions-with-solutions) * [Object-oriented design interview questions, **with solutions**](#object-oriented-design-interview-questions-with-solutions)
* [Additional system design interview questions](#additional-system-design-interview-questions) * [Additional system design interview questions](#additional-system-design-interview-questions)
* [学习指引](#study-guide)
* [如何回答一个系统设计面试题](#how-to-approach-a-system-design-interview-question)
* [系统设计面试题, **有答案**](#system-design-interview-questions-with-solutions)
* [面向对象设计面试题, **有答案**](#object-oriented-design-interview-questions-with-solutions)
* [其他系统设计面试题](#additional-system-design-interview-questions)
## Anki flashcards ## Anki flashcards
## 抽认卡
<p align="center"> <p align="center">
<img src="http://i.imgur.com/zdCAkB3.png"> <img src="http://i.imgur.com/zdCAkB3.png">
@ -53,170 +75,211 @@ Additional topics for interview prep:
</p> </p>
The provided [Anki flashcard decks](https://apps.ankiweb.net/) use spaced repetition to help you retain key system design concepts. The provided [Anki flashcard decks](https://apps.ankiweb.net/) use spaced repetition to help you retain key system design concepts.
这里提供的 [抽认卡堆](https://apps.ankiweb.net/) 使用间隔重复的方法帮助你记住系统设计的概念。
* [System design deck](resources/flash_cards/System%20Design.apkg) * [System design deck](resources/flash_cards/System%20Design.apkg)
* [System design exercises deck](resources/flash_cards/System%20Design%20Exercises.apkg) * [System design exercises deck](resources/flash_cards/System%20Design%20Exercises.apkg)
* [Object oriented design exercises deck](resources/flash_cards/OO%20Design.apkg) * [Object oriented design exercises deck](resources/flash_cards/OO%20Design.apkg)
* [系统设计卡堆](resources/flash_cards/System%20Design.apkg)
* [系统设计练习卡堆](resources/flash_cards/System%20Design%20Exercises.apkg)
* [面向对象设计练习卡堆](resources/flash_cards/OO%20Design.apkg)
Great for use while on-the-go. Great for use while on-the-go.
用起来非常棒。
## Contributing ## Contributing
## 贡献
> Learn from the community. > Learn from the community.
> 向社区学习。
Feel free to submit pull requests to help: Feel free to submit pull requests to help:
自由提交 PR 来帮助:
* Fix errors * Fix errors
* Improve sections * Improve sections
* Add new sections * Add new sections
* 修复错误
* 改善章节
* 添加章节
Content that needs some polishing is placed [under development](#under-development). Content that needs some polishing is placed [under development](#under-development).
还需要打磨的一些内容放在了 [开发中](#under-development)。
Review the [Contributing Guidelines](CONTRIBUTING.md). Review the [Contributing Guidelines](CONTRIBUTING.md).
查看 [贡献指导](CONTRIBUTING.md)。
### Translations ### Translations
### 翻译
Interested in **translating**? Please see the following [ticket](https://github.com/donnemartin/system-design-primer/issues/28). Interested in **translating**? Please see the following [ticket](https://github.com/donnemartin/system-design-primer/issues/28).
对**翻译**感兴趣?请查看这个 [门票](https://github.com/donnemartin/system-design-primer/issues/28)。
## Index of system design topics ## Index of system design topics
## 系统设计主题的索引
> Summaries of various system design topics, including pros and cons. **Everything is a trade-off**. > Summaries of various system design topics, including pros and cons. **Everything is a trade-off**.
> >
> Each section contains links to more in-depth resources. > Each section contains links to more in-depth resources.
> 各种系统设计主题的摘要,包括优点和缺点。**每一个主题都对应一个职业**。
>
> 每个章节都包含更深层次的资源的链接。
<p align="center"> <p align="center">
<img src="http://i.imgur.com/jrUBAF7.png"> <img src="http://i.imgur.com/jrUBAF7.png">
<br/> <br/>
</p> </p>
* [System design topics: start here](#system-design-topics-start-here) * [系统设计主题:从这里开始](#system-design-topics-start-here)
* [Step 1: Review the scalability video lecture](#step-1-review-the-scalability-video-lecture) * [第一步:查阅拓展性的视频讲座](#step-1-review-the-scalability-video-lecture)
* [Step 2: Review the scalability article](#step-2-review-the-scalability-article) * [第二步: 查阅拓展性的文章](#step-2-review-the-scalability-article)
* [Next steps](#next-steps) * [接下来的步骤](#next-steps)
* [Performance vs scalability](#performance-vs-scalability) * [性能 vs 拓展性](#performance-vs-scalability)
* [Latency vs throughput](#latency-vs-throughput) * [延迟 vs 吞吐量](#latency-vs-throughput)
* [Availability vs consistency](#availability-vs-consistency) * [可用性 vs 一致性](#availability-vs-consistency)
* [CAP theorem](#cap-theorem) * [CAP 理论](#cap-theorem)
* [CP - consistency and partition tolerance](#cp---consistency-and-partition-tolerance) * [CP - 一致性和分区容错性](#cp---consistency-and-partition-tolerance)
* [AP - availability and partition tolerance](#ap---availability-and-partition-tolerance) * [AP - 可用性和分区容错性](#ap---availability-and-partition-tolerance)
* [Consistency patterns](#consistency-patterns) * [一致模式](#consistency-patterns)
* [Weak consistency](#weak-consistency) * [弱一致性](#weak-consistency)
* [Eventual consistency](#eventual-consistency) * [最终一致性](#eventual-consistency)
* [Strong consistency](#strong-consistency) * [强一致](#strong-consistency)
* [Availability patterns](#availability-patterns) * [可用模式](#availability-patterns)
* [Fail-over](#fail-over) * [容灾](#fail-over)
* [Replication](#replication) * [复制集](#replication)
* [Domain name system](#domain-name-system) * [域名系统](#domain-name-system)
* [Content delivery network](#content-delivery-network) * [CDN](#content-delivery-network)
* [Push CDNs](#push-cdns) * [推送 CDNs](#push-cdns)
* [Pull CDNs](#pull-cdns) * [拉取 CDNs](#pull-cdns)
* [Load balancer](#load-balancer) * [负载均衡](#load-balancer)
* [Active-passive](#active-passive) * [主动-被动](#active-passive)
* [Active-active](#active-active) * [主动-主动](#active-active)
* [Layer 4 load balancing](#layer-4-load-balancing) * [4 层负载均衡](#layer-4-load-balancing)
* [Layer 7 load balancing](#layer-7-load-balancing) * [7 层负载均衡](#layer-7-load-balancing)
* [Horizontal scaling](#horizontal-scaling) * [水平拓展](#horizontal-scaling)
* [Reverse proxy (web server)](#reverse-proxy-web-server) * [反向代理web 服务)](#reverse-proxy-web-server)
* [Load balancer vs reverse proxy](#load-balancer-vs-reverse-proxy) * [负载均衡 vs 反向代理](#load-balancer-vs-reverse-proxy)
* [Application layer](#application-layer) * [应用层](#application-layer)
* [Microservices](#microservices) * [微服务](#microservices)
* [Service discovery](#service-discovery) * [服务发现](#service-discovery)
* [Database](#database) * [数据库](#database)
* [Relational database management system (RDBMS)](#relational-database-management-system-rdbms) * [关系型数据库管理系统 (RDBMS)](#relational-database-management-system-rdbms)
* [Master-slave replication](#master-slave-replication) * [Master-slave 复制集](#master-slave-replication)
* [Master-master replication](#master-master-replication) * [Master-master 复制集](#master-master-replication)
* [Federation](#federation) * [联合](#federation)
* [Sharding](#sharding) * [分片](#sharding)
* [Denormalization](#denormalization) * [反规则化](#denormalization)
* [SQL tuning](#sql-tuning) * [SQL 笔试题](#sql-tuning)
* [NoSQL](#nosql) * [NoSQL](#nosql)
* [Key-value store](#key-value-store) * [Key-value 存储](#key-value-store)
* [Document store](#document-store) * [文档存储](#document-store)
* [Wide column store](#wide-column-store) * [宽列存储](#wide-column-store)
* [Graph Database](#graph-database) * [图表数据库](#graph-database)
* [SQL or NoSQL](#sql-or-nosql) * [SQL 还是 NoSQL](#sql-or-nosql)
* [Cache](#cache) * [缓存](#cache)
* [Client caching](#client-caching) * [客户端缓存](#client-caching)
* [CDN caching](#cdn-caching) * [CDN 缓存](#cdn-caching)
* [Web server caching](#web-server-caching) * [Web 服务缓存](#web-server-caching)
* [Database caching](#database-caching) * [数据库缓存](#database-caching)
* [Application caching](#application-caching) * [应用缓存](#application-caching)
* [Caching at the database query level](#caching-at-the-database-query-level) * [在数据库查询层缓存](#caching-at-the-database-query-level)
* [Caching at the object level](#caching-at-the-object-level) * [对象缓存](#caching-at-the-object-level)
* [When to update the cache](#when-to-update-the-cache) * [何时更新缓存](#when-to-update-the-cache)
* [Cache-aside](#cache-aside) * [隐式缓存](#cache-aside)
* [Write-through](#write-through) * [直接写入](#write-through)
* [Write-behind (write-back)](#write-behind-write-back) * [回调写入](#write-behind-write-back)
* [Refresh-ahead](#refresh-ahead) * [自动更新](#refresh-ahead)
* [Asynchronism](#asynchronism) * [异步](#asynchronism)
* [Message queues](#message-queues) * [消息队列](#message-queues)
* [Task queues](#task-queues) * [任务队列](#task-queues)
* [Back pressure](#back-pressure) * [背压机制](#back-pressure)
* [Communication](#communication) * [通讯](#communication)
* [Transmission control protocol (TCP)](#transmission-control-protocol-tcp) * [传输控制协议 (TCP)](#transmission-control-protocol-tcp)
* [User datagram protocol (UDP)](#user-datagram-protocol-udp) * [用户数据报协议 (UDP)](#user-datagram-protocol-udp)
* [Remote procedure call (RPC)](#remote-procedure-call-rpc) * [远程控制调用 (RPC)](#remote-procedure-call-rpc)
* [Representational state transfer (REST)](#representational-state-transfer-rest) * [表述性状态转移 (REST)](#representational-state-transfer-rest)
* [Security](#security) * [网络安全](#security)
* [Appendix](#appendix) * [附录](#appendix)
* [Powers of two table](#powers-of-two-table) * [两张表的威力](#powers-of-two-table)
* [Latency numbers every programmer should know](#latency-numbers-every-programmer-should-know) * [每一位程序员应该知道的数字误差](#latency-numbers-every-programmer-should-know)
* [Additional system design interview questions](#additional-system-design-interview-questions) * [其他系统设计面试题](#additional-system-design-interview-questions)
* [Real world architectures](#real-world-architectures) * [真实架构](#real-world-architectures)
* [Company architectures](#company-architectures) * [公司架构](#company-architectures)
* [Company engineering blogs](#company-engineering-blogs) * [公司工程博客](#company-engineering-blogs)
* [Under development](#under-development) * [开发中](#under-development)
* [Credits](#credits) * [致谢](#credits)
* [Contact info](#contact-info) * [联系方式](#contact-info)
* [License](#license) * [许可](#license)
## Study guide ## Study guide
## 学习指引
> Suggested topics to review based on your interview timeline (short, medium, long). > Suggested topics to review based on your interview timeline (short, medium, long).
> 基于你面试的时间线(短,中,长)去回顾那些推荐的主题。
![Imgur](http://i.imgur.com/OfVllex.png) ![Imgur](http://i.imgur.com/OfVllex.png)
**Q: For interviews, do I need to know everything here?** **Q: For interviews, do I need to know everything here?**
**问:对于面试来说,我需要知道这里的所有知识点吗?**
**A: No, you don't need to know everything here to prepare for the interview**. **A: No, you don't need to know everything here to prepare for the interview**.
**答:不,如果只是为了准备面试的话,你并不需要知道指导的知识点。**
What you are asked in an interview depends on variables such as: What you are asked in an interview depends on variables such as:
在一场面试中你会被问到什么取决于下面这些因素:
* How much experience you have * How much experience you have
* What your technical background is * What your technical background is
* What positions you are interviewing for * What positions you are interviewing for
* Which companies you are interviewing with * Which companies you are interviewing with
* Luck * Luck
* 你的经验
* 你的技术背景
* 你面试的职位
* 你面试的公司
* 运气
More experienced candidates are generally expected to know more about system design. Architects or team leads might be expected to know more than individual contributors. Top tech companies are likely to have one or more design interview rounds. More experienced candidates are generally expected to know more about system design. Architects or team leads might be expected to know more than individual contributors. Top tech companies are likely to have one or more design interview rounds.
那些有经验的候选人通常会被期望了解更多的系统设计的知识。架构师或者团队负责人则会被期望了解更多除了个人贡献之外的知识。顶级的科技公司通常也会有一次或者更多的系统设计面试。
Start broad and go deeper in a few areas. It helps to know a little about various key system design topics. Adjust the following guide based on your timeline, experience, what positions you are interviewing for, and which companies you are interviewing with. Start broad and go deeper in a few areas. It helps to know a little about various key system design topics. Adjust the following guide based on your timeline, experience, what positions you are interviewing for, and which companies you are interviewing with.
面试会很宽泛的展开并在几个领域深入。这回帮助你了解一些关于系统设计的不同的主题。基于你的时间线,经验,面试的职位和面试的公司对下面的指导做出适当的调整。
* **Short timeline** - Aim for **breadth** with system design topics. Practice by solving **some** interview questions. * **Short timeline** - Aim for **breadth** with system design topics. Practice by solving **some** interview questions.
* **短期** - 以系统设计主题的**广度**为目标。通过解决**一些**面试题来练习。
* **Medium timeline** - Aim for **breadth** and **some depth** with system design topics. Practice by solving **many** interview questions. * **Medium timeline** - Aim for **breadth** and **some depth** with system design topics. Practice by solving **many** interview questions.
* **中期** - 以系统设计主题的**广度**和**初级深度**为目标。通过解决**很多**面试题来练习。
* **Long timeline** - Aim for **breadth** and **more depth** with system design topics. Practice by solving **most** interview questions. * **Long timeline** - Aim for **breadth** and **more depth** with system design topics. Practice by solving **most** interview questions.
* **长期** - 以系统设计主题的**广度**和**高级深度**为目标。通过解决**大部分**面试题来联系。
| | Short | Medium | Long | | | 短期 | 中期 | 长期 |
|---|---|---|---| | ---------------------------------------- | ---- | ---- | ---- |
| Read through the [System design topics](#index-of-system-design-topics) to get a broad understanding of how systems work | :+1: | :+1: | :+1: | | 阅读 [系统设计主题](#index-of-system-design-topics) 以获得一个关于系统如何工作的宽泛的认识 | :+1: | :+1: | :+1: |
| Read through a few articles in the [Company engineering blogs](#company-engineering-blogs) for the companies you are interviewing with | :+1: | :+1: | :+1: | | 阅读一些你要面试的 [公司工程博客](#company-engineering-blogs) 的文章 | :+1: | :+1: | :+1: |
| Read through a few [Real world architectures](#real-world-architectures) | :+1: | :+1: | :+1: | | 阅读 [真实世界的架构](#real-world-architectures) | :+1: | :+1: | :+1: |
| Review [How to approach a system design interview question](#how-to-approach-a-system-design-interview-question) | :+1: | :+1: | :+1: | | 复习 [如何处理一个系统设计面试题](#how-to-approach-a-system-design-interview-question) | :+1: | :+1: | :+1: |
| Work through [System design interview questions with solutions](#system-design-interview-questions-with-solutions) | Some | Many | Most | | 完成 [系统设计面试题和答案](#system-design-interview-questions-with-solutions) | 一些 | 很多 | 大部分 |
| Work through [Object-oriented design interview questions with solutions](#object-oriented-design-interview-questions-with-solutions) | Some | Many | Most | | 完成 [面向对象设计面试题和答案](#object-oriented-design-interview-questions-with-solutions) | 一些 | 很多 | 大部分 |
| Review [Additional system design interview questions](#additional-system-design-interview-questions) | Some | Many | Most | | 复习 [其他系统设计面试题和答案](#additional-system-design-interview-questions) | 一些 | 很多 | 大部分 |
## How to approach a system design interview question ## How to approach a system design interview question
## 如何处理一个系统设计面试题
> How to tackle a system design interview question. > How to tackle a system design interview question.
> 如何处理一个系统设计面试题。
The system design interview is an **open-ended conversation**. You are expected to lead it. The system design interview is an **open-ended conversation**. You are expected to lead it.
系统设计面试是一个**开放式的对话**。他们期望你去主导这个对话。
You can use the following steps to guide the discussion. To help solidify this process, work through the [System design interview questions with solutions](#system-design-interview-questions-with-solutions) section using the following steps. You can use the following steps to guide the discussion. To help solidify this process, work through the [System design interview questions with solutions](#system-design-interview-questions-with-solutions) section using the following steps.
你可以使用下面的步骤来指引讨论。为了巩固这个过程,请使用下面的步骤完成 [系统设计面试题和答案](#system-design-interview-questions-with-solutions) 这个章节。
### Step 1: Outline use cases, constraints, and assumptions ### Step 1: Outline use cases, constraints, and assumptions
### 第一步:描述使用场景,约束和假设
Gather requirements and scope the problem. Ask questions to clarify use cases and constraints. Discuss assumptions. Gather requirements and scope the problem. Ask questions to clarify use cases and constraints. Discuss assumptions.
把所有需要的东西聚集在一起,审视问题。不停的提问,以至于我们可以明确使用场景和约束。讨论假设。
* Who is going to use it? * Who is going to use it?
* How are they going to use it? * How are they going to use it?
@ -226,117 +289,151 @@ Gather requirements and scope the problem. Ask questions to clarify use cases a
* How much data do we expect to handle? * How much data do we expect to handle?
* How many requests per second do we expect? * How many requests per second do we expect?
* What is the expected read to write ratio? * What is the expected read to write ratio?
* 谁会使用它?
* 他们会怎样使用它?
* 有多少用户?
* 系统的作用是什么?
* 系统的输入输出分别是什么?
* 我们希望处理多少数据?
* 我们希望每秒钟处理多少请求?
* 我们希望的读写比率?
### Step 2: Create a high level design ### Step 2: Create a high level design
### 第二步:创造一个高级的设计
Outline a high level design with all important components. Outline a high level design with all important components.
使用所有重要的组件来描绘出一个高级的设计。
* Sketch the main components and connections * Sketch the main components and connections
* Justify your ideas * Justify your ideas
* 画出主要的组件和连接
* 证明你的想法
### Step 3: Design core components ### Step 3: Design core components
### 第三步:设计核心组件
Dive into details for each core component. For example, if you were asked to [design a url shortening service](solutions/system_design/pastebin/README.md), discuss: Dive into details for each core component. For example, if you were asked to [design a url shortening service](solutions/system_design/pastebin/README.md), discuss:
对每一个核心组件进行详细深入的分析。举例来说,如果你背问到 [设计一个 url 缩写服务](solutions/system_design/pastebin/README.md),开始讨论:
* Generating and storing a hash of the full url * Generating and storing a hash of the full url
* [MD5](solutions/system_design/pastebin/README.md) and [Base62](solutions/system_design/pastebin/README.md) * 生成并储存一个完整 url 的 hash
* Hash collisions * [MD5](solutions/system_design/pastebin/README.md) 和 [Base62](solutions/system_design/pastebin/README.md)
* SQL or NoSQL * Hash 碰撞
* Database schema * SQL 还是 NoSQL
* 数据库模型
* Translating a hashed url to the full url * Translating a hashed url to the full url
* Database lookup * 将一个 hashed url 翻译成完整的 url
* 数据库查找
* API and object-oriented design * API and object-oriented design
* API 和面向对象设计
### Step 4: Scale the design ### Step 4: Scale the design
### 第四步:度量设计
Identify and address bottlenecks, given the constraints. For example, do you need the following to address scalability issues? Identify and address bottlenecks, given the constraints. For example, do you need the following to address scalability issues?
确认和处理瓶颈以及一些限制。举例来说就是你需要下面的这些来完成拓展性的议题吗?
* Load balancer * Load balancer
* Horizontal scaling * Horizontal scaling
* Caching * Caching
* Database sharding * Database sharding
* 负载均衡
* 水平拓展
* 缓存
* 数据库分片
Discuss potential solutions and trade-offs. Everything is a trade-off. Address bottlenecks using [principles of scalable system design](#index-of-system-design-topics). Discuss potential solutions and trade-offs. Everything is a trade-off. Address bottlenecks using [principles of scalable system design](#index-of-system-design-topics).
论述可能的解决办法和代价。每件事情需要取舍。可以使用 [可拓展系统的设计原则](#index-of-system-design-topics) 来处理瓶颈。
### Back-of-the-envelope calculations ### Back-of-the-envelope calculations
### 信封背面的计算
You might be asked to do some estimates by hand. Refer to the [Appendix](#appendix) for the following resources: You might be asked to do some estimates by hand. Refer to the [Appendix](#appendix) for the following resources:
你或许会被要求通过手算进行一些估算。涉及到的 [附录](#appendix) 涉及到的是下面的这些资源:
* [Use back of the envelope calculations](http://highscalability.com/blog/2011/1/26/google-pro-tip-use-back-of-the-envelope-calculations-to-choo.html) * [使用信封的背面做计算](http://highscalability.com/blog/2011/1/26/google-pro-tip-use-back-of-the-envelope-calculations-to-choo.html)
* [Powers of two table](#powers-of-two-table) * [两张表的威力](#powers-of-two-table)
* [Latency numbers every programmer should know](#latency-numbers-every-programmer-should-know) * [每一位程序员都应该知道的数字误差](#latency-numbers-every-programmer-should-know)
### Source(s) and further reading ### Source(s) and further reading
### 源码以及查看更多
Check out the following links to get a better idea of what to expect: Check out the following links to get a better idea of what to expect:
查看下面的链接以获得我们期望的更好的想法:
* [How to ace a systems design interview](https://www.palantir.com/2011/10/how-to-rock-a-systems-design-interview/) * [怎样通过一个系统设计面试](https://www.palantir.com/2011/10/how-to-rock-a-systems-design-interview/)
* [The system design interview](http://www.hiredintech.com/system-design) * [系统设计面试](http://www.hiredintech.com/system-design)
* [Intro to Architecture and Systems Design Interviews](https://www.youtube.com/watch?v=ZgdS0EUmn70) * [系统架构与设计面试简介](https://www.youtube.com/watch?v=ZgdS0EUmn70)
## System design interview questions with solutions ## System design interview questions with solutions
## 系统设计面试题和答案
> Common system design interview questions with sample discussions, code, and diagrams. > Common system design interview questions with sample discussions, code, and diagrams.
> >
> Solutions linked to content in the `solutions/` folder. > Solutions linked to content in the `solutions/` folder.
> 普通的系统设计面试题和相关事例的论述,代码和图表。
>
> 答案链接到 `solutions/` 文件夹中的内容中。
>
| 问题 | |
| ---------------------------------------- | ---------------------------------------- |
| 设计 Pastebin.com (或者 Bit.ly) | [答案](solutions/system_design/pastebin/README.md) |
| 设计 Twitter 时间线和搜索 (或者 Facebook feed 和搜索) | [答案](solutions/system_design/twitter/README.md) |
| 设计一个网页爬虫 | [答案](solutions/system_design/web_crawler/README.md) |
| 设计 Mint.com | [答案](solutions/system_design/mint/README.md) |
| 为一个社交网络设计数据结构 | [答案](solutions/system_design/social_graph/README.md) |
| 为搜索引擎设计一个 key-value 储存 | [答案](solutions/system_design/query_cache/README.md) |
| 通过分类特性设计 Amazon 的销售排名 | [答案](solutions/system_design/sales_rank/README.md) |
| 在 AWS 上设计一个百万用户级别的系统 | [答案](solutions/system_design/scaling_aws/README.md) |
| 添加一个系统设计问题 | [贡献](#contributing) |
| Question | | ### 设计 Pastebin.com (或者 Bit.ly)
|---|---|
| Design Pastebin.com (or Bit.ly) | [Solution](solutions/system_design/pastebin/README.md) |
| Design the Twitter timeline (or Facebook feed)<br/>Design Twitter search (or Facebook search) | [Solution](solutions/system_design/twitter/README.md) |
| Design a web crawler | [Solution](solutions/system_design/web_crawler/README.md) |
| Design Mint.com | [Solution](solutions/system_design/mint/README.md) |
| Design the data structures for a social network | [Solution](solutions/system_design/social_graph/README.md) |
| Design a key-value store for a search engine | [Solution](solutions/system_design/query_cache/README.md) |
| Design Amazon's sales ranking by category feature | [Solution](solutions/system_design/sales_rank/README.md) |
| Design a system that scales to millions of users on AWS | [Solution](solutions/system_design/scaling_aws/README.md) |
| Add a system design question | [Contribute](#contributing) |
### Design Pastebin.com (or Bit.ly) [查看练习和答案](solutions/system_design/pastebin/README.md)
[View exercise and solution](solutions/system_design/pastebin/README.md)
![Imgur](http://i.imgur.com/4edXG0T.png) ![Imgur](http://i.imgur.com/4edXG0T.png)
### Design the Twitter timeline and search (or Facebook feed and search) ### 设计 Twitter 时间线和搜索 (或者 Facebook feed 和搜索)
[View exercise and solution](solutions/system_design/twitter/README.md) [查看练习和答案](solutions/system_design/twitter/README.md)
![Imgur](http://i.imgur.com/jrUBAF7.png) ![Imgur](http://i.imgur.com/jrUBAF7.png)
### Design a web crawler ### 设计一个网页爬虫
[View exercise and solution](solutions/system_design/web_crawler/README.md) [查看练习和答案](solutions/system_design/web_crawler/README.md)
![Imgur](http://i.imgur.com/bWxPtQA.png) ![Imgur](http://i.imgur.com/bWxPtQA.png)
### Design Mint.com ### 设计 Mint.com
[View exercise and solution](solutions/system_design/mint/README.md) [查看练习和答案](solutions/system_design/mint/README.md)
![Imgur](http://i.imgur.com/V5q57vU.png) ![Imgur](http://i.imgur.com/V5q57vU.png)
### Design the data structures for a social network ### 为一个社交网络设计数据结构
[View exercise and solution](solutions/system_design/social_graph/README.md) [查看练习和答案](solutions/system_design/social_graph/README.md)
![Imgur](http://i.imgur.com/cdCv5g7.png) ![Imgur](http://i.imgur.com/cdCv5g7.png)
### Design a key-value store for a search engine ### 为搜索引擎设计一个 key-value 储存
[View exercise and solution](solutions/system_design/query_cache/README.md) [查看练习和答案](solutions/system_design/query_cache/README.md)
![Imgur](http://i.imgur.com/4j99mhe.png) ![Imgur](http://i.imgur.com/4j99mhe.png)
### Design Amazon's sales ranking by category feature ### Design Amazon's sales ranking by category feature
### 通过分类特性设计 Amazon 的销售排名
[View exercise and solution](solutions/system_design/sales_rank/README.md) [查看练习和答案](solutions/system_design/sales_rank/README.md)
![Imgur](http://i.imgur.com/MzExP06.png) ![Imgur](http://i.imgur.com/MzExP06.png)
### Design a system that scales to millions of users on AWS ### Design a system that scales to millions of users on AWS
### 在 AWS 上设计一个百万用户级别的系统
[View exercise and solution](solutions/system_design/scaling_aws/README.md) [查看练习和答案](solutions/system_design/scaling_aws/README.md)
![Imgur](http://i.imgur.com/jj3A5N8.png) ![Imgur](http://i.imgur.com/jj3A5N8.png)
@ -349,7 +446,7 @@ Check out the following links to get a better idea of what to expect:
>**Note: This section is under development** >**Note: This section is under development**
| Question | | | Question | |
|---|---| | -------------------------------------- | ---------------------------------------- |
| Design a hash map | [Solution](solutions/object_oriented_design/hash_table/hash_map.ipynb) | | Design a hash map | [Solution](solutions/object_oriented_design/hash_table/hash_map.ipynb) |
| Design a least recently used cache | [Solution](solutions/object_oriented_design/lru_cache/lru_cache.ipynb) | | Design a least recently used cache | [Solution](solutions/object_oriented_design/lru_cache/lru_cache.ipynb) |
| Design a call center | [Solution](solutions/object_oriented_design/call_center/call_center.ipynb) | | Design a call center | [Solution](solutions/object_oriented_design/call_center/call_center.ipynb) |
@ -1327,7 +1424,7 @@ HTTP is a method for encoding and transporting data between a client and a serve
A basic HTTP request consists of a verb (method) and a resource (endpoint). Below are common HTTP verbs: A basic HTTP request consists of a verb (method) and a resource (endpoint). Below are common HTTP verbs:
| Verb | Description | Idempotent* | Safe | Cacheable | | Verb | Description | Idempotent* | Safe | Cacheable |
|---|---|---|---|---| | ------ | ---------------------------------------- | ----------- | ---- | --------------------------------------- |
| GET | Reads a resource | Yes | Yes | Yes | | GET | Reads a resource | Yes | Yes | Yes |
| POST | Creates a resource or trigger a process that handles data | No | No | Yes if response contains freshness info | | POST | Creates a resource or trigger a process that handles data | No | No | Yes if response contains freshness info |
| PUT | Creates or replace a resource | Yes | No | No | | PUT | Creates or replace a resource | Yes | No | No |
@ -1475,7 +1572,7 @@ REST is focused on exposing data. It minimizes the coupling between client/serv
### RPC and REST calls comparison ### RPC and REST calls comparison
| Operation | RPC | REST | | Operation | RPC | REST |
|---|---|---| | ------------------------------- | ---------------------------------------- | ---------------------------------------- |
| Signup | **POST** /signup | **POST** /persons | | Signup | **POST** /signup | **POST** /persons |
| Resign | **POST** /resign<br/>{<br/>"personid": "1234"<br/>} | **DELETE** /persons/1234 | | Resign | **POST** /resign<br/>{<br/>"personid": "1234"<br/>} | **DELETE** /persons/1234 |
| Read a person | **GET** /readPerson?personid=1234 | **GET** /persons/1234 | | Read a person | **GET** /readPerson?personid=1234 | **GET** /persons/1234 |
@ -1591,7 +1688,7 @@ Handy metrics based on numbers above:
> Common system design interview questions, with links to resources on how to solve each. > Common system design interview questions, with links to resources on how to solve each.
| Question | Reference(s) | | Question | Reference(s) |
|---|---| | ---------------------------------------- | ---------------------------------------- |
| Design a file sync service like Dropbox | [youtube.com](https://www.youtube.com/watch?v=PE4gwstWhmc) | | Design a file sync service like Dropbox | [youtube.com](https://www.youtube.com/watch?v=PE4gwstWhmc) |
| Design a search engine like Google | [queue.acm.org](http://queue.acm.org/detail.cfm?id=988407)<br/>[stackexchange.com](http://programmers.stackexchange.com/questions/38324/interview-question-how-would-you-implement-google-search)<br/>[ardendertat.com](http://www.ardendertat.com/2012/01/11/implementing-search-engines/)<br>[stanford.edu](http://infolab.stanford.edu/~backrub/google.html) | | Design a search engine like Google | [queue.acm.org](http://queue.acm.org/detail.cfm?id=988407)<br/>[stackexchange.com](http://programmers.stackexchange.com/questions/38324/interview-question-how-would-you-implement-google-search)<br/>[ardendertat.com](http://www.ardendertat.com/2012/01/11/implementing-search-engines/)<br>[stanford.edu](http://infolab.stanford.edu/~backrub/google.html) |
| Design a scalable web crawler like Google | [quora.com](https://www.quora.com/How-can-I-build-a-web-crawler-from-scratch) | | Design a scalable web crawler like Google | [quora.com](https://www.quora.com/How-can-I-build-a-web-crawler-from-scratch) |
@ -1632,7 +1729,7 @@ Handy metrics based on numbers above:
* Review the lessons learned * Review the lessons learned
| Type | System | Reference(s) | | Type | System | Reference(s) |
|---|---|---| | --------------- | ---------------------------------------- | ---------------------------------------- |
| Data processing | **MapReduce** - Distributed data processing from Google | [research.google.com](http://static.googleusercontent.com/media/research.google.com/zh-CN/us/archive/mapreduce-osdi04.pdf) | | Data processing | **MapReduce** - Distributed data processing from Google | [research.google.com](http://static.googleusercontent.com/media/research.google.com/zh-CN/us/archive/mapreduce-osdi04.pdf) |
| Data processing | **Spark** - Distributed data processing from Databricks | [slideshare.net](http://www.slideshare.net/AGrishchenko/apache-spark-architecture) | | Data processing | **Spark** - Distributed data processing from Databricks | [slideshare.net](http://www.slideshare.net/AGrishchenko/apache-spark-architecture) |
| Data processing | **Storm** - Distributed data processing from Twitter | [slideshare.net](http://www.slideshare.net/previa/storm-16094009) | | Data processing | **Storm** - Distributed data processing from Twitter | [slideshare.net](http://www.slideshare.net/previa/storm-16094009) |
@ -1658,7 +1755,7 @@ Handy metrics based on numbers above:
### Company architectures ### Company architectures
| Company | Reference(s) | | Company | Reference(s) |
|---|---| | -------------- | ---------------------------------------- |
| Amazon | [Amazon architecture](http://highscalability.com/amazon-architecture) | | Amazon | [Amazon architecture](http://highscalability.com/amazon-architecture) |
| Cinchcast | [Producing 1,500 hours of audio every day](http://highscalability.com/blog/2012/7/16/cinchcast-architecture-producing-1500-hours-of-audio-every-d.html) | | Cinchcast | [Producing 1,500 hours of audio every day](http://highscalability.com/blog/2012/7/16/cinchcast-architecture-producing-1500-hours-of-audio-every-d.html) |
| DataSift | [Realtime datamining At 120,000 tweets per second](http://highscalability.com/blog/2011/11/29/datasift-architecture-realtime-datamining-at-120000-tweets-p.html) | | DataSift | [Realtime datamining At 120,000 tweets per second](http://highscalability.com/blog/2011/11/29/datasift-architecture-realtime-datamining-at-120000-tweets-p.html) |