From f17998e1767e2e2fbe19387e0c7d9cc5b9e9e6f4 Mon Sep 17 00:00:00 2001 From: jfxu Date: Fri, 31 Mar 2017 16:36:44 +0800 Subject: [PATCH 01/16] =?UTF-8?q?=E7=AC=AC=E4=BA=94=E9=83=A8=E5=88=86?= =?UTF-8?q?=E7=BF=BB=E8=AF=91=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README-zh-Hant.md | 365 +++++++++++++++++++++++----------------------- 1 file changed, 181 insertions(+), 184 deletions(-) diff --git a/README-zh-Hant.md b/README-zh-Hant.md index defa77ef..ed562327 100644 --- a/README-zh-Hant.md +++ b/README-zh-Hant.md @@ -196,15 +196,15 @@ Start broad and go deeper in a few areas. It helps to know a little about vario * **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. -| | 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: | -| Read through a few articles in the [Company engineering blogs](#company-engineering-blogs) for the companies you are interviewing with | :+1: | :+1: | :+1: | -| Read through a few [Real world architectures](#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: | -| Work through [System design interview questions with solutions](#system-design-interview-questions-with-solutions) | Some | Many | Most | -| Work through [Object-oriented design interview questions with solutions](#object-oriented-design-interview-questions-with-solutions) | Some | Many | Most | -| Review [Additional system design interview questions](#additional-system-design-interview-questions) | Some | Many | Most | +| | 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: | +| Read through a few articles in the [Company engineering blogs](#company-engineering-blogs) for the companies you are interviewing with | :+1: | :+1: | :+1: | +| Read through a few [Real world architectures](#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: | +| Work through [System design interview questions with solutions](#system-design-interview-questions-with-solutions) | Some | Many | Most | +| Work through [Object-oriented design interview questions with solutions](#object-oriented-design-interview-questions-with-solutions) | Some | Many | Most | +| Review [Additional system design interview questions](#additional-system-design-interview-questions) | Some | Many | Most | ## How to approach a system design interview question @@ -280,17 +280,17 @@ Check out the following links to get a better idea of what to expect: > > Solutions linked to content in the `solutions/` folder. -| Question | | -|---|---| -| Design Pastebin.com (or Bit.ly) | [Solution](solutions/system_design/pastebin/README.md) | +| Question | | +| ---------------------------------------- | ---------------------------------------- | +| Design Pastebin.com (or Bit.ly) | [Solution](solutions/system_design/pastebin/README.md) | | Design the Twitter timeline (or Facebook feed)
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 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) | +| Add a system design question | [Contribute](#contributing) | ### Design Pastebin.com (or Bit.ly) @@ -348,16 +348,16 @@ Check out the following links to get a better idea of what to expect: >**Note: This section is under development** -| Question | | -|---|---| -| 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 call center | [Solution](solutions/object_oriented_design/call_center/call_center.ipynb) | -| Design a deck of cards | [Solution](solutions/object_oriented_design/deck_of_cards/deck_of_cards.ipynb) | -| Design a parking lot | [Solution](solutions/object_oriented_design/parking_lot/parking_lot.ipynb) | -| Design a chat server | [Solution](solutions/object_oriented_design/online_chat/online_chat.ipynb) | -| Design a circular array | [Contribute](#contributing) | -| Add an object-oriented design question | [Contribute](#contributing) | +| Question | | +| -------------------------------------- | ---------------------------------------- | +| 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 call center | [Solution](solutions/object_oriented_design/call_center/call_center.ipynb) | +| Design a deck of cards | [Solution](solutions/object_oriented_design/deck_of_cards/deck_of_cards.ipynb) | +| Design a parking lot | [Solution](solutions/object_oriented_design/parking_lot/parking_lot.ipynb) | +| Design a chat server | [Solution](solutions/object_oriented_design/online_chat/online_chat.ipynb) | +| Design a circular array | [Contribute](#contributing) | +| Add an object-oriented design question | [Contribute](#contributing) | ## System design topics: start here @@ -1326,13 +1326,13 @@ 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: -| Verb | Description | Idempotent* | Safe | Cacheable | -|---|---|---|---|---| -| 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 | -| PUT | Creates or replace a resource | Yes | No | No | -| PATCH | Partially updates a resource | No | No | Yes if response contains freshness info | -| DELETE | Deletes a resource | Yes | No | No | +| Verb | Description | Idempotent* | Safe | Cacheable | +| ------ | ---------------------------------------- | ----------- | ---- | --------------------------------------- | +| 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 | +| PUT | Creates or replace a resource | Yes | No | No | +| PATCH | Partially updates a resource | No | No | Yes if response contains freshness info | +| DELETE | Deletes a resource | Yes | No | No | *Can be called many times without different outcomes. @@ -1365,7 +1365,7 @@ Use TCP over UDP when: * You need all of the data to arrive intact * You want to automatically make a best estimate use of the network throughput -### User datagram protocol (UDP) +### 用户数据报协议(UDP)

@@ -1373,19 +1373,19 @@ Use TCP over UDP when: Source: How to make a multiplayer game

-UDP is connectionless. Datagrams (analogous to packets) are guaranteed only at the datagram level. Datagrams might reach their destination out of order or not at all. UDP does not support congestion control. Without the guarantees that TCP support, UDP is generally more efficient. +UDP 是无连接的。数据报(类似于数据包)只在数据报级别有保证。数据报可能会无序的到达目的地,也有可能会遗失。UDP 不支持拥塞控制。虽然不如 TCP 那样有保证,但 UDP 通常效率更高。 -UDP can broadcast, sending datagrams to all devices on the subnet. This is useful with [DHCP](https://en.wikipedia.org/wiki/Dynamic_Host_Configuration_Protocol) because the client has not yet received an IP address, thus preventing a way for TCP to stream without the IP address. +UDP 可以通过广播将数组报发送至子网内的所有设备。这对 [DHCP](https://en.wikipedia.org/wiki/Dynamic_Host_Configuration_Protocol) 很有用,因为子网内的设备还没有分配 IP 地址,而 IP 对于 TCP 是必须的。 -UDP is less reliable but works well in real time use cases such as VoIP, video chat, streaming, and realtime multiplayer games. +UDP 可靠性更低但适合用在网络电话、视频聊天,流(这个不知具体指啥)和实时多人游戏上。 -Use UDP over TCP when: +以下情况使用 UDP 代替 TCP: -* You need the lowest latency -* Late data is worse than loss of data -* You want to implement your own error correction +* 你需要更快的相应速度 +* 相对于数据丢失更糟的是数据延迟 +* 你想实现自己的错误校正方法 -#### Source(s) and further reading: TCP and UDP +#### 延伸阅读:TCP 与 UDP * [Networking for game programming](http://gafferongames.com/networking-for-game-programmers/udp-vs-tcp/) * [Key differences between TCP and UDP protocols](http://www.cyberciti.biz/faq/key-differences-between-tcp-and-udp-protocols/) @@ -1394,7 +1394,7 @@ Use UDP over TCP when: * [User datagram protocol](https://en.wikipedia.org/wiki/User_Datagram_Protocol) * [Scaling memcache at Facebook](http://www.cs.bu.edu/~jappavoo/jappavoo.github.com/451/papers/memcache-fb.pdf) -### Remote procedure call (RPC) +### 远程过程调用协议(RPC)

@@ -1402,18 +1402,17 @@ Use UDP over TCP when: Source: Crack the system design interview

-In an RPC, a client causes a procedure to execute on a different address space, usually a remote server. The procedure is coded as if it were a local procedure call, abstracting away the details of how to communicate with the server from the client program. Remote calls are usually slower and less reliable than local calls so it is helpful to distinguish RPC calls from local calls. Popular RPC frameworks include [Protobuf](https://developers.google.com/protocol-buffers/), [Thrift](https://thrift.apache.org/), and [Avro](https://avro.apache.org/docs/current/). +在一个 RPC 里,客户端会去调用另一个地址空间(通常是一个远程服务器)里的方法。调用代码看起来就像是调用的是一个本地方法,客户端和服务器交互的具体过程被抽象。远程调用相对于本地调用一般较慢而且可靠性更差,因此区分两者是有帮助的。热门的 RPC 框架包括 [Protobuf](https://developers.google.com/protocol-buffers/), [Thrift](https://thrift.apache.org/) 和 [Avro](https://avro.apache.org/docs/current/)。 -RPC is a request-response protocol: +RPC 是一个“请求-响应”协议: -* **Client program** - Calls the client stub procedure. The parameters are pushed onto the stack like a local procedure call. -* **Client stub procedure** - Marshals (packs) procedure id and arguments into a request message. -* **Client communication module** - OS sends the message from the client to the server. -* **Server communication module** - OS passes the incoming packets to the server stub procedure. -* **Server stub procedure** - Unmarshalls the results, calls the server procedure matching the procedure id and passes the given arguments. -* The server response repeats the steps above in reverse order. +* **客户端程序** ── 调用客户端存根程序。就像调用本地方法一样,参数会被压入栈中。 +* **客户端存根程序** ── 将请求过程的 id 和参数打包进请求信息中。 +* **客户端通信模块** ── 将信息从客户端发送至服务端。 +* **服务端通信模块** ── 将接受的包传给服务端存根程序。 +* **服务端存根程序** ── 将结果解包,依据过程 id 调用服务端方法并将参数传递过去。 -Sample RPC calls: +RPC 调用示例: ``` GET /someoperation?data=anId @@ -1425,36 +1424,37 @@ POST /anotheroperation } ``` -RPC is focused on exposing behaviors. RPCs are often used for performance reasons with internal communications, as you can hand-craft native calls to better fit your use cases. +RPC 专注于暴露方法。RPC 通常用于处理内部通讯的性能问题,这样你可以手动处理本地调用以更好的适应你的情况。 -Choose a Native Library aka SDK when: -* You know your target platform. -* You want to control how your "logic" is accessed -* You want to control how error control happens off your library -* Performance and end user experience is your primary concern +当以下情况时选择本地库或者 SDK: -HTTP APIs following **REST** tend to be used more often for public APIs. +* 你知道你的目标平台。 +* 你想控制如何访问你的“逻辑”。 +* 你想对发生在你的库中的错误进行控制。 +* 性能和终端用户体验是你最关心的事。 -#### Disadvantage(s): RPC +遵循 **REST** 的 HTTP API 往往更适用于公共 API。 -* RPC clients become tightly coupled to the service implementation. -* A new API must be defined for every new operation or use case. -* It can be difficult to debug RPC. -* You might not be able to leverage existing technologies out of the box. For example, it might require additional effort to ensure [RPC calls are properly cached](http://etherealbits.com/2012/12/debunking-the-myths-of-rpc-rest/) on caching servers such as [Squid](http://www.squid-cache.org/). +#### 缺点:RPC -### Representational state transfer (REST) +* RPC 客户端与服务实现捆绑地很紧密。 +* 一个新的 API 必须在每一个操作或者用例中定义。 +* RPC 很难调试。 +* 你可能没办法很方便的去修改现有的技术。举个例子,如果你希望在 [Squid](http://www.squid-cache.org/) 这样的缓存服务器上确保 [RPC 被正确缓存](http://etherealbits.com/2012/12/debunking-the-myths-of-rpc-rest/)的话可能需要一些额外的努力了。 -REST is an architectural style enforcing a client/server model where the client acts on a set of resources managed by the server. The server provides a representation of resources and actions that can either manipulate or get a new representation of resources. All communication must be stateless and cacheable. +### 具象状态传输(REST) -There are four qualities of a RESTful interface: +REST 是一种强制的客户端/服务端架构设计模型,客户端基于服务端管理的一系列资源操作。服务端提供修改或获取资源的接口。所有的通信必须是无状态和可缓存的。 -* **Identify resources (URI in HTTP)** - use the same URI regardless of any operation. -* **Change with representations (Verbs in HTTP)** - use verbs, headers, and body. -* **Self-descriptive error message (status response in HTTP)** - Use status codes, don't reinvent the wheel. -* **[HATEOAS](http://restcookbook.com/Basics/hateoas/) (HTML interface for HTTP)** - your web service should be fully accessible in a browser. +RESTful 接口有四条规则: -Sample REST calls: +* **标志资源(HTTP 里的 URI)** ── 无论什么操作都使用同一个 URI。 +* **表示的改变(HTTP 的 Verbs)** ── 使用 verbs, headers 和 body。 +* **可自我描述的错误信息(HTTP 中的 状态相应)** ── 使用状态码,不要重新造轮子。 +* **[HATEOAS](http://restcookbook.com/Basics/hateoas/)(HTTP 中的HTML 接口)** ── 你的 web 服务器应该能够通过浏览器访问。 + +REST 请求的例子: ``` GET /someresources/anId @@ -1463,32 +1463,32 @@ PUT /someresources/anId {"anotherdata": "another value"} ``` -REST is focused on exposing data. It minimizes the coupling between client/server and is often used for public HTTP APIs. REST uses a more generic and uniform method of exposing resources through URIs, [representation through headers](https://github.com/for-GET/know-your-http-well/blob/master/headers.md), and actions through verbs such as GET, POST, PUT, DELETE, and PATCH. Being stateless, REST is great for horizontal scaling and partitioning. +REST 关注于暴露数据。它最小化了客户端与服务端的联系并经常被用户公共 HTTP API。REST 使用更通常与规范化的方法来通过 URI 暴露资源,[通过 header 来表述](https://github.com/for-GET/know-your-http-well/blob/master/headers.md)并通过 GET, POST, PUT, DELETE 和 PATCH 这些 verbs 来进行操作。因为无状态的特性,REST 易于横向扩展和隔离。 -#### Disadvantage(s): REST +#### 缺点:REST -* With REST being focused on exposing data, it might not be a good fit if resources are not naturally organized or accessed in a simple hierarchy. For example, returning all updated records from the past hour matching a particular set of events is not easily expressed as a path. With REST, it is likely to be implemented with a combination of URI path, query parameters, and possibly the request body. -* REST typically relies on a few verbs (GET, POST, PUT, DELETE, and PATCH) which sometimes doesn't fit your use case. For example, moving expired documents to the archive folder might not cleanly fit within these verbs. -* Fetching complicated resources with nested hierarchies requires multiple round trips between the client and server to render single views, e.g. fetching content of a blog entry and the comments on that entry. For mobile applications operating in variable network conditions, these multiple roundtrips are highly undesirable. -* Over time, more fields might be added to an API response and older clients will receive all new data fields, even those that they do not need, as a result, it bloats the payload size and leads to larger latencies. +* 由于 REST 将重点放在暴露数据,所以当资源不是自然组织的或者结构复杂的时候它可能无法很好的适应。举个例子,返回过去一小时中与特定事件集匹配的更新记录这种操作就很难表示为路径。使用 REST,可能会使用 URI 路径,查询参数和可能的请求体来实现。 +* REST 一般依赖几个 verbs(GET, POST, PUT, DELETE 和 PATCH),但有时候仅仅这些没法满足你的需要。举个例子,将过期的文档移动到归档文件夹里去,这样的操作可能没法简单的用上面这几个 verbs 表达。 +* 使用嵌套层次结构来获取复杂资源需要客户端和服务端多次交互来渲染单个视图。比如,获取博客的内容和其下的评论。对于在可变网络环境下的移动应用,是不希望看到这种多次请求。 +* 随着时间的推移,更多的字段可能会被添加到 API 响应中,较旧的客户端将会接收到所有新的数据字段,即使是那些它们不需要的字段,结果它会增加负载大小并引起更大的延迟。 -### RPC and REST calls comparison +### PRC 与 REST 比较 -| Operation | RPC | REST | -|---|---|---| -| Signup | **POST** /signup | **POST** /persons | -| Resign | **POST** /resign
{
"personid": "1234"
} | **DELETE** /persons/1234 | -| Read a person | **GET** /readPerson?personid=1234 | **GET** /persons/1234 | -| Read a person’s items list | **GET** /readUsersItemsList?personid=1234 | **GET** /persons/1234/items | +| 操作 | RPC | REST | +| ------------------------------- | ---------------------------------------- | ---------------------------------------- | +| Signup | **POST** /signup | **POST** /persons | +| Resign | **POST** /resign
{
"personid": "1234"
} | **DELETE** /persons/1234 | +| Read a person | **GET** /readPerson?personid=1234 | **GET** /persons/1234 | +| Read a person’s items list | **GET** /readUsersItemsList?personid=1234 | **GET** /persons/1234/items | | Add an item to a person’s items | **POST** /addItemToUsersItemsList
{
"personid": "1234";
"itemid": "456"
} | **POST** /persons/1234/items
{
"itemid": "456"
} | -| Update an item | **POST** /modifyItem
{
"itemid": "456";
"key": "value"
} | **PUT** /items/456
{
"key": "value"
} | -| Delete an item | **POST** /removeItem
{
"itemid": "456"
} | **DELETE** /items/456 | +| Update an item | **POST** /modifyItem
{
"itemid": "456";
"key": "value"
} | **PUT** /items/456
{
"key": "value"
} | +| Delete an item | **POST** /removeItem
{
"itemid": "456"
} | **DELETE** /items/456 |

Source: Do you really know why you prefer REST over RPC

-#### Source(s) and further reading: REST and RPC +#### 延伸阅读:REST 与 RPC * [Do you really know why you prefer REST over RPC](https://apihandyman.io/do-you-really-know-why-you-prefer-rest-over-rpc/) * [When are RPC-ish approaches more appropriate than REST?](http://programmers.stackexchange.com/a/181186) @@ -1499,27 +1499,27 @@ REST is focused on exposing data. It minimizes the coupling between client/serv * [Thrift](https://code.facebook.com/posts/1468950976659943/) * [Why REST for internal use and not RPC](http://arstechnica.com/civis/viewtopic.php?t=1190508) -## Security +## 安全 -This section could use some updates. Consider [contributing](#contributing)! +这一部分需要更多内容。[一起来吧](#contributing)! -Security is a broad topic. Unless you have considerable experience, a security background, or are applying for a position that requires knowledge of security, you probably won't need to know more than the basics: +安全是一个宽泛的话题。下面这些知识对你应该足够了除非你有很多的经验、安全背景或者你正在申请一个需要安全知识的职位。 -* Encrypt in transit and at rest. -* Sanitize all user inputs or any input parameters exposed to user to prevent [XSS](https://en.wikipedia.org/wiki/Cross-site_scripting) and [SQL injection](https://en.wikipedia.org/wiki/SQL_injection). -* Use parameterized queries to prevent SQL injection. -* Use the principle of [least privilege](https://en.wikipedia.org/wiki/Principle_of_least_privilege). +* 在运输和等待过程中加密 +* 对所有的用户输入和从用户那里发来的参数进行处理以防止 [XSS](https://en.wikipedia.org/wiki/Cross-site_scripting) 和 [SQL 注入](https://en.wikipedia.org/wiki/SQL_injection)。 +* 使用参数化的查询来防止 SQL 注入。 +* 使用[最小权限原则](https://en.wikipedia.org/wiki/Principle_of_least_privilege)。 -### Source(s) and further reading +### 延伸阅读 * [Security guide for developers](https://github.com/FallibleInc/security-guide-for-developers) * [OWASP top ten](https://www.owasp.org/index.php/OWASP_Top_Ten_Cheat_Sheet) -## Appendix +## 附录 -You'll sometimes be asked to do 'back-of-the-envelope' estimates. For example, you might need to determine how long it will take to generate 100 image thumbnails from disk or how much memory a data structure will take. The **Powers of two table** and **Latency numbers every programmer should know** are handy references. +一些时候你会被要求做出保守估计。比如,你可能需要估计从磁盘中生成 100 张图片的缩略图需要的时间或者一个数据结构需要多少的内存。**2 的次方表**和**每个开发者都需要知道的一些时间数据**(译注:OSChina 上有这篇文章的[译文](https://www.oschina.net/news/30009/every-programmer-should-know))都是一些很方便的参考资料。 -### Powers of two table +### 2 的次方表 ``` Power Exact Value Approx Value Bytes @@ -1534,7 +1534,7 @@ Power Exact Value Approx Value Bytes 40 1,099,511,627,776 1 trillion 1 TB ``` -#### Source(s) and further reading +#### 延伸阅读 * [Powers of two](https://en.wikipedia.org/wiki/Power_of_two) @@ -1566,58 +1566,57 @@ Notes 1 ms = 10^-3 seconds = 1,000 us = 1,000,000 ns ``` -Handy metrics based on numbers above: +基于上述数字的指标: +* 从磁盘以 30 MB/s 的速度顺序读取 +* 以 100 MB/s 从 1 Gbps 的以太网顺序读取 +* 从 SSD 以 1 GB/s 的速度读取 +* 以 4 GB/s 的速度从主存读取 +* 每秒能绕地球 6-7 圈 +* 数据中心内每秒有 2,000 次往返 -* Read sequentially from disk at 30 MB/s -* Read sequentially from 1 Gbps Ethernet at 100 MB/s -* Read sequentially from SSD at 1 GB/s -* Read sequentially from main memory at 4 GB/s -* 6-7 world-wide round trips per second -* 2,000 round trips per second within a data center - -#### Latency numbers visualized +#### 延迟数可视化 ![](https://camo.githubusercontent.com/77f72259e1eb58596b564d1ad823af1853bc60a3/687474703a2f2f692e696d6775722e636f6d2f6b307431652e706e67) -#### Source(s) and further reading +#### 延伸阅读 * [Latency numbers every programmer should know - 1](https://gist.github.com/jboner/2841832) * [Latency numbers every programmer should know - 2](https://gist.github.com/hellerbarde/2843375) * [Designs, lessons, and advice from building large distributed systems](http://www.cs.cornell.edu/projects/ladis2009/talks/dean-keynote-ladis2009.pdf) * [Software Engineering Advice from Building Large-Scale Distributed Systems](https://static.googleusercontent.com/media/research.google.com/en//people/jeff/stanford-295-talk.pdf) -### Additional system design interview questions +### 额外的系统设计面试问题 -> Common system design interview questions, with links to resources on how to solve each. +> 常见的系统设计面试问题,给出了如何解决的方案链接 -| Question | Reference(s) | -|---|---| -| 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)
[stackexchange.com](http://programmers.stackexchange.com/questions/38324/interview-question-how-would-you-implement-google-search)
[ardendertat.com](http://www.ardendertat.com/2012/01/11/implementing-search-engines/)
[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 Google docs | [code.google.com](https://code.google.com/p/google-mobwrite/)
[neil.fraser.name](https://neil.fraser.name/writing/sync/) | -| Design a key-value store like Redis | [slideshare.net](http://www.slideshare.net/dvirsky/introduction-to-redis) | -| Design a cache system like Memcached | [slideshare.net](http://www.slideshare.net/oemebamo/introduction-to-memcached) | -| Design a recommendation system like Amazon's | [hulu.com](http://tech.hulu.com/blog/2011/09/19/recommendation-system.html)
[ijcai13.org](http://ijcai13.org/files/tutorial_slides/td3.pdf) | -| Design a tinyurl system like Bitly | [n00tc0d3r.blogspot.com](http://n00tc0d3r.blogspot.com/) | -| Design a chat app like WhatsApp | [highscalability.com](http://highscalability.com/blog/2014/2/26/the-whatsapp-architecture-facebook-bought-for-19-billion.html) -| Design a picture sharing system like Instagram | [highscalability.com](http://highscalability.com/flickr-architecture)
[highscalability.com](http://highscalability.com/blog/2011/12/6/instagram-architecture-14-million-users-terabytes-of-photos.html) | -| Design the Facebook news feed function | [quora.com](http://www.quora.com/What-are-best-practices-for-building-something-like-a-News-Feed)
[quora.com](http://www.quora.com/Activity-Streams/What-are-the-scaling-issues-to-keep-in-mind-while-developing-a-social-network-feed)
[slideshare.net](http://www.slideshare.net/danmckinley/etsy-activity-feeds-architecture) | -| Design the Facebook timeline function | [facebook.com](https://www.facebook.com/note.php?note_id=10150468255628920)
[highscalability.com](http://highscalability.com/blog/2012/1/23/facebook-timeline-brought-to-you-by-the-power-of-denormaliza.html) | -| Design the Facebook chat function | [erlang-factory.com](http://www.erlang-factory.com/upload/presentations/31/EugeneLetuchy-ErlangatFacebook.pdf)
[facebook.com](https://www.facebook.com/note.php?note_id=14218138919&id=9445547199&index=0) | -| Design a graph search function like Facebook's | [facebook.com](https://www.facebook.com/notes/facebook-engineering/under-the-hood-building-out-the-infrastructure-for-graph-search/10151347573598920)
[facebook.com](https://www.facebook.com/notes/facebook-engineering/under-the-hood-indexing-and-ranking-in-graph-search/10151361720763920)
[facebook.com](https://www.facebook.com/notes/facebook-engineering/under-the-hood-the-natural-language-interface-of-graph-search/10151432733048920) | -| Design a content delivery network like CloudFlare | [cmu.edu](http://repository.cmu.edu/cgi/viewcontent.cgi?article=2112&context=compsci) | -| Design a trending topic system like Twitter's | [michael-noll.com](http://www.michael-noll.com/blog/2013/01/18/implementing-real-time-trending-topics-in-storm/)
[snikolov .wordpress.com](http://snikolov.wordpress.com/2012/11/14/early-detection-of-twitter-trends/) | -| Design a random ID generation system | [blog.twitter.com](https://blog.twitter.com/2010/announcing-snowflake)
[github.com](https://github.com/twitter/snowflake/) | -| Return the top k requests during a time interval | [ucsb.edu](https://icmi.cs.ucsb.edu/research/tech_reports/reports/2005-23.pdf)
[wpi.edu](http://davis.wpi.edu/xmdv/docs/EDBT11-diyang.pdf) | -| Design a system that serves data from multiple data centers | [highscalability.com](http://highscalability.com/blog/2009/8/24/how-google-serves-data-from-multiple-datacenters.html) | -| Design an online multiplayer card game | [indieflashblog.com](http://www.indieflashblog.com/how-to-create-an-asynchronous-multiplayer-game.html)
[buildnewgames.com](http://buildnewgames.com/real-time-multiplayer/) | -| Design a garbage collection system | [stuffwithstuff.com](http://journal.stuffwithstuff.com/2013/12/08/babys-first-garbage-collector/)
[washington.edu](http://courses.cs.washington.edu/courses/csep521/07wi/prj/rick.pdf) | -| Add a system design question | [Contribute](#contributing) | +| 问题 | 引用 | +| --------------------- | ---------------------------------------- | +| 设计类似于 Dropbox 的文件同步服务 | [youtube.com](https://www.youtube.com/watch?v=PE4gwstWhmc) | +| 设计类似于 Google 的搜索引擎 | [queue.acm.org](http://queue.acm.org/detail.cfm?id=988407)
[stackexchange.com](http://programmers.stackexchange.com/questions/38324/interview-question-how-would-you-implement-google-search)
[ardendertat.com](http://www.ardendertat.com/2012/01/11/implementing-search-engines/)
[stanford.edu](http://infolab.stanford.edu/~backrub/google.html) | +| 设计类似于 Google 的可扩展网络爬虫 | [quora.com](https://www.quora.com/How-can-I-build-a-web-crawler-from-scratch) | +| 设计 Google 文档 | [code.google.com](https://code.google.com/p/google-mobwrite/)
[neil.fraser.name](https://neil.fraser.name/writing/sync/) | +| 设计类似 Redis 的建值存储 | [slideshare.net](http://www.slideshare.net/dvirsky/introduction-to-redis) | +| 设计类似 Memcached 的缓存系统 | [slideshare.net](http://www.slideshare.net/oemebamo/introduction-to-memcached) | +| 设计类似亚马逊的推荐系统 | [hulu.com](http://tech.hulu.com/blog/2011/09/19/recommendation-system.html)
[ijcai13.org](http://ijcai13.org/files/tutorial_slides/td3.pdf) | +| 设计类似 Bitly 的短链接系统 | [n00tc0d3r.blogspot.com](http://n00tc0d3r.blogspot.com/) | +| 设计类似 WhatsApp 的聊天应用 | [highscalability.com](http://highscalability.com/blog/2014/2/26/the-whatsapp-architecture-facebook-bought-for-19-billion.html) +| 设计类似 Instagram 的图片分享系统| [highscalability.com](http://highscalability.com/flickr-architecture)
[highscalability.com](http://highscalability.com/blog/2011/12/6/instagram-architecture-14-million-users-terabytes-of-photos.html) | +| 设计 Facebook 的新闻推荐方法 | [quora.com](http://www.quora.com/What-are-best-practices-for-building-something-like-a-News-Feed)
[quora.com](http://www.quora.com/Activity-Streams/What-are-the-scaling-issues-to-keep-in-mind-while-developing-a-social-network-feed)
[slideshare.net](http://www.slideshare.net/danmckinley/etsy-activity-feeds-architecture) | +| 设计 Facebook 的时间线系统 | [facebook.com](https://www.facebook.com/note.php?note_id=10150468255628920)
[highscalability.com](http://highscalability.com/blog/2012/1/23/facebook-timeline-brought-to-you-by-the-power-of-denormaliza.html) | +| 设计 Facebook 的聊天系统 | [erlang-factory.com](http://www.erlang-factory.com/upload/presentations/31/EugeneLetuchy-ErlangatFacebook.pdf)
[facebook.com](https://www.facebook.com/note.php?note_id=14218138919&id=9445547199&index=0) | +| 设计类似 Facebook 的图表搜索系统 | [facebook.com](https://www.facebook.com/notes/facebook-engineering/under-the-hood-building-out-the-infrastructure-for-graph-search/10151347573598920)
[facebook.com](https://www.facebook.com/notes/facebook-engineering/under-the-hood-indexing-and-ranking-in-graph-search/10151361720763920)
[facebook.com](https://www.facebook.com/notes/facebook-engineering/under-the-hood-the-natural-language-interface-of-graph-search/10151432733048920) | +| 设计类似 CloudFlare 的内容传递网络 | [cmu.edu](http://repository.cmu.edu/cgi/viewcontent.cgi?article=2112&context=compsci) | +| 设计类似 Twitter 的热门话题系统 | [michael-noll.com](http://www.michael-noll.com/blog/2013/01/18/implementing-real-time-trending-topics-in-storm/)
[snikolov .wordpress.com](http://snikolov.wordpress.com/2012/11/14/early-detection-of-twitter-trends/) | +| 设计一个随机 ID 生成系统 | [blog.twitter.com](https://blog.twitter.com/2010/announcing-snowflake)
[github.com](https://github.com/twitter/snowflake/) | +| 返回一定时间段内次数前 k 高的请求 | [ucsb.edu](https://icmi.cs.ucsb.edu/research/tech_reports/reports/2005-23.pdf)
[wpi.edu](http://davis.wpi.edu/xmdv/docs/EDBT11-diyang.pdf) | +| 设计一个数据源于多个数据中心的服务系统 | [highscalability.com](http://highscalability.com/blog/2009/8/24/how-google-serves-data-from-multiple-datacenters.html) | +| 设计一个多人网络卡牌游戏 | [indieflashblog.com](http://www.indieflashblog.com/how-to-create-an-asynchronous-multiplayer-game.html)
[buildnewgames.com](http://buildnewgames.com/real-time-multiplayer/) | +| 设计一个垃圾回收系统 | [stuffwithstuff.com](http://journal.stuffwithstuff.com/2013/12/08/babys-first-garbage-collector/)
[washington.edu](http://courses.cs.washington.edu/courses/csep521/07wi/prj/rick.pdf) | +| 添加更多的系统设计问题 | [Contribute](#contributing) | -### Real world architectures +### 真实的设计架构 -> Articles on how real world systems are designed. +> 关于现实中真实的系统是怎么设计的文章。

@@ -1625,20 +1624,20 @@ Handy metrics based on numbers above: Source: Twitter timelines at scale

-**Don't focus on nitty gritty details for the following articles, instead:** +** 不要专注于一下文章的细节,专注于以下方面:** -* Identify shared principles, common technologies, and patterns within these articles -* Study what problems are solved by each component, where it works, where it doesn't -* Review the lessons learned +* 发现这些文章中的共同的原则、技术和模式。 +* 学习每个组件解决哪些问题,什么情况下使用,什么情况下不适用 +* 复习学过的文章 -|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 | **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 store | **Bigtable** - Distributed column-oriented database from Google | [harvard.edu](http://www.read.seas.harvard.edu/~kohler/class/cs239-w08/chang06bigtable.pdf) | -| Data store | **HBase** - Open source implementation of Bigtable | [slideshare.net](http://www.slideshare.net/alexbaranau/intro-to-hbase) | +| | | | +| Data store | **Bigtable** - Distributed column-oriented database from Google | [harvard.edu](http://www.read.seas.harvard.edu/~kohler/class/cs239-w08/chang06bigtable.pdf) | +| Data store | **HBase** - Open source implementation of Bigtable | [slideshare.net](http://www.slideshare.net/alexbaranau/intro-to-hbase) | | Data store | **Cassandra** - Distributed column-oriented database from Facebook | [slideshare.net](http://www.slideshare.net/planetcassandra/cassandra-introduction-features-30103666) | Data store | **DynamoDB** - Document-oriented database from Amazon | [harvard.edu](http://www.read.seas.harvard.edu/~kohler/class/cs239-w08/decandia07dynamo.pdf) | | Data store | **MongoDB** - Document-oriented database | [slideshare.net](http://www.slideshare.net/mdirolf/introduction-to-mongodb) | @@ -1655,38 +1654,38 @@ Handy metrics based on numbers above: | Misc | **Zookeeper** - Centralized infrastructure and services enabling synchronization | [slideshare.net](http://www.slideshare.net/sauravhaloi/introduction-to-apache-zookeeper) | | | Add an architecture | [Contribute](#contributing) | -### Company architectures +### 公司的系统架构 -| Company | Reference(s) | -|---|---| -| 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) | -| 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) | -| DropBox | [How we've scaled Dropbox](https://www.youtube.com/watch?v=PE4gwstWhmc) | -| ESPN | [Operating At 100,000 duh nuh nuhs per second](http://highscalability.com/blog/2013/11/4/espns-architecture-at-scale-operating-at-100000-duh-nuh-nuhs.html) | -| Google | [Google architecture](http://highscalability.com/google-architecture) | -| Instagram | [14 million users, terabytes of photos](http://highscalability.com/blog/2011/12/6/instagram-architecture-14-million-users-terabytes-of-photos.html)
[What powers Instagram](http://instagram-engineering.tumblr.com/post/13649370142/what-powers-instagram-hundreds-of-instances) | -| Justin.tv | [Justin.Tv's live video broadcasting architecture](http://highscalability.com/blog/2010/3/16/justintvs-live-video-broadcasting-architecture.html) | -| Facebook | [Scaling memcached at Facebook](https://cs.uwaterloo.ca/~brecht/courses/854-Emerging-2014/readings/key-value/fb-memcached-nsdi-2013.pdf)
[TAO: Facebook’s distributed data store for the social graph](https://cs.uwaterloo.ca/~brecht/courses/854-Emerging-2014/readings/data-store/tao-facebook-distributed-datastore-atc-2013.pdf)
[Facebook’s photo storage](https://www.usenix.org/legacy/event/osdi10/tech/full_papers/Beaver.pdf) | -| Flickr | [Flickr architecture](http://highscalability.com/flickr-architecture) | -| Mailbox | [From 0 to one million users in 6 weeks](http://highscalability.com/blog/2013/6/18/scaling-mailbox-from-0-to-one-million-users-in-6-weeks-and-1.html) | -| Pinterest | [From 0 To 10s of billions of page views a month](http://highscalability.com/blog/2013/4/15/scaling-pinterest-from-0-to-10s-of-billions-of-page-views-a.html)
[18 million visitors, 10x growth, 12 employees](http://highscalability.com/blog/2012/5/21/pinterest-architecture-update-18-million-visitors-10x-growth.html) | -| Playfish | [50 million monthly users and growing](http://highscalability.com/blog/2010/9/21/playfishs-social-gaming-architecture-50-million-monthly-user.html) | -| PlentyOfFish | [PlentyOfFish architecture](http://highscalability.com/plentyoffish-architecture) | -| Salesforce | [How they handle 1.3 billion transactions a day](http://highscalability.com/blog/2013/9/23/salesforce-architecture-how-they-handle-13-billion-transacti.html) | +| Company | Reference(s) | +| -------------- | ---------------------------------------- | +| 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) | +| 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) | +| DropBox | [How we've scaled Dropbox](https://www.youtube.com/watch?v=PE4gwstWhmc) | +| ESPN | [Operating At 100,000 duh nuh nuhs per second](http://highscalability.com/blog/2013/11/4/espns-architecture-at-scale-operating-at-100000-duh-nuh-nuhs.html) | +| Google | [Google architecture](http://highscalability.com/google-architecture) | +| Instagram | [14 million users, terabytes of photos](http://highscalability.com/blog/2011/12/6/instagram-architecture-14-million-users-terabytes-of-photos.html)
[What powers Instagram](http://instagram-engineering.tumblr.com/post/13649370142/what-powers-instagram-hundreds-of-instances) | +| Justin.tv | [Justin.Tv's live video broadcasting architecture](http://highscalability.com/blog/2010/3/16/justintvs-live-video-broadcasting-architecture.html) | +| Facebook | [Scaling memcached at Facebook](https://cs.uwaterloo.ca/~brecht/courses/854-Emerging-2014/readings/key-value/fb-memcached-nsdi-2013.pdf)
[TAO: Facebook’s distributed data store for the social graph](https://cs.uwaterloo.ca/~brecht/courses/854-Emerging-2014/readings/data-store/tao-facebook-distributed-datastore-atc-2013.pdf)
[Facebook’s photo storage](https://www.usenix.org/legacy/event/osdi10/tech/full_papers/Beaver.pdf) | +| Flickr | [Flickr architecture](http://highscalability.com/flickr-architecture) | +| Mailbox | [From 0 to one million users in 6 weeks](http://highscalability.com/blog/2013/6/18/scaling-mailbox-from-0-to-one-million-users-in-6-weeks-and-1.html) | +| Pinterest | [From 0 To 10s of billions of page views a month](http://highscalability.com/blog/2013/4/15/scaling-pinterest-from-0-to-10s-of-billions-of-page-views-a.html)
[18 million visitors, 10x growth, 12 employees](http://highscalability.com/blog/2012/5/21/pinterest-architecture-update-18-million-visitors-10x-growth.html) | +| Playfish | [50 million monthly users and growing](http://highscalability.com/blog/2010/9/21/playfishs-social-gaming-architecture-50-million-monthly-user.html) | +| PlentyOfFish | [PlentyOfFish architecture](http://highscalability.com/plentyoffish-architecture) | +| Salesforce | [How they handle 1.3 billion transactions a day](http://highscalability.com/blog/2013/9/23/salesforce-architecture-how-they-handle-13-billion-transacti.html) | | Stack Overflow | [Stack Overflow architecture](http://highscalability.com/blog/2009/8/5/stack-overflow-architecture.html) | -| TripAdvisor | [40M visitors, 200M dynamic page views, 30TB data](http://highscalability.com/blog/2011/6/27/tripadvisor-architecture-40m-visitors-200m-dynamic-page-view.html) | -| Tumblr | [15 billion page views a month](http://highscalability.com/blog/2012/2/13/tumblr-architecture-15-billion-page-views-a-month-and-harder.html) | -| Twitter | [Making Twitter 10000 percent faster](http://highscalability.com/scaling-twitter-making-twitter-10000-percent-faster)
[Storing 250 million tweets a day using MySQL](http://highscalability.com/blog/2011/12/19/how-twitter-stores-250-million-tweets-a-day-using-mysql.html)
[150M active users, 300K QPS, a 22 MB/S firehose](http://highscalability.com/blog/2013/7/8/the-architecture-twitter-uses-to-deal-with-150m-active-users.html)
[Timelines at scale](https://www.infoq.com/presentations/Twitter-Timeline-Scalability)
[Big and small data at Twitter](https://www.youtube.com/watch?v=5cKTP36HVgI)
[Operations at Twitter: scaling beyond 100 million users](https://www.youtube.com/watch?v=z8LU0Cj6BOU) | -| Uber | [How Uber scales their real-time market platform](http://highscalability.com/blog/2015/9/14/how-uber-scales-their-real-time-market-platform.html) | -| WhatsApp | [The WhatsApp architecture Facebook bought for $19 billion](http://highscalability.com/blog/2014/2/26/the-whatsapp-architecture-facebook-bought-for-19-billion.html) | -| YouTube | [YouTube scalability](https://www.youtube.com/watch?v=w5WVu624fY8)
[YouTube architecture](http://highscalability.com/youtube-architecture) | +| TripAdvisor | [40M visitors, 200M dynamic page views, 30TB data](http://highscalability.com/blog/2011/6/27/tripadvisor-architecture-40m-visitors-200m-dynamic-page-view.html) | +| Tumblr | [15 billion page views a month](http://highscalability.com/blog/2012/2/13/tumblr-architecture-15-billion-page-views-a-month-and-harder.html) | +| Twitter | [Making Twitter 10000 percent faster](http://highscalability.com/scaling-twitter-making-twitter-10000-percent-faster)
[Storing 250 million tweets a day using MySQL](http://highscalability.com/blog/2011/12/19/how-twitter-stores-250-million-tweets-a-day-using-mysql.html)
[150M active users, 300K QPS, a 22 MB/S firehose](http://highscalability.com/blog/2013/7/8/the-architecture-twitter-uses-to-deal-with-150m-active-users.html)
[Timelines at scale](https://www.infoq.com/presentations/Twitter-Timeline-Scalability)
[Big and small data at Twitter](https://www.youtube.com/watch?v=5cKTP36HVgI)
[Operations at Twitter: scaling beyond 100 million users](https://www.youtube.com/watch?v=z8LU0Cj6BOU) | +| Uber | [How Uber scales their real-time market platform](http://highscalability.com/blog/2015/9/14/how-uber-scales-their-real-time-market-platform.html) | +| WhatsApp | [The WhatsApp architecture Facebook bought for $19 billion](http://highscalability.com/blog/2014/2/26/the-whatsapp-architecture-facebook-bought-for-19-billion.html) | +| YouTube | [YouTube scalability](https://www.youtube.com/watch?v=w5WVu624fY8)
[YouTube architecture](http://highscalability.com/youtube-architecture) | -### Company engineering blogs +### 公司工程博客 -> Architectures for companies you are interviewing with. +> 你即将面试的公司的架构 > -> Questions you encounter might be from the same domain. +> 你面对的问题可能就来自于同样领域 * [Airbnb Engineering](http://nerds.airbnb.com/) * [Atlassian Developers](https://developer.atlassian.com/blog/) @@ -1730,24 +1729,22 @@ Handy metrics based on numbers above: * [Yelp Engineering Blog](http://engineeringblog.yelp.com/) * [Zynga Engineering Blog](https://www.zynga.com/blogs/engineering) -#### Source(s) and further reading +#### 延伸阅读 * [kilimchoi/engineering-blogs](https://github.com/kilimchoi/engineering-blogs) -## Under development +## 正在开发中 -Interested in adding a section or helping complete one in-progress? [Contribute](#contributing)! +有兴趣加入添加一些部分或者帮助完善某些部分吗?[加入进来吧](#contributing)! -* Distributed computing with MapReduce -* Consistent hashing -* Scatter gather +* 使用 MapReduce 进行分布式计算 +* 一致性哈希 * [Contribute](#contributing) ## Credits -Credits and sources are provided throughout this repo. -Special thanks to: +特别鸣谢: * [Hired in tech](http://www.hiredintech.com/system-design/the-system-design-process/) * [Cracking the coding interview](https://www.amazon.com/dp/0984782850/) @@ -1759,11 +1756,11 @@ Special thanks to: * [A distributed systems reading list](http://dancres.github.io/Pages/) * [Cracking the system design interview](http://www.puncsky.com/blog/2016/02/14/crack-the-system-design-interview/) -## Contact info +## 联系方式 -Feel free to contact me to discuss any issues, questions, or comments. +欢迎联系我讨论本文的不足、问题或者意见 -My contact info can be found on my [GitHub page](https://github.com/donnemartin). +可以在我的 [GitHub 主页](https://github.com/donnemartin)上找到我的联系方式 ## License From e296a317ab7767a30b4f2e73ab4a3cdbf64e5d09 Mon Sep 17 00:00:00 2001 From: xiaoyusilen Date: Mon, 3 Apr 2017 23:02:17 +0800 Subject: [PATCH 02/16] first edition --- README-zh-Hant.md | 466 +++++++++++++++++++++++----------------------- 1 file changed, 233 insertions(+), 233 deletions(-) diff --git a/README-zh-Hant.md b/README-zh-Hant.md index defa77ef..3861e03e 100644 --- a/README-zh-Hant.md +++ b/README-zh-Hant.md @@ -196,15 +196,15 @@ Start broad and go deeper in a few areas. It helps to know a little about vario * **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. -| | 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: | -| Read through a few articles in the [Company engineering blogs](#company-engineering-blogs) for the companies you are interviewing with | :+1: | :+1: | :+1: | -| Read through a few [Real world architectures](#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: | -| Work through [System design interview questions with solutions](#system-design-interview-questions-with-solutions) | Some | Many | Most | -| Work through [Object-oriented design interview questions with solutions](#object-oriented-design-interview-questions-with-solutions) | Some | Many | Most | -| Review [Additional system design interview questions](#additional-system-design-interview-questions) | Some | Many | Most | +| | 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: | +| Read through a few articles in the [Company engineering blogs](#company-engineering-blogs) for the companies you are interviewing with | :+1: | :+1: | :+1: | +| Read through a few [Real world architectures](#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: | +| Work through [System design interview questions with solutions](#system-design-interview-questions-with-solutions) | Some | Many | Most | +| Work through [Object-oriented design interview questions with solutions](#object-oriented-design-interview-questions-with-solutions) | Some | Many | Most | +| Review [Additional system design interview questions](#additional-system-design-interview-questions) | Some | Many | Most | ## How to approach a system design interview question @@ -280,17 +280,17 @@ Check out the following links to get a better idea of what to expect: > > Solutions linked to content in the `solutions/` folder. -| Question | | -|---|---| -| Design Pastebin.com (or Bit.ly) | [Solution](solutions/system_design/pastebin/README.md) | +| Question | | +| ---------------------------------------- | ---------------------------------------- | +| Design Pastebin.com (or Bit.ly) | [Solution](solutions/system_design/pastebin/README.md) | | Design the Twitter timeline (or Facebook feed)
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 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) | +| Add a system design question | [Contribute](#contributing) | ### Design Pastebin.com (or Bit.ly) @@ -348,16 +348,16 @@ Check out the following links to get a better idea of what to expect: >**Note: This section is under development** -| Question | | -|---|---| -| 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 call center | [Solution](solutions/object_oriented_design/call_center/call_center.ipynb) | -| Design a deck of cards | [Solution](solutions/object_oriented_design/deck_of_cards/deck_of_cards.ipynb) | -| Design a parking lot | [Solution](solutions/object_oriented_design/parking_lot/parking_lot.ipynb) | -| Design a chat server | [Solution](solutions/object_oriented_design/online_chat/online_chat.ipynb) | -| Design a circular array | [Contribute](#contributing) | -| Add an object-oriented design question | [Contribute](#contributing) | +| Question | | +| -------------------------------------- | ---------------------------------------- | +| 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 call center | [Solution](solutions/object_oriented_design/call_center/call_center.ipynb) | +| Design a deck of cards | [Solution](solutions/object_oriented_design/deck_of_cards/deck_of_cards.ipynb) | +| Design a parking lot | [Solution](solutions/object_oriented_design/parking_lot/parking_lot.ipynb) | +| Design a chat server | [Solution](solutions/object_oriented_design/online_chat/online_chat.ipynb) | +| Design a circular array | [Contribute](#contributing) | +| Add an object-oriented design question | [Contribute](#contributing) | ## System design topics: start here @@ -1018,21 +1018,21 @@ In a graph database, each node is a record and each arc is a relationship betwee Graphs databases offer high performance for data models with complex relationships, such as a social network. They are relatively new and are not yet widely-used; it might be more difficult to find development tools and resources. Many graphs can only be accessed with [REST APIs](#representational-state-transfer-rest). -##### Source(s) and further reading: graph +##### 相关资源和延伸阅读:图 -* [Graph database](https://en.wikipedia.org/wiki/Graph_database) +* [图数据库](https://en.wikipedia.org/wiki/Graph_database) * [Neo4j](https://neo4j.com/) * [FlockDB](https://blog.twitter.com/2010/introducing-flockdb) -#### Source(s) and further reading: NoSQL +#### 相关资源和延伸阅读:NoSQL -* [Explanation of base terminology](http://stackoverflow.com/questions/3342497/explanation-of-base-terminology) -* [NoSQL databases a survey and decision guidance](https://medium.com/baqend-blog/nosql-databases-a-survey-and-decision-guidance-ea7823a822d#.wskogqenq) -* [Scalability](http://www.lecloud.net/post/7994751381/scalability-for-dummies-part-2-database) -* [Introduction to NoSQL](https://www.youtube.com/watch?v=qI_g07C_Q5I) -* [NoSQL patterns](http://horicky.blogspot.com/2009/11/nosql-patterns.html) +* [基础术语解释](http://stackoverflow.com/questions/3342497/explanation-of-base-terminology) +* [NoSQL 数据库 — 调查与决策指导](https://medium.com/baqend-blog/nosql-databases-a-survey-and-decision-guidance-ea7823a822d#.wskogqenq) +* [可扩展性](http://www.lecloud.net/post/7994751381/scalability-for-dummies-part-2-database) +* [NoSQL 的介绍](https://www.youtube.com/watch?v=qI_g07C_Q5I) +* [NoSQL 模式](http://horicky.blogspot.com/2009/11/nosql-patterns.html) -### SQL or NoSQL +### SQL 还是 NoSQL

@@ -1040,41 +1040,41 @@ Graphs databases offer high performance for data models with complex relationshi Source: Transitioning from RDBMS to NoSQL

-Reasons for **SQL**: +选择 **SQL** 的原因: -* Structured data -* Strict schema -* Relational data -* Need for complex joins -* Transactions -* Clear patterns for scaling -* More established: developers, community, code, tools, etc -* Lookups by index are very fast +* 结构化数据 +* 严格的架构 +* 关系型数据 +* 需要复杂的 joins +* 事务 +* 清除缩放模式 +* 更成熟的开发人员,社区,代码,工具等等 +* 通过索引查找非常快 -Reasons for **NoSQL**: +选择 **NoSQL** 的原因: -* Semi-structured data -* Dynamic or flexible schema -* Non relational data -* No need for complex joins -* Store many TB (or PB) of data -* Very data intensive workload -* Very high throughput for IOPS +* 半结构化数据 +* 动态/灵活的模式 +* 非关系型数据 +* 不需要复杂的 joins 操作 +* 可以存储大量 TB/PB 数据 +* 非常数据密集的工作量 +* 非常高的 IOPS 吞吐量 -Sample data well-suited for NoSQL: +适合 NoSQL 操作的数据: -* Rapid ingest of clickstream and log data -* Leaderboard or scoring data -* Temporary data, such as a shopping cart -* Frequently accessed ('hot') tables -* Metadata/lookup tables +* 埋点数据以及日志数据 +* 排行榜或者得分数据 +* 临时数据,比如购物车 +* 需要频繁访问的表 +* 元数据/查找表 -##### Source(s) and further reading: SQL or NoSQL +相关资源和延伸阅读:SQL 还是 NoSQL -* [Scaling up to your first 10 million users](https://www.youtube.com/watch?v=vg5onp8TU6Q) -* [SQL vs NoSQL differences](https://www.sitepoint.com/sql-vs-nosql-differences/) +* [扩大您的用户到第一个1000万](https://www.youtube.com/watch?v=vg5onp8TU6Q) +* [SQL 和 NoSQL 的不同](https://www.sitepoint.com/sql-vs-nosql-differences/) -## Cache +## 缓存

@@ -1082,70 +1082,70 @@ Sample data well-suited for NoSQL: Source: Scalable system design patterns

-Caching improves page load times and can reduce the load on your servers and databases. In this model, the dispatcher will first lookup if the request has been made before and try to find the previous result to return, in order to save the actual execution. +缓存可以提高页面加载时间,并可以减少服务器和数据库的负载。在这个模式中,分发器会先去查看这个请求之前是否处理过,如果可以找到之前的结果那么就返回至客户端,否则,就将请求分发至处理池,以便将实际的处理结果存储至缓存中。 -Databases often benefit from a uniform distribution of reads and writes across its partitions. Popular items can skew the distribution, causing bottlenecks. Putting a cache in front of a database can help absorb uneven loads and spikes in traffic. +数据库分片均匀分布的读取是最好的。但是热门数据会让读取分布不均匀,这样就会造成瓶颈,如果在数据库前加个缓存,就会抹平不均匀的负载和突发流量对数据库的影响。 -### Client caching +### 客户端缓存 -Caches can be located on the client side (OS or browser), [server side](#reverse-proxy), or in a distinct cache layer. +缓存可以位于客户端(操作系统或者浏览器),[服务端](#reverse-proxy)或者不同的缓存层。 -### CDN caching +### CDN缓存 -[CDNs](#content-delivery-network) are considered a type of cache. +[CDNs](#content-delivery-network) 也是一种缓存。 -### Web server caching +### Web 服务器缓存 -[Reverse proxies](#reverse-proxy-web-server) and caches such as [Varnish](https://www.varnish-cache.org/) can serve static and dynamic content directly. Web servers can also cache requests, returning responses without having to contact application servers. +[反向代理](#reverse-proxy-web-server)和缓存(比如 [Varnish](https://www.varnish-cache.org/))可以直接提供静态和动态内容。Web 服务器同样也可以缓存请求,返回相应结果而不必连接应用服务器。 -### Database caching +### 数据库缓存 -Your database usually includes some level of caching in a default configuration, optimized for a generic use case. Tweaking these settings for specific usage patterns can further boost performance. +数据库的默认配置中通常包含缓存级别,针对一般用例进行了优化。调整配置中在不同情况下使用不同的模式可以进一步提高性能。 -### Application caching +### 应用缓存 -In-memory caches such as Memcached and Redis are key-value stores between your application and your data storage. Since the data is held in RAM, it is much faster than typical databases where data is stored on disk. RAM is more limited than disk, so [cache invalidation](https://en.wikipedia.org/wiki/Cache_algorithms) algorithms such as [least recently used (LRU)](https://en.wikipedia.org/wiki/Cache_algorithms#Least_Recently_Used) can help invalidate 'cold' entries and keep 'hot' data in RAM. +基于内存的缓存比如 Memcached 和 Redis 是应用程序和数据存储之间的一种键值存储。由于数据保存在 RAM 中,它比存储在磁盘上的典型数据库要快多了。RAM 比磁盘限制更多,所以[缓存无效算法](https://en.wikipedia.org/wiki/Cache_algorithms)比如 [least recently used (LRU)](https://en.wikipedia.org/wiki/Cache_algorithms#Least_Recently_Used) 可以将「热门数据」放在 RAM 中,而对一些比较「冷门」的数据不做处理。 -Redis has the following additional features: +Redis 有下列附加功能: -* Persistence option -* Built-in data structures such as sorted sets and lists +* 持久性选项 +* 内置数据结构比如有序集合和列表 -There are multiple levels you can cache that fall into two general categories: **database queries** and **objects**: +有多个缓存级别,分为两大类:**数据库查询**和**对象**: -* Row level -* Query-level -* Fully-formed serializable objects -* Fully-rendered HTML +* 行级别 +* 查询级别 +* 完整的可序列化对象 +* 完全渲染的 HTML -Generally, you should try to avoid file-based caching, as it makes cloning and auto-scaling more difficult. +一般来说,你应该尽量避免基于文件的缓存,因为这使得复制和自动缩放很困难。 -### Caching at the database query level +### 数据库查询级别的缓存 -Whenever you query the database, hash the query as a key and store the result to the cache. This approach suffers from expiration issues: +当你查询数据库的时候,将查询结果作为关键字同时将结果存储到缓存中。这种方法会遇到以下问题: -* Hard to delete a cached result with complex queries -* If one piece of data changes such as a table cell, you need to delete all cached queries that might include the changed cell +* 很难用复杂的查询删除已缓存结果。 +* 如果一条数据比如表中某条数据的一项被改变,则需要删除所有可能包含已更改项的缓存结果。 -### Caching at the object level +### 对象级别的缓存 -See your data as an object, similar to what you do with your application code. Have your application assemble the dataset from the database into a class instance or a data structure(s): +将您的数据视为对象,就像对待你的应用代码一样。 让应用程序将数据从数据库中组合到类实例或数据结构中: -* Remove the object from cache if its underlying data has changed -* Allows for asynchronous processing: workers assemble objects by consuming the latest cached object +* 如果对象的基础数据已经更改了,那么从缓存中删掉这个对象。 +* 允许异步处理:workers 通过使用最新的缓存对象来组装对象。 -Suggestions of what to cache: +建议缓存的内容: -* User sessions -* Fully rendered web pages -* Activity streams -* User graph data +* 用户会话 +* 完全渲染的 Web 页面 +* 活动流 +* 用户图数据 -### When to update the cache +### 何时更新缓存 -Since you can only store a limited amount of data in cache, you'll need to determine which cache update strategy works best for your use case. +由于你只能在缓存中存储有限的数据,所以你需要选择一个适用于你用例的缓存更新策略。 -#### Cache-aside +#### 缓存

@@ -1153,12 +1153,12 @@ Since you can only store a limited amount of data in cache, you'll need to deter Source: From cache to in-memory data grid

-The application is responsible for reading and writing from storage. The cache does not interact with storage directly. The application does the following: +应用从存储器读写。缓存不和存储器直接交互,应用执行以下操作: -* Look for entry in cache, resulting in a cache miss -* Load entry from the database -* Add entry to cache -* Return entry +* 在缓存中查找记录,如果所需数据不在缓存中 +* 从数据库中加载所需内容 +* 将查找到的结果存储到缓存中 +* 返回所需内容 ``` def get_user(self, user_id): @@ -1171,17 +1171,17 @@ def get_user(self, user_id): return user ``` -[Memcached](https://memcached.org/) is generally used in this manner. +[Memcached](https://memcached.org/) 通常用这种方式使用。 -Subsequent reads of data added to cache are fast. Cache-aside is also referred to as lazy loading. Only requested data is cached, which avoids filling up the cache with data that isn't requested. +添加到缓存中的数据读取速度很快。缓存模式也称为延迟加载。只缓存所请求的数据,这避免了没有被请求的数据占满了缓存空间。 -##### Disadvantage(s): cache-aside +##### 缓存的缺点: -* Each cache miss results in three trips, which can cause a noticeable delay. -* Data can become stale if it is updated in the database. This issue is mitigated by setting a time-to-live (TTL) which forces an update of the cache entry, or by using write-through. -* When a node fails, it is replaced by a new, empty node, increasing latency. +* 每一次所需数据不在缓存中都需要经历三个过程,这会导致明显的延迟。 +* 如果数据库中的数据更新了会导致缓存中的数据过时。这个问题需要通过设置 TTL 强制更新缓存或者直写模式来缓解这种情况。 +* 当一个节点出现故障的时候,它将会被一个新的节点替代,这增加了延迟的时间。 -#### Write-through +#### 直写模式

@@ -1189,19 +1189,19 @@ Subsequent reads of data added to cache are fast. Cache-aside is also referred Source: Scalability, availability, stability, patterns

-The application uses the cache as the main data store, reading and writing data to it, while the cache is responsible for reading and writing to the database: +应用使用缓存作为主要的数据存储,将数据读写到缓存中,而缓存负责从数据库中读写数据。 -* Application adds/updates entry in cache -* Cache synchronously writes entry to data store -* Return +* 应用向缓存中添加/更新数据 +* 缓存将所需内容写入数据存储 +* 返回所需内容 -Application code: +应用代码: ``` set_user(12345, {"foo":"bar"}) ``` -Cache code: +缓存代码: ``` def set_user(user_id, values): @@ -1209,14 +1209,14 @@ def set_user(user_id, values): cache.set(user_id, user) ``` -Write-through is a slow overall operation due to the write operation, but subsequent reads of just written data are fast. Users are generally more tolerant of latency when updating data than reading data. Data in the cache is not stale. +由于读写操作所以直写模式整体是一种很慢的操作,但是读取刚写入的数据很快。相比读取数据,用户通常比较能接受更新数据时速度较慢。缓存中的数据不会过时。 -##### Disadvantage(s): write through +##### 直写模式的缺点: -* When a new node is created due to failure or scaling, the new node will not cache entries until the entry is updated in the database. Cache-aside in conjunction with write through can mitigate this issue. -* Most data written might never read, which can be minimized with a TTL. +* 由于故障或者缩放而创建的新的节点,新的节点不会缓存,直到数据库更新为止。缓存应用直写模式可以缓解这个问题。 +* 写入的大多数数据可能永远都不会被读取,用 TTL 可以最小化这种情况的出现。 -#### Write-behind (write-back) +#### 回写模式

@@ -1224,17 +1224,17 @@ Write-through is a slow overall operation due to the write operation, but subseq Source: Scalability, availability, stability, patterns

-In write-behind, tha application does the following: +在回写模式中,应用执行以下操作: -* Add/update entry in cache -* Asynchronously write entry to the data store, improving write performance +* 在缓存中增加或者更新条目 +* 异步写入数据,提高写入性能。 -##### Disadvantage(s): write-behind +##### 回写模式的缺点: -* There could be data loss if the cache goes down prior to its contents hitting the data store. -* It is more complex to implement write-behind than it is to implement cache-aside or write-through. +* 缓存可能在其内容成功存储之前丢失数据。 +* 执行直写模式比缓存或者回写模式更复杂。 -#### Refresh-ahead +#### 刷新

@@ -1242,31 +1242,31 @@ In write-behind, tha application does the following: Source: From cache to in-memory data grid

-You can configure the cache to automatically refresh any recently accessed cache entry prior to its expiration. +你可以将缓存配置成在到期之前自动刷新最近访问过的内容。 -Refresh-ahead can result in reduced latency vs read-through if the cache can accurately predict which items are likely to be needed in the future. +如果缓存可以准确预测将来可能请求哪些数据,那么刷新可能会导致延迟与读取时间的降低。 -##### Disadvantage(s): refresh-ahead +##### 刷新的缺点: -* Not accurately predicting which items are likely to be needed in the future can result in reduced performance than without refresh-ahead. +* 不能准确预测到未来需要用到的数据可能会导致性能不如不使用刷新。 -### Disadvantage(s): cache +### 缓存的缺点: -* Need to maintain consistency between caches and the source of truth such as the database through [cache invalidation](https://en.wikipedia.org/wiki/Cache_algorithms). -* Need to make application changes such as adding Redis or memcached. -* Cache invalidation is a difficult problem, there is additional complexity associated with when to update the cache. +* 需要保持缓存和真实数据源之间的一致性,比如数据库根据[缓存无效](https://en.wikipedia.org/wiki/Cache_algorithms)。 +* 需要改变应用程序比如增加 Redis 或者 memcached。 +* 无效缓存是个难题,什么时候更新缓存是额外复杂的问题。 -### Source(s) and further reading +### 相关资源和延伸阅读 -* [From cache to in-memory data grid](http://www.slideshare.net/tmatyashovsky/from-cache-to-in-memory-data-grid-introduction-to-hazelcast) -* [Scalable system design patterns](http://horicky.blogspot.com/2010/10/scalable-system-design-patterns.html) -* [Introduction to architecting systems for scale](http://lethain.com/introduction-to-architecting-systems-for-scale/) -* [Scalability, availability, stability, patterns](http://www.slideshare.net/jboner/scalability-availability-stability-patterns/) -* [Scalability](http://www.lecloud.net/post/9246290032/scalability-for-dummies-part-3-cache) -* [AWS ElastiCache strategies](http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/Strategies.html) -* [Wikipedia](https://en.wikipedia.org/wiki/Cache_(computing)) +* [从缓存到内存数据](http://www.slideshare.net/tmatyashovsky/from-cache-to-in-memory-data-grid-introduction-to-hazelcast) +* [可扩展系统设计模式](http://horicky.blogspot.com/2010/10/scalable-system-design-patterns.html) +* [scale 的系统架构介绍](http://lethain.com/introduction-to-architecting-systems-for-scale/) +* [可扩展性,可用性,稳定性,模式](http://www.slideshare.net/jboner/scalability-availability-stability-patterns/) +* [可扩展性]((http://www.lecloud.net/post/9246290032/scalability-for-dummies-part-3-cache)) +* [AWS ElastiCache 策略](http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/Strategies.html) +* [维基百科](https://en.wikipedia.org/wiki/Cache_(computing)) -## Asynchronism +## 异步

@@ -1274,45 +1274,45 @@ Refresh-ahead can result in reduced latency vs read-through if the cache can acc Source: Intro to architecting systems for scale

-Asynchronous workflows help reduce request times for expensive operations that would otherwise be performed in-line. They can also help by doing time-consuming work in advance, such as periodic aggregation of data. +异步工作流有助于减少操作的请求时间否则它们就会按顺序执行。它们可以通过提前进行一些耗时的工作来帮助减少请求时间,比如定期汇总数据。 -### Message queues +### 消息队列 -Message queues receive, hold, and deliver messages. If an operation is too slow to perform inline, you can use a message queue with the following workflow: +消息队列接收,保留和传递消息。如果按顺序执行操作太慢的话,你可以使用有以下工作流的消息队列: -* An application publishes a job to the queue, then notifies the user of job status -* A worker picks up the job from the queue, processes it, then signals the job is complete +* 应用程序将作业发布到队列,然后通知用户作业状态 +* 一个 worker 从队列中取出该作业,对其进行处理,然后显示该作业完成 -The user is not blocked and the job is processed in the background. During this time, the client might optionally do a small amount of processing to make it seem like the task has completed. For example, if posting a tweet, the tweet could be instantly posted to your timeline, but it could take some time before your tweet is actually delivered to all of your followers. +用户未被阻止,作业在后台处理。在此期间,客户端可能会进行一些处理使得看上去像是任务已经完成了。例如,如果要发送一条推文,推文可能会马上出现在你的时间线上,但是可能需要一些时间才能将你的推文推送到你的所有关注者那里去。 -**Redis** is useful as a simple message broker but messages can be lost. +**Redis** 是一个令人满意的简单的消息代理,但是消息有可能会丢失。 -**RabbitMQ** is popular but requires you to adapt to the 'AMQP' protocol and manage your own nodes. +**RabbitMQ** 很受欢迎但是要求你适应「AMQP」协议并且管理你自己的节点。 -**Amazon SQS**, is hosted but can have high latency and has the possibility of messages being delivered twice. +**Amazon SQS** 是被托管的,但可能具有高延迟,并且消息可能会被传送两次。 -### Task queues +### 任务队列 -Tasks queues receive tasks and their related data, runs them, then delivers their results. They can support scheduling and can be used to run computationally-intensive jobs in the background. +任务队列接收任务及其相关数据,运行它们,然后传递其结果。 它们可以支持调度,并可用于在后台运行计算密集型作业。 -**Celery** has support for scheduling and primarily has python support. +**Celery** 支持调度,主要是用 Python 开发的。 -### Back pressure +### 背压 -If queues start to grow significantly, the queue size can become larger than memory, resulting in cache misses, disk reads, and even slower performance. [Back pressure](http://mechanical-sympathy.blogspot.com/2012/05/apply-back-pressure-when-overloaded.html) can help by limiting the queue size, thereby maintaining a high throughput rate and good response times for jobs already in the queue. Once the queue fills up, clients get a server busy or HTTP 503 status code to try again later. Clients can retry the request at a later time, perhaps with [exponential backoff](https://en.wikipedia.org/wiki/Exponential_backoff). +如果队列开始明显增长,那么队列大小可能会超过内存大小,导致高速缓存未命中,磁盘读取,甚至性能更慢。[背压](http://mechanical-sympathy.blogspot.com/2012/05/apply-back-pressure-when-overloaded.html)可以通过限制队列大小来帮助我们,从而为队列中的作业保持高吞吐率和良好的响应时间。一旦队列填满,客户端将得到服务器忙活着 HTTP 503 状态码,以便稍后重试。客户端可以在稍后时间重试该请求,也许是[指数退避](https://en.wikipedia.org/wiki/Exponential_backoff)。 -### Disadvantage(s): asynchronism +### 异步的缺点: -* Use cases such as inexpensive calculations and realtime workflows might be better suited for synchronous operations, as introducing queues can add delays and complexity. +* 廉价计算和实时工作流等用例可能更适用于同步操作,因为引入队列可能会增加延迟和复杂性。 -### Source(s) and further reading +### 相关资源和延伸阅读 -* [It's all a numbers game](https://www.youtube.com/watch?v=1KRYH75wgy4) -* [Applying back pressure when overloaded](http://mechanical-sympathy.blogspot.com/2012/05/apply-back-pressure-when-overloaded.html) -* [Little's law](https://en.wikipedia.org/wiki/Little%27s_law) -* [What is the difference between a message queue and a task queue?](https://www.quora.com/What-is-the-difference-between-a-message-queue-and-a-task-queue-Why-would-a-task-queue-require-a-message-broker-like-RabbitMQ-Redis-Celery-or-IronMQ-to-function) +* [这是一个数字游戏](https://www.youtube.com/watch?v=1KRYH75wgy4) +* [超载时应用背压](http://mechanical-sympathy.blogspot.com/2012/05/apply-back-pressure-when-overloaded.html) +* [利特尔法则](https://en.wikipedia.org/wiki/Little%27s_law) +* [消息队列与任务队列有什么区别?](https://www.quora.com/What-is-the-difference-between-a-message-queue-and-a-task-queue-Why-would-a-task-queue-require-a-message-broker-like-RabbitMQ-Redis-Celery-or-IronMQ-to-function) -## Communication +## 通讯

@@ -1320,28 +1320,28 @@ If queues start to grow significantly, the queue size can become larger than mem Source: OSI 7 layer model

-### Hypertext transfer protocol (HTTP) +### 超文本传输协议(HTTP) -HTTP is a method for encoding and transporting data between a client and a server. It is a request/response protocol: clients issue requests and servers issue responses with relevant content and completion status info about the request. HTTP is self-contained, allowing requests and responses to flow through many intermediate routers and servers that perform load balancing, caching, encryption, and compression. +HTTP 是一种在客户端和服务器之间编码和传输数据的方法。它是一个请求/响应协议:客户端和服务端针对相关内容和完成状态信息的请求和响应。HTTP 是独立的,允许请求和响应流经许多执行负载均衡,缓存,加密和压缩的中间路由器和服务器。 -A basic HTTP request consists of a verb (method) and a resource (endpoint). Below are common HTTP verbs: +一个基本的 HTTP 请求由一个动词(方法)和一个资源(endpoint)组成。 以下是常见的 HTTP 动词: -| Verb | Description | Idempotent* | Safe | Cacheable | -|---|---|---|---|---| -| 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 | -| PUT | Creates or replace a resource | Yes | No | No | -| PATCH | Partially updates a resource | No | No | Yes if response contains freshness info | -| DELETE | Deletes a resource | Yes | No | No | +| 动词 | 描述 | *幂等 | 安全性 | 可缓存 | +| ------ | -------------- | ---- | ---- | ------------- | +| GET | 读取资源 | Yes | Yes | Yes | +| POST | 创建资源或触发处理数据的进程 | No | No | 可以,如果回应包含刷新信息 | +| PUT | 创建或替换资源 | Yes | No | No | +| PATCH | 部分更新资源 | No | No | 可以,如果回应包含刷新信息 | +| DELETE | 删除资源 | Yes | No | No | -*Can be called many times without different outcomes. +*多次执行不会产生不同的结果。 -HTTP is an application layer protocol relying on lower-level protocols such as **TCP** and **UDP**. +HTTP 是依赖于较低级协议(如 **TCP** 和 **UDP**)的应用层协议。 * [HTTP](https://www.nginx.com/resources/glossary/http/) * [README](https://www.quora.com/What-is-the-difference-between-HTTP-protocol-and-TCP-protocol) -### Transmission control protocol (TCP) +### 传输控制协议(TCP)

@@ -1349,21 +1349,21 @@ HTTP is an application layer protocol relying on lower-level protocols such as * Source: How to make a multiplayer game

-TCP is a connection-oriented protocol over an [IP network](https://en.wikipedia.org/wiki/Internet_Protocol). Connection is established and terminated using a [handshake](https://en.wikipedia.org/wiki/Handshaking). All packets sent are guaranteed to reach the destination in the original order and without corruption through: +TCP 是通过 [IP 网络](https://en.wikipedia.org/wiki/Internet_Protocol)的面向连接的协议。 使用[握手](https://en.wikipedia.org/wiki/Handshaking)建立和断开连接。 发送的所有数据包保证以原始顺序到达目的地,用以下措施保证数据包不被损坏: -* Sequence numbers and [checksum fields](https://en.wikipedia.org/wiki/Transmission_Control_Protocol#Checksum_computation) for each packet -* [Acknowledgement](https://en.wikipedia.org/wiki/Acknowledgement_(data_networks)) packets and automatic retransmission +* 每个数据包的序列号和[校验码](https://en.wikipedia.org/wiki/Transmission_Control_Protocol#Checksum_computation)。 +* [确认包](https://en.wikipedia.org/wiki/Acknowledgement_(data_networks))和自动重传 -If the sender does not receive a correct response, it will resend the packets. If there are multiple timeouts, the connection is dropped. TCP also implements [flow control](https://en.wikipedia.org/wiki/Flow_control_(data)) and [congestion control](https://en.wikipedia.org/wiki/Network_congestion#Congestion_control). These guarantees cause delays and generally results in less efficient transmission than UDP. +如果发送者没有收到正确的响应,它将重新发送数据包。如果多次超时,连接就会断开。TCP 实行[流量控制](https://en.wikipedia.org/wiki/Flow_control_(data))和[拥塞控制](https://en.wikipedia.org/wiki/Network_congestion#Congestion_control)。这些确保措施会导致延迟,而且通常导致传输效率比 UDP 低。 -To ensure high throughput, web servers can keep a large number of TCP connections open, resulting in high memory usage. It can be expensive to have a large number of open connections between web server threads and say, a [memcached](#memcached) server. [Connection pooling](https://en.wikipedia.org/wiki/Connection_pool) can help in addition to switching to UDP where applicable. +为了确保高吞吐量,Web 服务器可以保持大量的 TCP 连接,从而导致高内存使用。在 Web 服务器线程间拥有大量开放连接可能开销巨大,消耗资源过多,也就是说,一个 [memcached](#memcached) 服务器。[连接池](https://en.wikipedia.org/wiki/Connection_pool) 可以帮助除了在适用的情况下切换到 UDP。 -TCP is useful for applications that require high reliability but are less time critical. Some examples include web servers, database info, SMTP, FTP, and SSH. +TCP 对于需要高可靠性但时间紧迫的应用程序很有用。比如包括 Web 服务器,数据库信息,SMTP,FTP 和 SSH。 -Use TCP over UDP when: +什么时候使用 TCP over UDP: -* You need all of the data to arrive intact -* You want to automatically make a best estimate use of the network throughput +* 你需要数据完好无损。 +* 你想对网络吞吐量自动进行最佳评估。 ### User datagram protocol (UDP) @@ -1474,15 +1474,15 @@ REST is focused on exposing data. It minimizes the coupling between client/serv ### RPC and REST calls comparison -| Operation | RPC | REST | -|---|---|---| -| Signup | **POST** /signup | **POST** /persons | -| Resign | **POST** /resign
{
"personid": "1234"
} | **DELETE** /persons/1234 | -| Read a person | **GET** /readPerson?personid=1234 | **GET** /persons/1234 | -| Read a person’s items list | **GET** /readUsersItemsList?personid=1234 | **GET** /persons/1234/items | +| Operation | RPC | REST | +| ------------------------------- | ---------------------------------------- | ---------------------------------------- | +| Signup | **POST** /signup | **POST** /persons | +| Resign | **POST** /resign
{
"personid": "1234"
} | **DELETE** /persons/1234 | +| Read a person | **GET** /readPerson?personid=1234 | **GET** /persons/1234 | +| Read a person’s items list | **GET** /readUsersItemsList?personid=1234 | **GET** /persons/1234/items | | Add an item to a person’s items | **POST** /addItemToUsersItemsList
{
"personid": "1234";
"itemid": "456"
} | **POST** /persons/1234/items
{
"itemid": "456"
} | -| Update an item | **POST** /modifyItem
{
"itemid": "456";
"key": "value"
} | **PUT** /items/456
{
"key": "value"
} | -| Delete an item | **POST** /removeItem
{
"itemid": "456"
} | **DELETE** /items/456 | +| Update an item | **POST** /modifyItem
{
"itemid": "456";
"key": "value"
} | **PUT** /items/456
{
"key": "value"
} | +| Delete an item | **POST** /removeItem
{
"itemid": "456"
} | **DELETE** /items/456 |

Source: Do you really know why you prefer REST over RPC @@ -1590,16 +1590,16 @@ Handy metrics based on numbers above: > Common system design interview questions, with links to resources on how to solve each. -| Question | Reference(s) | -|---|---| -| 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)
[stackexchange.com](http://programmers.stackexchange.com/questions/38324/interview-question-how-would-you-implement-google-search)
[ardendertat.com](http://www.ardendertat.com/2012/01/11/implementing-search-engines/)
[stanford.edu](http://infolab.stanford.edu/~backrub/google.html) | +| Question | Reference(s) | +| ---------------------------------------- | ---------------------------------------- | +| 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)
[stackexchange.com](http://programmers.stackexchange.com/questions/38324/interview-question-how-would-you-implement-google-search)
[ardendertat.com](http://www.ardendertat.com/2012/01/11/implementing-search-engines/)
[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 Google docs | [code.google.com](https://code.google.com/p/google-mobwrite/)
[neil.fraser.name](https://neil.fraser.name/writing/sync/) | -| Design a key-value store like Redis | [slideshare.net](http://www.slideshare.net/dvirsky/introduction-to-redis) | -| Design a cache system like Memcached | [slideshare.net](http://www.slideshare.net/oemebamo/introduction-to-memcached) | +| Design Google docs | [code.google.com](https://code.google.com/p/google-mobwrite/)
[neil.fraser.name](https://neil.fraser.name/writing/sync/) | +| Design a key-value store like Redis | [slideshare.net](http://www.slideshare.net/dvirsky/introduction-to-redis) | +| Design a cache system like Memcached | [slideshare.net](http://www.slideshare.net/oemebamo/introduction-to-memcached) | | Design a recommendation system like Amazon's | [hulu.com](http://tech.hulu.com/blog/2011/09/19/recommendation-system.html)
[ijcai13.org](http://ijcai13.org/files/tutorial_slides/td3.pdf) | -| Design a tinyurl system like Bitly | [n00tc0d3r.blogspot.com](http://n00tc0d3r.blogspot.com/) | +| Design a tinyurl system like Bitly | [n00tc0d3r.blogspot.com](http://n00tc0d3r.blogspot.com/) | | Design a chat app like WhatsApp | [highscalability.com](http://highscalability.com/blog/2014/2/26/the-whatsapp-architecture-facebook-bought-for-19-billion.html) | Design a picture sharing system like Instagram | [highscalability.com](http://highscalability.com/flickr-architecture)
[highscalability.com](http://highscalability.com/blog/2011/12/6/instagram-architecture-14-million-users-terabytes-of-photos.html) | | Design the Facebook news feed function | [quora.com](http://www.quora.com/What-are-best-practices-for-building-something-like-a-News-Feed)
[quora.com](http://www.quora.com/Activity-Streams/What-are-the-scaling-issues-to-keep-in-mind-while-developing-a-social-network-feed)
[slideshare.net](http://www.slideshare.net/danmckinley/etsy-activity-feeds-architecture) | @@ -1631,14 +1631,14 @@ Handy metrics based on numbers above: * Study what problems are solved by each component, where it works, where it doesn't * 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 | **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 store | **Bigtable** - Distributed column-oriented database from Google | [harvard.edu](http://www.read.seas.harvard.edu/~kohler/class/cs239-w08/chang06bigtable.pdf) | -| Data store | **HBase** - Open source implementation of Bigtable | [slideshare.net](http://www.slideshare.net/alexbaranau/intro-to-hbase) | +| | | | +| Data store | **Bigtable** - Distributed column-oriented database from Google | [harvard.edu](http://www.read.seas.harvard.edu/~kohler/class/cs239-w08/chang06bigtable.pdf) | +| Data store | **HBase** - Open source implementation of Bigtable | [slideshare.net](http://www.slideshare.net/alexbaranau/intro-to-hbase) | | Data store | **Cassandra** - Distributed column-oriented database from Facebook | [slideshare.net](http://www.slideshare.net/planetcassandra/cassandra-introduction-features-30103666) | Data store | **DynamoDB** - Document-oriented database from Amazon | [harvard.edu](http://www.read.seas.harvard.edu/~kohler/class/cs239-w08/decandia07dynamo.pdf) | | Data store | **MongoDB** - Document-oriented database | [slideshare.net](http://www.slideshare.net/mdirolf/introduction-to-mongodb) | @@ -1657,30 +1657,30 @@ Handy metrics based on numbers above: ### Company architectures -| Company | Reference(s) | -|---|---| -| 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) | -| 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) | -| DropBox | [How we've scaled Dropbox](https://www.youtube.com/watch?v=PE4gwstWhmc) | -| ESPN | [Operating At 100,000 duh nuh nuhs per second](http://highscalability.com/blog/2013/11/4/espns-architecture-at-scale-operating-at-100000-duh-nuh-nuhs.html) | -| Google | [Google architecture](http://highscalability.com/google-architecture) | -| Instagram | [14 million users, terabytes of photos](http://highscalability.com/blog/2011/12/6/instagram-architecture-14-million-users-terabytes-of-photos.html)
[What powers Instagram](http://instagram-engineering.tumblr.com/post/13649370142/what-powers-instagram-hundreds-of-instances) | -| Justin.tv | [Justin.Tv's live video broadcasting architecture](http://highscalability.com/blog/2010/3/16/justintvs-live-video-broadcasting-architecture.html) | -| Facebook | [Scaling memcached at Facebook](https://cs.uwaterloo.ca/~brecht/courses/854-Emerging-2014/readings/key-value/fb-memcached-nsdi-2013.pdf)
[TAO: Facebook’s distributed data store for the social graph](https://cs.uwaterloo.ca/~brecht/courses/854-Emerging-2014/readings/data-store/tao-facebook-distributed-datastore-atc-2013.pdf)
[Facebook’s photo storage](https://www.usenix.org/legacy/event/osdi10/tech/full_papers/Beaver.pdf) | -| Flickr | [Flickr architecture](http://highscalability.com/flickr-architecture) | -| Mailbox | [From 0 to one million users in 6 weeks](http://highscalability.com/blog/2013/6/18/scaling-mailbox-from-0-to-one-million-users-in-6-weeks-and-1.html) | -| Pinterest | [From 0 To 10s of billions of page views a month](http://highscalability.com/blog/2013/4/15/scaling-pinterest-from-0-to-10s-of-billions-of-page-views-a.html)
[18 million visitors, 10x growth, 12 employees](http://highscalability.com/blog/2012/5/21/pinterest-architecture-update-18-million-visitors-10x-growth.html) | -| Playfish | [50 million monthly users and growing](http://highscalability.com/blog/2010/9/21/playfishs-social-gaming-architecture-50-million-monthly-user.html) | -| PlentyOfFish | [PlentyOfFish architecture](http://highscalability.com/plentyoffish-architecture) | -| Salesforce | [How they handle 1.3 billion transactions a day](http://highscalability.com/blog/2013/9/23/salesforce-architecture-how-they-handle-13-billion-transacti.html) | +| Company | Reference(s) | +| -------------- | ---------------------------------------- | +| 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) | +| 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) | +| DropBox | [How we've scaled Dropbox](https://www.youtube.com/watch?v=PE4gwstWhmc) | +| ESPN | [Operating At 100,000 duh nuh nuhs per second](http://highscalability.com/blog/2013/11/4/espns-architecture-at-scale-operating-at-100000-duh-nuh-nuhs.html) | +| Google | [Google architecture](http://highscalability.com/google-architecture) | +| Instagram | [14 million users, terabytes of photos](http://highscalability.com/blog/2011/12/6/instagram-architecture-14-million-users-terabytes-of-photos.html)
[What powers Instagram](http://instagram-engineering.tumblr.com/post/13649370142/what-powers-instagram-hundreds-of-instances) | +| Justin.tv | [Justin.Tv's live video broadcasting architecture](http://highscalability.com/blog/2010/3/16/justintvs-live-video-broadcasting-architecture.html) | +| Facebook | [Scaling memcached at Facebook](https://cs.uwaterloo.ca/~brecht/courses/854-Emerging-2014/readings/key-value/fb-memcached-nsdi-2013.pdf)
[TAO: Facebook’s distributed data store for the social graph](https://cs.uwaterloo.ca/~brecht/courses/854-Emerging-2014/readings/data-store/tao-facebook-distributed-datastore-atc-2013.pdf)
[Facebook’s photo storage](https://www.usenix.org/legacy/event/osdi10/tech/full_papers/Beaver.pdf) | +| Flickr | [Flickr architecture](http://highscalability.com/flickr-architecture) | +| Mailbox | [From 0 to one million users in 6 weeks](http://highscalability.com/blog/2013/6/18/scaling-mailbox-from-0-to-one-million-users-in-6-weeks-and-1.html) | +| Pinterest | [From 0 To 10s of billions of page views a month](http://highscalability.com/blog/2013/4/15/scaling-pinterest-from-0-to-10s-of-billions-of-page-views-a.html)
[18 million visitors, 10x growth, 12 employees](http://highscalability.com/blog/2012/5/21/pinterest-architecture-update-18-million-visitors-10x-growth.html) | +| Playfish | [50 million monthly users and growing](http://highscalability.com/blog/2010/9/21/playfishs-social-gaming-architecture-50-million-monthly-user.html) | +| PlentyOfFish | [PlentyOfFish architecture](http://highscalability.com/plentyoffish-architecture) | +| Salesforce | [How they handle 1.3 billion transactions a day](http://highscalability.com/blog/2013/9/23/salesforce-architecture-how-they-handle-13-billion-transacti.html) | | Stack Overflow | [Stack Overflow architecture](http://highscalability.com/blog/2009/8/5/stack-overflow-architecture.html) | -| TripAdvisor | [40M visitors, 200M dynamic page views, 30TB data](http://highscalability.com/blog/2011/6/27/tripadvisor-architecture-40m-visitors-200m-dynamic-page-view.html) | -| Tumblr | [15 billion page views a month](http://highscalability.com/blog/2012/2/13/tumblr-architecture-15-billion-page-views-a-month-and-harder.html) | -| Twitter | [Making Twitter 10000 percent faster](http://highscalability.com/scaling-twitter-making-twitter-10000-percent-faster)
[Storing 250 million tweets a day using MySQL](http://highscalability.com/blog/2011/12/19/how-twitter-stores-250-million-tweets-a-day-using-mysql.html)
[150M active users, 300K QPS, a 22 MB/S firehose](http://highscalability.com/blog/2013/7/8/the-architecture-twitter-uses-to-deal-with-150m-active-users.html)
[Timelines at scale](https://www.infoq.com/presentations/Twitter-Timeline-Scalability)
[Big and small data at Twitter](https://www.youtube.com/watch?v=5cKTP36HVgI)
[Operations at Twitter: scaling beyond 100 million users](https://www.youtube.com/watch?v=z8LU0Cj6BOU) | -| Uber | [How Uber scales their real-time market platform](http://highscalability.com/blog/2015/9/14/how-uber-scales-their-real-time-market-platform.html) | -| WhatsApp | [The WhatsApp architecture Facebook bought for $19 billion](http://highscalability.com/blog/2014/2/26/the-whatsapp-architecture-facebook-bought-for-19-billion.html) | -| YouTube | [YouTube scalability](https://www.youtube.com/watch?v=w5WVu624fY8)
[YouTube architecture](http://highscalability.com/youtube-architecture) | +| TripAdvisor | [40M visitors, 200M dynamic page views, 30TB data](http://highscalability.com/blog/2011/6/27/tripadvisor-architecture-40m-visitors-200m-dynamic-page-view.html) | +| Tumblr | [15 billion page views a month](http://highscalability.com/blog/2012/2/13/tumblr-architecture-15-billion-page-views-a-month-and-harder.html) | +| Twitter | [Making Twitter 10000 percent faster](http://highscalability.com/scaling-twitter-making-twitter-10000-percent-faster)
[Storing 250 million tweets a day using MySQL](http://highscalability.com/blog/2011/12/19/how-twitter-stores-250-million-tweets-a-day-using-mysql.html)
[150M active users, 300K QPS, a 22 MB/S firehose](http://highscalability.com/blog/2013/7/8/the-architecture-twitter-uses-to-deal-with-150m-active-users.html)
[Timelines at scale](https://www.infoq.com/presentations/Twitter-Timeline-Scalability)
[Big and small data at Twitter](https://www.youtube.com/watch?v=5cKTP36HVgI)
[Operations at Twitter: scaling beyond 100 million users](https://www.youtube.com/watch?v=z8LU0Cj6BOU) | +| Uber | [How Uber scales their real-time market platform](http://highscalability.com/blog/2015/9/14/how-uber-scales-their-real-time-market-platform.html) | +| WhatsApp | [The WhatsApp architecture Facebook bought for $19 billion](http://highscalability.com/blog/2014/2/26/the-whatsapp-architecture-facebook-bought-for-19-billion.html) | +| YouTube | [YouTube scalability](https://www.youtube.com/watch?v=w5WVu624fY8)
[YouTube architecture](http://highscalability.com/youtube-architecture) | ### Company engineering blogs From 0210556892ecfa9cfe01a56fec4139101030135b Mon Sep 17 00:00:00 2001 From: xiaoyusilen Date: Mon, 3 Apr 2017 23:14:25 +0800 Subject: [PATCH 03/16] Modify details --- README-zh-Hant.md | 168 +++++++++++++++++++++++----------------------- 1 file changed, 84 insertions(+), 84 deletions(-) mode change 100644 => 100755 README-zh-Hant.md diff --git a/README-zh-Hant.md b/README-zh-Hant.md old mode 100644 new mode 100755 index 3861e03e..86c456f8 --- a/README-zh-Hant.md +++ b/README-zh-Hant.md @@ -1020,17 +1020,17 @@ Graphs databases offer high performance for data models with complex relationshi ##### 相关资源和延伸阅读:图 -* [图数据库](https://en.wikipedia.org/wiki/Graph_database) -* [Neo4j](https://neo4j.com/) -* [FlockDB](https://blog.twitter.com/2010/introducing-flockdb) +- [图数据库](https://en.wikipedia.org/wiki/Graph_database) +- [Neo4j](https://neo4j.com/) +- [FlockDB](https://blog.twitter.com/2010/introducing-flockdb) #### 相关资源和延伸阅读:NoSQL -* [基础术语解释](http://stackoverflow.com/questions/3342497/explanation-of-base-terminology) -* [NoSQL 数据库 — 调查与决策指导](https://medium.com/baqend-blog/nosql-databases-a-survey-and-decision-guidance-ea7823a822d#.wskogqenq) -* [可扩展性](http://www.lecloud.net/post/7994751381/scalability-for-dummies-part-2-database) -* [NoSQL 的介绍](https://www.youtube.com/watch?v=qI_g07C_Q5I) -* [NoSQL 模式](http://horicky.blogspot.com/2009/11/nosql-patterns.html) +- [基础术语解释](http://stackoverflow.com/questions/3342497/explanation-of-base-terminology) +- [NoSQL 数据库 — 调查与决策指导](https://medium.com/baqend-blog/nosql-databases-a-survey-and-decision-guidance-ea7823a822d#.wskogqenq) +- [可扩展性](http://www.lecloud.net/post/7994751381/scalability-for-dummies-part-2-database) +- [NoSQL 的介绍](https://www.youtube.com/watch?v=qI_g07C_Q5I) +- [NoSQL 模式](http://horicky.blogspot.com/2009/11/nosql-patterns.html) ### SQL 还是 NoSQL @@ -1042,37 +1042,37 @@ Graphs databases offer high performance for data models with complex relationshi 选择 **SQL** 的原因: -* 结构化数据 -* 严格的架构 -* 关系型数据 -* 需要复杂的 joins -* 事务 -* 清除缩放模式 -* 更成熟的开发人员,社区,代码,工具等等 -* 通过索引查找非常快 +- 结构化数据 +- 严格的架构 +- 关系型数据 +- 需要复杂的 joins +- 事务 +- 清除缩放模式 +- 更成熟的开发人员,社区,代码,工具等等 +- 通过索引查找非常快 选择 **NoSQL** 的原因: -* 半结构化数据 -* 动态/灵活的模式 -* 非关系型数据 -* 不需要复杂的 joins 操作 -* 可以存储大量 TB/PB 数据 -* 非常数据密集的工作量 -* 非常高的 IOPS 吞吐量 +- 半结构化数据 +- 动态/灵活的模式 +- 非关系型数据 +- 不需要复杂的 joins 操作 +- 可以存储大量 TB/PB 数据 +- 非常数据密集的工作量 +- 非常高的 IOPS 吞吐量 适合 NoSQL 操作的数据: -* 埋点数据以及日志数据 -* 排行榜或者得分数据 -* 临时数据,比如购物车 -* 需要频繁访问的表 -* 元数据/查找表 +- 埋点数据以及日志数据 +- 排行榜或者得分数据 +- 临时数据,比如购物车 +- 需要频繁访问的表 +- 元数据/查找表 相关资源和延伸阅读:SQL 还是 NoSQL -* [扩大您的用户到第一个1000万](https://www.youtube.com/watch?v=vg5onp8TU6Q) -* [SQL 和 NoSQL 的不同](https://www.sitepoint.com/sql-vs-nosql-differences/) +- [扩大您的用户到第一个1000万](https://www.youtube.com/watch?v=vg5onp8TU6Q) +- [SQL 和 NoSQL 的不同](https://www.sitepoint.com/sql-vs-nosql-differences/) ## 缓存 @@ -1108,15 +1108,15 @@ Graphs databases offer high performance for data models with complex relationshi Redis 有下列附加功能: -* 持久性选项 -* 内置数据结构比如有序集合和列表 +- 持久性选项 +- 内置数据结构比如有序集合和列表 有多个缓存级别,分为两大类:**数据库查询**和**对象**: -* 行级别 -* 查询级别 -* 完整的可序列化对象 -* 完全渲染的 HTML +- 行级别 +- 查询级别 +- 完整的可序列化对象 +- 完全渲染的 HTML 一般来说,你应该尽量避免基于文件的缓存,因为这使得复制和自动缩放很困难。 @@ -1124,22 +1124,22 @@ Redis 有下列附加功能: 当你查询数据库的时候,将查询结果作为关键字同时将结果存储到缓存中。这种方法会遇到以下问题: -* 很难用复杂的查询删除已缓存结果。 -* 如果一条数据比如表中某条数据的一项被改变,则需要删除所有可能包含已更改项的缓存结果。 +- 很难用复杂的查询删除已缓存结果。 +- 如果一条数据比如表中某条数据的一项被改变,则需要删除所有可能包含已更改项的缓存结果。 ### 对象级别的缓存 将您的数据视为对象,就像对待你的应用代码一样。 让应用程序将数据从数据库中组合到类实例或数据结构中: -* 如果对象的基础数据已经更改了,那么从缓存中删掉这个对象。 -* 允许异步处理:workers 通过使用最新的缓存对象来组装对象。 +- 如果对象的基础数据已经更改了,那么从缓存中删掉这个对象。 +- 允许异步处理:workers 通过使用最新的缓存对象来组装对象。 建议缓存的内容: -* 用户会话 -* 完全渲染的 Web 页面 -* 活动流 -* 用户图数据 +- 用户会话 +- 完全渲染的 Web 页面 +- 活动流 +- 用户图数据 ### 何时更新缓存 @@ -1155,10 +1155,10 @@ Redis 有下列附加功能: 应用从存储器读写。缓存不和存储器直接交互,应用执行以下操作: -* 在缓存中查找记录,如果所需数据不在缓存中 -* 从数据库中加载所需内容 -* 将查找到的结果存储到缓存中 -* 返回所需内容 +- 在缓存中查找记录,如果所需数据不在缓存中 +- 从数据库中加载所需内容 +- 将查找到的结果存储到缓存中 +- 返回所需内容 ``` def get_user(self, user_id): @@ -1177,9 +1177,9 @@ def get_user(self, user_id): ##### 缓存的缺点: -* 每一次所需数据不在缓存中都需要经历三个过程,这会导致明显的延迟。 -* 如果数据库中的数据更新了会导致缓存中的数据过时。这个问题需要通过设置 TTL 强制更新缓存或者直写模式来缓解这种情况。 -* 当一个节点出现故障的时候,它将会被一个新的节点替代,这增加了延迟的时间。 +- 每一次所需数据不在缓存中都需要经历三个过程,这会导致明显的延迟。 +- 如果数据库中的数据更新了会导致缓存中的数据过时。这个问题需要通过设置 TTL 强制更新缓存或者直写模式来缓解这种情况。 +- 当一个节点出现故障的时候,它将会被一个新的节点替代,这增加了延迟的时间。 #### 直写模式 @@ -1191,9 +1191,9 @@ def get_user(self, user_id): 应用使用缓存作为主要的数据存储,将数据读写到缓存中,而缓存负责从数据库中读写数据。 -* 应用向缓存中添加/更新数据 -* 缓存将所需内容写入数据存储 -* 返回所需内容 +- 应用向缓存中添加/更新数据 +- 缓存将所需内容写入数据存储 +- 返回所需内容 应用代码: @@ -1213,8 +1213,8 @@ def set_user(user_id, values): ##### 直写模式的缺点: -* 由于故障或者缩放而创建的新的节点,新的节点不会缓存,直到数据库更新为止。缓存应用直写模式可以缓解这个问题。 -* 写入的大多数数据可能永远都不会被读取,用 TTL 可以最小化这种情况的出现。 +- 由于故障或者缩放而创建的新的节点,新的节点不会缓存,直到数据库更新为止。缓存应用直写模式可以缓解这个问题。 +- 写入的大多数数据可能永远都不会被读取,用 TTL 可以最小化这种情况的出现。 #### 回写模式 @@ -1226,13 +1226,13 @@ def set_user(user_id, values): 在回写模式中,应用执行以下操作: -* 在缓存中增加或者更新条目 -* 异步写入数据,提高写入性能。 +- 在缓存中增加或者更新条目 +- 异步写入数据,提高写入性能。 ##### 回写模式的缺点: -* 缓存可能在其内容成功存储之前丢失数据。 -* 执行直写模式比缓存或者回写模式更复杂。 +- 缓存可能在其内容成功存储之前丢失数据。 +- 执行直写模式比缓存或者回写模式更复杂。 #### 刷新 @@ -1248,23 +1248,23 @@ def set_user(user_id, values): ##### 刷新的缺点: -* 不能准确预测到未来需要用到的数据可能会导致性能不如不使用刷新。 +- 不能准确预测到未来需要用到的数据可能会导致性能不如不使用刷新。 ### 缓存的缺点: -* 需要保持缓存和真实数据源之间的一致性,比如数据库根据[缓存无效](https://en.wikipedia.org/wiki/Cache_algorithms)。 -* 需要改变应用程序比如增加 Redis 或者 memcached。 -* 无效缓存是个难题,什么时候更新缓存是额外复杂的问题。 +- 需要保持缓存和真实数据源之间的一致性,比如数据库根据[缓存无效](https://en.wikipedia.org/wiki/Cache_algorithms)。 +- 需要改变应用程序比如增加 Redis 或者 memcached。 +- 无效缓存是个难题,什么时候更新缓存是额外复杂的问题。 ### 相关资源和延伸阅读 -* [从缓存到内存数据](http://www.slideshare.net/tmatyashovsky/from-cache-to-in-memory-data-grid-introduction-to-hazelcast) -* [可扩展系统设计模式](http://horicky.blogspot.com/2010/10/scalable-system-design-patterns.html) -* [scale 的系统架构介绍](http://lethain.com/introduction-to-architecting-systems-for-scale/) -* [可扩展性,可用性,稳定性,模式](http://www.slideshare.net/jboner/scalability-availability-stability-patterns/) -* [可扩展性]((http://www.lecloud.net/post/9246290032/scalability-for-dummies-part-3-cache)) -* [AWS ElastiCache 策略](http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/Strategies.html) -* [维基百科](https://en.wikipedia.org/wiki/Cache_(computing)) +- [从缓存到内存数据](http://www.slideshare.net/tmatyashovsky/from-cache-to-in-memory-data-grid-introduction-to-hazelcast) +- [可扩展系统设计模式](http://horicky.blogspot.com/2010/10/scalable-system-design-patterns.html) +- [scale 的系统架构介绍](http://lethain.com/introduction-to-architecting-systems-for-scale/) +- [可扩展性,可用性,稳定性,模式](http://www.slideshare.net/jboner/scalability-availability-stability-patterns/) +- [可扩展性]((http://www.lecloud.net/post/9246290032/scalability-for-dummies-part-3-cache)) +- [AWS ElastiCache 策略](http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/Strategies.html) +- [维基百科](https://en.wikipedia.org/wiki/Cache_(computing)) ## 异步 @@ -1280,8 +1280,8 @@ def set_user(user_id, values): 消息队列接收,保留和传递消息。如果按顺序执行操作太慢的话,你可以使用有以下工作流的消息队列: -* 应用程序将作业发布到队列,然后通知用户作业状态 -* 一个 worker 从队列中取出该作业,对其进行处理,然后显示该作业完成 +- 应用程序将作业发布到队列,然后通知用户作业状态 +- 一个 worker 从队列中取出该作业,对其进行处理,然后显示该作业完成 用户未被阻止,作业在后台处理。在此期间,客户端可能会进行一些处理使得看上去像是任务已经完成了。例如,如果要发送一条推文,推文可能会马上出现在你的时间线上,但是可能需要一些时间才能将你的推文推送到你的所有关注者那里去。 @@ -1303,14 +1303,14 @@ def set_user(user_id, values): ### 异步的缺点: -* 廉价计算和实时工作流等用例可能更适用于同步操作,因为引入队列可能会增加延迟和复杂性。 +- 廉价计算和实时工作流等用例可能更适用于同步操作,因为引入队列可能会增加延迟和复杂性。 ### 相关资源和延伸阅读 -* [这是一个数字游戏](https://www.youtube.com/watch?v=1KRYH75wgy4) -* [超载时应用背压](http://mechanical-sympathy.blogspot.com/2012/05/apply-back-pressure-when-overloaded.html) -* [利特尔法则](https://en.wikipedia.org/wiki/Little%27s_law) -* [消息队列与任务队列有什么区别?](https://www.quora.com/What-is-the-difference-between-a-message-queue-and-a-task-queue-Why-would-a-task-queue-require-a-message-broker-like-RabbitMQ-Redis-Celery-or-IronMQ-to-function) +- [这是一个数字游戏](https://www.youtube.com/watch?v=1KRYH75wgy4) +- [超载时应用背压](http://mechanical-sympathy.blogspot.com/2012/05/apply-back-pressure-when-overloaded.html) +- [利特尔法则](https://en.wikipedia.org/wiki/Little%27s_law) +- [消息队列与任务队列有什么区别?](https://www.quora.com/What-is-the-difference-between-a-message-queue-and-a-task-queue-Why-would-a-task-queue-require-a-message-broker-like-RabbitMQ-Redis-Celery-or-IronMQ-to-function) ## 通讯 @@ -1338,8 +1338,8 @@ HTTP 是一种在客户端和服务器之间编码和传输数据的方法。它 HTTP 是依赖于较低级协议(如 **TCP** 和 **UDP**)的应用层协议。 -* [HTTP](https://www.nginx.com/resources/glossary/http/) -* [README](https://www.quora.com/What-is-the-difference-between-HTTP-protocol-and-TCP-protocol) +- [HTTP](https://www.nginx.com/resources/glossary/http/) +- [README](https://www.quora.com/What-is-the-difference-between-HTTP-protocol-and-TCP-protocol) ### 传输控制协议(TCP) @@ -1351,8 +1351,8 @@ HTTP 是依赖于较低级协议(如 **TCP** 和 **UDP**)的应用层协议 TCP 是通过 [IP 网络](https://en.wikipedia.org/wiki/Internet_Protocol)的面向连接的协议。 使用[握手](https://en.wikipedia.org/wiki/Handshaking)建立和断开连接。 发送的所有数据包保证以原始顺序到达目的地,用以下措施保证数据包不被损坏: -* 每个数据包的序列号和[校验码](https://en.wikipedia.org/wiki/Transmission_Control_Protocol#Checksum_computation)。 -* [确认包](https://en.wikipedia.org/wiki/Acknowledgement_(data_networks))和自动重传 +- 每个数据包的序列号和[校验码](https://en.wikipedia.org/wiki/Transmission_Control_Protocol#Checksum_computation)。 +- [确认包](https://en.wikipedia.org/wiki/Acknowledgement_(data_networks))和自动重传 如果发送者没有收到正确的响应,它将重新发送数据包。如果多次超时,连接就会断开。TCP 实行[流量控制](https://en.wikipedia.org/wiki/Flow_control_(data))和[拥塞控制](https://en.wikipedia.org/wiki/Network_congestion#Congestion_control)。这些确保措施会导致延迟,而且通常导致传输效率比 UDP 低。 @@ -1362,8 +1362,8 @@ TCP 对于需要高可靠性但时间紧迫的应用程序很有用。比如包 什么时候使用 TCP over UDP: -* 你需要数据完好无损。 -* 你想对网络吞吐量自动进行最佳评估。 +- 你需要数据完好无损。 +- 你想对网络吞吐量自动进行最佳评估。 ### User datagram protocol (UDP) From 6c7257db45f1eb01a4a07c095aee180d6d1fcd79 Mon Sep 17 00:00:00 2001 From: xiaoyusilen Date: Tue, 4 Apr 2017 20:29:31 +0800 Subject: [PATCH 04/16] Modify details --- README-zh-Hant.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README-zh-Hant.md b/README-zh-Hant.md index 86c456f8..18152d22 100755 --- a/README-zh-Hant.md +++ b/README-zh-Hant.md @@ -1260,7 +1260,7 @@ def set_user(user_id, values): - [从缓存到内存数据](http://www.slideshare.net/tmatyashovsky/from-cache-to-in-memory-data-grid-introduction-to-hazelcast) - [可扩展系统设计模式](http://horicky.blogspot.com/2010/10/scalable-system-design-patterns.html) -- [scale 的系统架构介绍](http://lethain.com/introduction-to-architecting-systems-for-scale/) +- [大型系统架构介绍](http://lethain.com/introduction-to-architecting-systems-for-scale/) - [可扩展性,可用性,稳定性,模式](http://www.slideshare.net/jboner/scalability-availability-stability-patterns/) - [可扩展性]((http://www.lecloud.net/post/9246290032/scalability-for-dummies-part-3-cache)) - [AWS ElastiCache 策略](http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/Strategies.html) From c72b9591f23b0345a452cc54013d9caccf609cdc Mon Sep 17 00:00:00 2001 From: xujifa Date: Fri, 7 Apr 2017 11:53:09 +0800 Subject: [PATCH 05/16] =?UTF-8?q?=E7=BF=BB=E8=AF=91=E5=BB=B6=E4=BC=B8?= =?UTF-8?q?=E9=98=85=E8=AF=BB=E9=87=8C=E7=9A=84=E6=96=87=E7=AB=A0=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README-zh-Hant.md | 52 +++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/README-zh-Hant.md b/README-zh-Hant.md index ed562327..74451879 100644 --- a/README-zh-Hant.md +++ b/README-zh-Hant.md @@ -1385,14 +1385,14 @@ UDP 可靠性更低但适合用在网络电话、视频聊天,流(这个不 * 相对于数据丢失更糟的是数据延迟 * 你想实现自己的错误校正方法 -#### 延伸阅读:TCP 与 UDP +#### 来源及延伸阅读:TCP 与 UDP -* [Networking for game programming](http://gafferongames.com/networking-for-game-programmers/udp-vs-tcp/) -* [Key differences between TCP and UDP protocols](http://www.cyberciti.biz/faq/key-differences-between-tcp-and-udp-protocols/) -* [Difference between TCP and UDP](http://stackoverflow.com/questions/5970383/difference-between-tcp-and-udp) -* [Transmission control protocol](https://en.wikipedia.org/wiki/Transmission_Control_Protocol) -* [User datagram protocol](https://en.wikipedia.org/wiki/User_Datagram_Protocol) -* [Scaling memcache at Facebook](http://www.cs.bu.edu/~jappavoo/jappavoo.github.com/451/papers/memcache-fb.pdf) +* [游戏编程的网络](http://gafferongames.com/networking-for-game-programmers/udp-vs-tcp/) +* [TCP 与 UDP 的关键区别](http://www.cyberciti.biz/faq/key-differences-between-tcp-and-udp-protocols/) +* [TCP 与 UDP 的不同](http://stackoverflow.com/questions/5970383/difference-between-tcp-and-udp) +* [传输控制协议](https://en.wikipedia.org/wiki/Transmission_Control_Protocol) +* [用户数据报协议](https://en.wikipedia.org/wiki/User_Datagram_Protocol) +* [Facebook 对内存缓存的扩展](http://www.cs.bu.edu/~jappavoo/jappavoo.github.com/451/papers/memcache-fb.pdf) ### 远程过程调用协议(RPC) @@ -1488,16 +1488,16 @@ REST 关注于暴露数据。它最小化了客户端与服务端的联系并经 Source: Do you really know why you prefer REST over RPC

-#### 延伸阅读:REST 与 RPC +#### 来源及延伸阅读:REST 与 RPC -* [Do you really know why you prefer REST over RPC](https://apihandyman.io/do-you-really-know-why-you-prefer-rest-over-rpc/) -* [When are RPC-ish approaches more appropriate than REST?](http://programmers.stackexchange.com/a/181186) +* [你知道你为什么更喜欢 REST 而不是 RPC 吗](https://apihandyman.io/do-you-really-know-why-you-prefer-rest-over-rpc/) +* [什么时候 RPC 比 REST 更合适?](http://programmers.stackexchange.com/a/181186) * [REST vs JSON-RPC](http://stackoverflow.com/questions/15056878/rest-vs-json-rpc) -* [Debunking the myths of RPC and REST](http://etherealbits.com/2012/12/debunking-the-myths-of-rpc-rest/) -* [What are the drawbacks of using REST](https://www.quora.com/What-are-the-drawbacks-of-using-RESTful-APIs) -* [Crack the system design interview](http://www.puncsky.com/blog/2016/02/14/crack-the-system-design-interview/) -* [Thrift](https://code.facebook.com/posts/1468950976659943/) -* [Why REST for internal use and not RPC](http://arstechnica.com/civis/viewtopic.php?t=1190508) +* [揭开 RPC 和 REST 的神秘面纱](http://etherealbits.com/2012/12/debunking-the-myths-of-rpc-rest/) +* [使用 REST 的缺点是什么](https://www.quora.com/What-are-the-drawbacks-of-using-RESTful-APIs) +* [破解系统设计面试](http://www.puncsky.com/blog/2016/02/14/crack-the-system-design-interview/) +* [节约](https://code.facebook.com/posts/1468950976659943/) +* [为什么在内部使用 REST 而不是 RPC](http://arstechnica.com/civis/viewtopic.php?t=1190508) ## 安全 @@ -1510,9 +1510,9 @@ REST 关注于暴露数据。它最小化了客户端与服务端的联系并经 * 使用参数化的查询来防止 SQL 注入。 * 使用[最小权限原则](https://en.wikipedia.org/wiki/Principle_of_least_privilege)。 -### 延伸阅读 +### 来源及延伸阅读 -* [Security guide for developers](https://github.com/FallibleInc/security-guide-for-developers) +* [为开发者准备的安全引导](https://github.com/FallibleInc/security-guide-for-developers) * [OWASP top ten](https://www.owasp.org/index.php/OWASP_Top_Ten_Cheat_Sheet) ## 附录 @@ -1534,11 +1534,11 @@ Power Exact Value Approx Value Bytes 40 1,099,511,627,776 1 trillion 1 TB ``` -#### 延伸阅读 +#### 来源及延伸阅读 -* [Powers of two](https://en.wikipedia.org/wiki/Power_of_two) +* [2 的次方](https://en.wikipedia.org/wiki/Power_of_two) -### Latency numbers every programmer should know +### 每个程序员都应该知道的延迟数 ``` Latency Comparison Numbers @@ -1578,12 +1578,12 @@ Notes ![](https://camo.githubusercontent.com/77f72259e1eb58596b564d1ad823af1853bc60a3/687474703a2f2f692e696d6775722e636f6d2f6b307431652e706e67) -#### 延伸阅读 +#### 来源及延伸阅读 -* [Latency numbers every programmer should know - 1](https://gist.github.com/jboner/2841832) -* [Latency numbers every programmer should know - 2](https://gist.github.com/hellerbarde/2843375) -* [Designs, lessons, and advice from building large distributed systems](http://www.cs.cornell.edu/projects/ladis2009/talks/dean-keynote-ladis2009.pdf) -* [Software Engineering Advice from Building Large-Scale Distributed Systems](https://static.googleusercontent.com/media/research.google.com/en//people/jeff/stanford-295-talk.pdf) +* [每个程序员都应该知道的延迟数 — 1](https://gist.github.com/jboner/2841832) +* [每个程序员都应该知道的延迟数 — 2](https://gist.github.com/hellerbarde/2843375) +* [关于建设大型分布式系统的的设计方案、课程和建议](http://www.cs.cornell.edu/projects/ladis2009/talks/dean-keynote-ladis2009.pdf) +* [关于建设大型可拓展分布式系统的软件工程咨询](https://static.googleusercontent.com/media/research.google.com/en//people/jeff/stanford-295-talk.pdf) ### 额外的系统设计面试问题 @@ -1729,7 +1729,7 @@ Notes * [Yelp Engineering Blog](http://engineeringblog.yelp.com/) * [Zynga Engineering Blog](https://www.zynga.com/blogs/engineering) -#### 延伸阅读 +#### 来源及延伸阅读 * [kilimchoi/engineering-blogs](https://github.com/kilimchoi/engineering-blogs) From 56e41d34e0ecc70b288fd588322a679e9ada82e3 Mon Sep 17 00:00:00 2001 From: xiaoyusilen Date: Sat, 8 Apr 2017 09:31:05 +0800 Subject: [PATCH 06/16] Change translation details --- README-zh-Hant.md | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/README-zh-Hant.md b/README-zh-Hant.md index 18152d22..ec51b7e3 100755 --- a/README-zh-Hant.md +++ b/README-zh-Hant.md @@ -1047,7 +1047,7 @@ Graphs databases offer high performance for data models with complex relationshi - 关系型数据 - 需要复杂的 joins - 事务 -- 清除缩放模式 +- 清晰的缩放模式 - 更成熟的开发人员,社区,代码,工具等等 - 通过索引查找非常快 @@ -1082,7 +1082,7 @@ Graphs databases offer high performance for data models with complex relationshi Source: Scalable system design patterns

-缓存可以提高页面加载时间,并可以减少服务器和数据库的负载。在这个模式中,分发器会先去查看这个请求之前是否处理过,如果可以找到之前的结果那么就返回至客户端,否则,就将请求分发至处理池,以便将实际的处理结果存储至缓存中。 +缓存可以提高页面加载速度,并可以减少服务器和数据库的负载。在这个模型中,分发器先查看请求之前是否被响应过,如果有则将之前的结果直接返回,来省掉真正的处理。 数据库分片均匀分布的读取是最好的。但是热门数据会让读取分布不均匀,这样就会造成瓶颈,如果在数据库前加个缓存,就会抹平不均匀的负载和突发流量对数据库的影响。 @@ -1090,9 +1090,9 @@ Graphs databases offer high performance for data models with complex relationshi 缓存可以位于客户端(操作系统或者浏览器),[服务端](#reverse-proxy)或者不同的缓存层。 -### CDN缓存 +### CDN 缓存 -[CDNs](#content-delivery-network) 也是一种缓存。 +[CDNs](#content-delivery-network) 也被视为一种缓存。 ### Web 服务器缓存 @@ -1100,11 +1100,11 @@ Graphs databases offer high performance for data models with complex relationshi ### 数据库缓存 -数据库的默认配置中通常包含缓存级别,针对一般用例进行了优化。调整配置中在不同情况下使用不同的模式可以进一步提高性能。 +数据库的默认配置中通常包含缓存级别,针对一般用例进行了优化。调整配置,在不同情况下使用不同的模式可以进一步提高性能。 ### 应用缓存 -基于内存的缓存比如 Memcached 和 Redis 是应用程序和数据存储之间的一种键值存储。由于数据保存在 RAM 中,它比存储在磁盘上的典型数据库要快多了。RAM 比磁盘限制更多,所以[缓存无效算法](https://en.wikipedia.org/wiki/Cache_algorithms)比如 [least recently used (LRU)](https://en.wikipedia.org/wiki/Cache_algorithms#Least_Recently_Used) 可以将「热门数据」放在 RAM 中,而对一些比较「冷门」的数据不做处理。 +基于内存的缓存比如 Memcached 和 Redis 是应用程序和数据存储之间的一种键值存储。由于数据保存在 RAM 中,它比存储在磁盘上的典型数据库要快多了。RAM 比磁盘限制更多,所以例如 [least recently used (LRU)](https://en.wikipedia.org/wiki/Cache_algorithms#Least_Recently_Used) 的[缓存无效算法](https://en.wikipedia.org/wiki/Cache_algorithms)可以将「热门数据」放在 RAM 中,而对一些比较「冷门」的数据不做处理。 Redis 有下列附加功能: @@ -1122,14 +1122,14 @@ Redis 有下列附加功能: ### 数据库查询级别的缓存 -当你查询数据库的时候,将查询结果作为关键字同时将结果存储到缓存中。这种方法会遇到以下问题: +当你查询数据库的时候,将查询语句的哈希值与查询结果存储到缓存中。这种方法会遇到以下问题: - 很难用复杂的查询删除已缓存结果。 - 如果一条数据比如表中某条数据的一项被改变,则需要删除所有可能包含已更改项的缓存结果。 ### 对象级别的缓存 -将您的数据视为对象,就像对待你的应用代码一样。 让应用程序将数据从数据库中组合到类实例或数据结构中: +将您的数据视为对象,就像对待你的应用代码一样。让应用程序将数据从数据库中组合到类实例或数据结构中: - 如果对象的基础数据已经更改了,那么从缓存中删掉这个对象。 - 允许异步处理:workers 通过使用最新的缓存对象来组装对象。 @@ -1177,7 +1177,7 @@ def get_user(self, user_id): ##### 缓存的缺点: -- 每一次所需数据不在缓存中都需要经历三个过程,这会导致明显的延迟。 +- 请求的数据如果不在缓存中就需要经过三个步骤来获取数据,这会导致明显的延迟。 - 如果数据库中的数据更新了会导致缓存中的数据过时。这个问题需要通过设置 TTL 强制更新缓存或者直写模式来缓解这种情况。 - 当一个节点出现故障的时候,它将会被一个新的节点替代,这增加了延迟的时间。 @@ -1192,7 +1192,7 @@ def get_user(self, user_id): 应用使用缓存作为主要的数据存储,将数据读写到缓存中,而缓存负责从数据库中读写数据。 - 应用向缓存中添加/更新数据 -- 缓存将所需内容写入数据存储 +- 缓存同步地写入数据存储 - 返回所需内容 应用代码: @@ -1209,7 +1209,7 @@ def set_user(user_id, values): cache.set(user_id, user) ``` -由于读写操作所以直写模式整体是一种很慢的操作,但是读取刚写入的数据很快。相比读取数据,用户通常比较能接受更新数据时速度较慢。缓存中的数据不会过时。 +由于存写操作所以直写模式整体是一种很慢的操作,但是读取刚写入的数据很快。相比读取数据,用户通常比较能接受更新数据时速度较慢。缓存中的数据不会过时。 ##### 直写模式的缺点: @@ -1254,7 +1254,7 @@ def set_user(user_id, values): - 需要保持缓存和真实数据源之间的一致性,比如数据库根据[缓存无效](https://en.wikipedia.org/wiki/Cache_algorithms)。 - 需要改变应用程序比如增加 Redis 或者 memcached。 -- 无效缓存是个难题,什么时候更新缓存是额外复杂的问题。 +- 无效缓存是个难题,什么时候更新缓存是与之相关的复杂问题。 ### 相关资源和延伸阅读 @@ -1274,7 +1274,7 @@ def set_user(user_id, values): Source: Intro to architecting systems for scale

-异步工作流有助于减少操作的请求时间否则它们就会按顺序执行。它们可以通过提前进行一些耗时的工作来帮助减少请求时间,比如定期汇总数据。 +异步工作流有助于减少那些原本顺序执行的请求时间。它们可以通过提前进行一些耗时的工作来帮助减少请求时间,比如定期汇总数据。 ### 消息队列 @@ -1283,7 +1283,7 @@ def set_user(user_id, values): - 应用程序将作业发布到队列,然后通知用户作业状态 - 一个 worker 从队列中取出该作业,对其进行处理,然后显示该作业完成 -用户未被阻止,作业在后台处理。在此期间,客户端可能会进行一些处理使得看上去像是任务已经完成了。例如,如果要发送一条推文,推文可能会马上出现在你的时间线上,但是可能需要一些时间才能将你的推文推送到你的所有关注者那里去。 +不去阻塞用户操作,作业在后台处理。在此期间,客户端可能会进行一些处理使得看上去像是任务已经完成了。例如,如果要发送一条推文,推文可能会马上出现在你的时间线上,但是可能需要一些时间才能将你的推文推送到你的所有关注者那里去。 **Redis** 是一个令人满意的简单的消息代理,但是消息有可能会丢失。 @@ -1303,7 +1303,7 @@ def set_user(user_id, values): ### 异步的缺点: -- 廉价计算和实时工作流等用例可能更适用于同步操作,因为引入队列可能会增加延迟和复杂性。 +- 简单的计算和实时工作流等用例可能更适用于同步操作,因为引入队列可能会增加延迟和复杂性。 ### 相关资源和延伸阅读 @@ -1324,15 +1324,15 @@ def set_user(user_id, values): HTTP 是一种在客户端和服务器之间编码和传输数据的方法。它是一个请求/响应协议:客户端和服务端针对相关内容和完成状态信息的请求和响应。HTTP 是独立的,允许请求和响应流经许多执行负载均衡,缓存,加密和压缩的中间路由器和服务器。 -一个基本的 HTTP 请求由一个动词(方法)和一个资源(endpoint)组成。 以下是常见的 HTTP 动词: +一个基本的 HTTP 请求由一个动词(方法)和一个资源(端点)组成。 以下是常见的 HTTP 动词: -| 动词 | 描述 | *幂等 | 安全性 | 可缓存 | -| ------ | -------------- | ---- | ---- | ------------- | -| GET | 读取资源 | Yes | Yes | Yes | -| POST | 创建资源或触发处理数据的进程 | No | No | 可以,如果回应包含刷新信息 | -| PUT | 创建或替换资源 | Yes | No | No | -| PATCH | 部分更新资源 | No | No | 可以,如果回应包含刷新信息 | -| DELETE | 删除资源 | Yes | No | No | +| 动词 | 描述 | *幂等 | 安全性 | 可缓存 | +| ------ | -------------- | ---- | ---- | -------------- | +| GET | 读取资源 | Yes | Yes | Yes | +| POST | 创建资源或触发处理数据的进程 | No | No | Yes,如果回应包含刷新信息 | +| PUT | 创建或替换资源 | Yes | No | No | +| PATCH | 部分更新资源 | No | No | Yes,如果回应包含刷新信息 | +| DELETE | 删除资源 | Yes | No | No | *多次执行不会产生不同的结果。 From cf5005f4d7ceaf61a208269ba79e5f237553db5a Mon Sep 17 00:00:00 2001 From: xiaoyusilen Date: Sat, 8 Apr 2017 09:33:49 +0800 Subject: [PATCH 07/16] Modify again --- README-zh-Hant.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README-zh-Hant.md b/README-zh-Hant.md index ec51b7e3..3614bda5 100755 --- a/README-zh-Hant.md +++ b/README-zh-Hant.md @@ -1069,7 +1069,7 @@ Graphs databases offer high performance for data models with complex relationshi - 需要频繁访问的表 - 元数据/查找表 -相关资源和延伸阅读:SQL 还是 NoSQL +##### 相关资源和延伸阅读:SQL 还是 NoSQL - [扩大您的用户到第一个1000万](https://www.youtube.com/watch?v=vg5onp8TU6Q) - [SQL 和 NoSQL 的不同](https://www.sitepoint.com/sql-vs-nosql-differences/) From fb310d160781b2d425ab2ad98ada40a746578a7f Mon Sep 17 00:00:00 2001 From: xiaoyusilen Date: Sat, 8 Apr 2017 13:39:18 +0800 Subject: [PATCH 08/16] Final change --- README-zh-Hant.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README-zh-Hant.md b/README-zh-Hant.md index 3614bda5..1578239f 100755 --- a/README-zh-Hant.md +++ b/README-zh-Hant.md @@ -1360,7 +1360,7 @@ TCP 是通过 [IP 网络](https://en.wikipedia.org/wiki/Internet_Protocol)的面 TCP 对于需要高可靠性但时间紧迫的应用程序很有用。比如包括 Web 服务器,数据库信息,SMTP,FTP 和 SSH。 -什么时候使用 TCP over UDP: +以下情况使用 TCP 代替 UDP: - 你需要数据完好无损。 - 你想对网络吞吐量自动进行最佳评估。 From 23ecd1da2adf1f1bbdd5be92ed4da1f0100a5677 Mon Sep 17 00:00:00 2001 From: xiaoyusilen Date: Mon, 10 Apr 2017 21:13:29 +0800 Subject: [PATCH 09/16] change details --- README-zh-Hant.md | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/README-zh-Hant.md b/README-zh-Hant.md index f1f351b7..1b26bcd8 100755 --- a/README-zh-Hant.md +++ b/README-zh-Hant.md @@ -1325,7 +1325,6 @@ HTTP 是一种在客户端和服务器之间编码和传输数据的方法。它 一个基本的 HTTP 请求由一个动词(方法)和一个资源(端点)组成。 以下是常见的 HTTP 动词: -<<<<<<< HEAD | 动词 | 描述 | *幂等 | 安全性 | 可缓存 | | ------ | -------------- | ---- | ---- | -------------- | | GET | 读取资源 | Yes | Yes | Yes | @@ -1333,15 +1332,7 @@ HTTP 是一种在客户端和服务器之间编码和传输数据的方法。它 | PUT | 创建或替换资源 | Yes | No | No | | PATCH | 部分更新资源 | No | No | Yes,如果回应包含刷新信息 | | DELETE | 删除资源 | Yes | No | No | -======= -| Verb | Description | Idempotent* | Safe | Cacheable | -| ------ | ---------------------------------------- | ----------- | ---- | --------------------------------------- | -| 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 | -| PUT | Creates or replace a resource | Yes | No | No | -| PATCH | Partially updates a resource | No | No | Yes if response contains freshness info | -| DELETE | Deletes a resource | Yes | No | No | ->>>>>>> 5e2f3f50aeb57ab433d5fd8ca21f09bcb5fc4d83 +>>>>>>> *多次执行不会产生不同的结果。 From 85f01791c0bc8a75fc5911e6fbd95b81919b45e5 Mon Sep 17 00:00:00 2001 From: xiaoyusilen Date: Mon, 10 Apr 2017 21:43:36 +0800 Subject: [PATCH 10/16] change again:) --- README-zh-Hant.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/README-zh-Hant.md b/README-zh-Hant.md index 1b26bcd8..c5dd56d3 100755 --- a/README-zh-Hant.md +++ b/README-zh-Hant.md @@ -1261,7 +1261,7 @@ def set_user(user_id, values): - [可扩展系统设计模式](http://horicky.blogspot.com/2010/10/scalable-system-design-patterns.html) - [大型系统架构介绍](http://lethain.com/introduction-to-architecting-systems-for-scale/) - [可扩展性,可用性,稳定性,模式](http://www.slideshare.net/jboner/scalability-availability-stability-patterns/) -- [可扩展性]((http://www.lecloud.net/post/9246290032/scalability-for-dummies-part-3-cache)) +- [可扩展性](http://www.lecloud.net/post/9246290032/scalability-for-dummies-part-3-cache) - [AWS ElastiCache 策略](http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/Strategies.html) - [维基百科](https://en.wikipedia.org/wiki/Cache_(computing)) @@ -1332,8 +1332,6 @@ HTTP 是一种在客户端和服务器之间编码和传输数据的方法。它 | PUT | 创建或替换资源 | Yes | No | No | | PATCH | 部分更新资源 | No | No | Yes,如果回应包含刷新信息 | | DELETE | 删除资源 | Yes | No | No | ->>>>>>> - *多次执行不会产生不同的结果。 HTTP 是依赖于较低级协议(如 **TCP** 和 **UDP**)的应用层协议。 From f19dae323b39c18ed392785c02096418f03ca4ce Mon Sep 17 00:00:00 2001 From: L9m Date: Mon, 10 Apr 2017 22:34:10 +0800 Subject: [PATCH 11/16] =?UTF-8?q?=E9=87=8D=E6=96=B0=E6=8F=90=E4=BA=A4=20?= =?UTF-8?q?=E7=AC=AC=E4=BA=8C=E9=83=A8=E5=88=86=20=E7=BF=BB=E8=AF=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 重新提交 第二部分 翻译 --- README-zh-Hant.md | 337 +++++++++++++++++++++++----------------------- 1 file changed, 169 insertions(+), 168 deletions(-) diff --git a/README-zh-Hant.md b/README-zh-Hant.md index c5dd56d3..4693a384 100755 --- a/README-zh-Hant.md +++ b/README-zh-Hant.md @@ -339,267 +339,269 @@ ![Imgur](http://i.imgur.com/jj3A5N8.png) -## Object-oriented design interview questions with solutions +## 面向对象设计面试问题及解答 -> Common object-oriented design interview questions with sample discussions, code, and diagrams. +> 常见面向对象设计面试问题及实例讨论,代码和图表演示。 > -> Solutions linked to content in the `solutions/` folder. +> 与内容相关的解决方案在 `solutions/` 文件夹中。 ->**Note: This section is under development** +>**注:此节还在完善中** -| Question | | -| -------------------------------------- | ---------------------------------------- | -| 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 call center | [Solution](solutions/object_oriented_design/call_center/call_center.ipynb) | -| Design a deck of cards | [Solution](solutions/object_oriented_design/deck_of_cards/deck_of_cards.ipynb) | -| Design a parking lot | [Solution](solutions/object_oriented_design/parking_lot/parking_lot.ipynb) | -| Design a chat server | [Solution](solutions/object_oriented_design/online_chat/online_chat.ipynb) | -| Design a circular array | [Contribute](#contributing) | -| Add an object-oriented design question | [Contribute](#contributing) | +| 问题 | | +|---|---| +| 设计 hash map | [解决方案](solutions/object_oriented_design/hash_table/hash_map.ipynb) | +| 设计 LRU 缓存 | [解决方案](solutions/object_oriented_design/lru_cache/lru_cache.ipynb) | +| 设计一个呼叫中心 | [解决方案](solutions/object_oriented_design/call_center/call_center.ipynb) | +| 设计一副牌 | [解决方案](solutions/object_oriented_design/deck_of_cards/deck_of_cards.ipynb) | +| 设计一个停车场 | [解决方案](solutions/object_oriented_design/parking_lot/parking_lot.ipynb) | +| 设计一个聊天服务 | [解决方案](solutions/object_oriented_design/online_chat/online_chat.ipynb) | +| 设计一个环形数组 | [待解决](#contributing) | +| 添加一个面向对象设计问题 | [待解决](#contributing) | -## System design topics: start here +## 系统设计主题:从这里开始 -New to system design? +不熟悉系统设计? -First, you'll need a basic understanding of common principles, learning about what they are, how they are used, and their pros and cons. +首先,你需要对一般性原则有一个基本的认识,知道它们是什么,怎样使用以及利弊。 -### Step 1: Review the scalability video lecture +### 第一步:回顾可扩展性(scalability)的视频讲座 -[Scalability Lecture at Harvard](https://www.youtube.com/watch?v=-W9F__D3oY4) +[哈佛大学可扩展性讲座](https://www.youtube.com/watch?v=-W9F__D3oY4) -* Topics covered: - * Vertical scaling - * Horizontal scaling - * Caching - * Load balancing - * Database replication - * Database partitioning +* 主题涵盖 + * 垂直扩展(Vertical scaling) + * 水平扩展(Horizontal scaling) + * 缓存 + * 负载均衡 + * 数据库复制 + * 数据库分区 -### Step 2: Review the scalability article +### 第二步:回顾可扩展性文章 -[Scalability](http://www.lecloud.net/tagged/scalability) +[可扩展性](http://www.lecloud.net/tagged/scalability) -* Topics covered: +* 主题涵盖: * [Clones](http://www.lecloud.net/post/7295452622/scalability-for-dummies-part-1-clones) - * [Databases](http://www.lecloud.net/post/7994751381/scalability-for-dummies-part-2-database) - * [Caches](http://www.lecloud.net/post/9246290032/scalability-for-dummies-part-3-cache) - * [Asynchronism](http://www.lecloud.net/post/9699762917/scalability-for-dummies-part-4-asynchronism) + * [数据库](http://www.lecloud.net/post/7994751381/scalability-for-dummies-part-2-database) + * [缓存](http://www.lecloud.net/post/9246290032/scalability-for-dummies-part-3-cache) + * [异步](http://www.lecloud.net/post/9699762917/scalability-for-dummies-part-4-asynchronism) -### Next steps +### 接下来的步骤 -Next, we'll look at high-level trade-offs: +接下来,我们将看看高阶的权衡和取舍: -* **Performance** vs **scalability** -* **Latency** vs **throughput** -* **Availability** vs **consistency** +* **性能**与**可扩展性** +* **延迟**与**吞吐量** +* **可用性**与**一致性** -Keep in mind that **everything is a trade-off**. +记住**每个方面都面临取舍和权衡**。 -Then we'll dive into more specific topics such as DNS, CDNs, and load balancers. +然后,我们将深入更具体的主题,如 DNS,CDN 和负载均衡器。 -## Performance vs scalability +## 性能与可扩展性 -A service is **scalable** if it results in increased **performance** in a manner proportional to resources added. Generally, increasing performance means serving more units of work, but it can also be to handle larger units of work, such as when datasets grow.1 +如果服务**性能**的增长与资源的增加是成比例的,服务就是可扩展的。通常,提高性能意味着服务于更多的工作单元,另一方面,当数据集增长时,同样也可以处理更大的工作单位。1 -Another way to look at performance vs scalability: +另一个角度来看待性能与可扩展性: -* If you have a **performance** problem, your system is slow for a single user. -* If you have a **scalability** problem, your system is fast for a single user but slow under heavy load. +* 如果你的系统有 **性能** 问题,对于单个用户来说是缓慢的。 +* 如果你的系统有 **可扩展性** 问题,单个用户较快但在高负载下会变慢。 -### Source(s) and further reading +### 来源及延伸阅读 * [A word on scalability](http://www.allthingsdistributed.com/2006/03/a_word_on_scalability.html) * [Scalability, availability, stability, patterns](http://www.slideshare.net/jboner/scalability-availability-stability-patterns/) -## Latency vs throughput +## 延迟与吞吐量 -**Latency** is the time to perform some action or to produce some result. +**延迟**是执行操作或运算结果所花费的时间。 -**Throughput** is the number of such actions or results per unit of time. +**吞吐量**是单位时间内(执行)此类操作或运算的数量。 -Generally, you should aim for **maximal throughput** with **acceptable latency**. +通常,你应该以**可接受级延迟**下**最大化吞吐量**为目标。 -### Source(s) and further reading +### 来源及延伸阅读 * [Understanding latency vs throughput](https://community.cadence.com/cadence_blogs_8/b/sd/archive/2010/09/13/understanding-latency-vs-throughput) -## Availability vs consistency +## 可用性与一致性 -### CAP theorem +### CAP 理论


- Source: CAP theorem revisited + 来源:CAP theorem revisited

-In a distributed computer system, you can only support two of the following guarantees: +在一个分布式计算系统中,只能同时满足下列的两点: -* **Consistency** - Every read receives the most recent write or an error -* **Availability** - Every request receives a response, without guarantee that it contains the most recent version of the information -* **Partition Tolerance** - The system continues to operate despite arbitrary partitioning due to network failures +* **一致性** - 每次访问都能获得最新数据但可能会收到错误响应 +* **可用性** - 每次访问都能收到非错响应,但不保证获取到最新数据 +* **分区容错性** - 在任意分区网络故障的情况下系统仍能继续运行 -*Networks aren't reliable, so you'll need to support partition tolerance. You'll need to make a software tradeoff between consistency and availability.* +*网络并不可靠,所以你应要支持分区容错性,并需要在软件可用性和一致性间做出取舍。* -#### CP - consistency and partition tolerance +#### CP - 一致性和分区容错性 -Waiting for a response from the partitioned node might result in a timeout error. CP is a good choice if your business needs require atomic reads and writes. +等待分区节点的响应可能会导致延时错误。如果你的业务需求需要原子读写,CP 是一个不错的选择。 -#### AP - availability and partition tolerance +#### AP - 可用性与分区容错性 -Responses return the most recent version of the data, which might not be the latest. Writes might take some time to propagate when the partition is resolved. +响应返回的最近版本数据可能并不是最新的。当分区解析完后,写入(操作)可能要花一些时间来传播。 -AP is a good choice if the business needs allow for [eventual consistency](#eventual-consistency) or when the system needs to continue working despite external errors. +如果业务需求允许[最终一致性](#eventual-consistency),或当有外部故障时要求系统继续运行,AP 是一个不错的选择。 -### Source(s) and further reading +### 来源及延伸阅读 * [CAP theorem revisited](http://robertgreiner.com/2014/08/cap-theorem-revisited/) * [A plain english introduction to CAP theorem](http://ksat.me/a-plain-english-introduction-to-cap-theorem/) * [CAP FAQ](https://github.com/henryr/cap-faq) -## Consistency patterns +## 一致性模式 -With multiple copies of the same data, we are faced with options on how to synchronize them so clients have a consistent view of the data. Recall the definition of consistency from the [CAP theorem](#cap-theorem) - Every read receives the most recent write or an error. +有同一份数据的多份副本,我们面临着怎样同步它们的选择,以便让客户端有一致的显示数据。回想 [CAP 定理](#cap-theorem)中的一致性定义 - 每次访问都能获得最新数据但可能会收到错误响应 -### Weak consistency -After a write, reads may or may not see it. A best effort approach is taken. +### 弱一致性 -This approach is seen in systems such as memcached. Weak consistency works well in real time use cases such as VoIP, video chat, and realtime multiplayer games. For example, if you are on a phone call and lose reception for a few seconds, when you regain connection you do not hear what was spoken during connection loss. +在写入之后,访问可能看到,也可能看不到(写入数据)。尽力优化之让其可见。 -### Eventual consistency +这种方式可以 memcached 等系统中看到。弱一致性在 VoIP,视频聊天和实时多人游戏等真实用例中表现不错。打个比方,如果你在通话中丢失信号几秒钟时间,当重新连接时你是听不到这几秒钟所说的话的。 -After a write, reads will eventually see it (typically within milliseconds). Data is replicated asynchronously. +### 最终一致性 -This approach is seen in systems such as DNS and email. Eventual consistency works well in highly available systems. +在写入后,访问最终能看到写入数据(通常在数毫秒内)。数据被异步复制。 -### Strong consistency +DNS 和 email 等系统使用的是此种方式。最终一致性在高可用性系统中效果不错。 -After a write, reads will see it. Data is replicated synchronously. +### 强一致性 -This approach is seen in file systems and RDBMSes. Strong consistency works well in systems that need transactions. +在写入后,访问立即可见。数据被同步复制。 -### Source(s) and further reading +文件系统和关系型数据库(RDBMS)中使用的是此种方式。强一致性在需要记录的系统中运作良好。 + +### 来源及延伸阅读 * [Transactions across data centers](http://snarfed.org/transactions_across_datacenters_io.html) -## Availability patterns +## 可用性模式 -There are two main patterns to support high availability: **fail-over** and **replication**. +有两种支持高可用性的模式: **故障切换(fail-over)**和**复制(replication)**。 -### Fail-over +### 故障切换 -#### Active-passive +#### 工作到备用切换(Active-passive) -With active-passive fail-over, heartbeats are sent between the active and the passive server on standby. If the heartbeat is interrupted, the passive server takes over the active's IP address and resumes service. +关于工作到备用的故障切换,工作服务器发送周期信号给等待中的备用服务器。如果周期信号中断,备用服务器切换成工作服务器的 IP 地址并恢复服务。 -The length of downtime is determined by whether the passive server is already running in 'hot' standby or whether it needs to start up from 'cold' standby. Only the active server handles traffic. +宕机时间取决于备用服务器处于‘热‘等待状态还是需要从‘冷‘等待状态进行启动。只有工作服务器处理流量。 -Active-passive failover can also be referred to as master-slave failover. +工作到备用的故障切换也被称为主从切换。 -#### Active-active +#### 双工作切换(Active-active) -In active-active, both servers are managing traffic, spreading the load between them. +在双工作切换中,双方都在管控流量,在它们之间分散负载。 -If the servers are public-facing, the DNS would need to know about the public IPs of both servers. If the servers are internal-facing, application logic would need to know about both servers. +如果是外网服务器,DNS 将需要对两方都了解。如果是内网服务器,应用程序逻辑将需要对两方都了解。 -Active-active failover can also be referred to as master-master failover. +双工作切换也可以称为主主切换。 -### Disadvantage(s): failover +### 缺陷:故障切换 -* Fail-over adds more hardware and additional complexity. -* There is a potential for loss of data if the active system fails before any newly written data can be replicated to the passive. +* 故障切换需要添加额外硬件并增加复杂性。 +* 如果新写入数据在能被复制到备用系统之前,工作系统出现了故障,则有可能会丢失数据。 -### Replication +### 复制 -#### Master-slave and master-master +#### 主-从复制和主-主复制 -This topic is further discussed in the [Database](#database) section: +这个主题进一步探讨了[数据库](#database)部分: -* [Master-slave replication](#master-slave-replication) -* [Master-master replication](#master-master-replication) +* [主-从复制](#master-slave-replication) +* [主-主复制](#master-master-replication) -## Domain name system +## 域名系统


- Source: DNS security presentation + 来源: DNS security presentation

-A Domain Name System (DNS) translates a domain name such as www.example.com to an IP address. +域名系统是把 www.example.com 等域名转换成 IP 地址。 -DNS is hierarchical, with a few authoritative servers at the top level. Your router or ISP provides information about which DNS server(s) to contact when doing a lookup. Lower level DNS servers cache mappings, which could become stale due to DNS propagation delays. DNS results can also be cached by your browser or OS for a certain period of time, determined by the [time to live (TTL)](https://en.wikipedia.org/wiki/Time_to_live). +域名系统是分层次的,一些 DNS 服务器位于顶层。当查询(域名) IP 时,路由或 ISP 提供连接 DNS 服务器的信息。较低层 DNS 服务器缓存映射,它可能会因为 DNS 传播延时而失效。DNS 结果可以缓存在浏览器或操作系统中一段时间,时间长短取决于[存活时间 TTL](https://en.wikipedia.org/wiki/Time_to_live)。 -* **NS record (name server)** - Specifies the DNS servers for your domain/subdomain. -* **MX record (mail exchange)** - Specifies the mail servers for accepting messages. -* **A record (address)** - Points a name to an IP address. -* **CNAME (canonical)** - Points a name to another name or `CNAME` (example.com to www.example.com) or to an `A` record. +* **NS 记录(域名服务)** - 指定解析域名或子域名的 DNS 服务器。 +* **MX 记录(邮件交换)** - 指定接收信息的邮件服务器。 +* **A 记录(地址)** - 指定域名对应的 IP 地址记录。 +* **CNAME(规范)** - 一个域名映射到另一个域名或 `CNAME` 记录(example.com 指向 www.example.com)或映射到一个 `A` 记录。 -Services such as [CloudFlare](https://www.cloudflare.com/dns/) and [Route 53](https://aws.amazon.com/route53/) provide managed DNS services. Some DNS services can route traffic through various methods: +[CloudFlare](https://www.cloudflare.com/dns/) 和 [Route 53](https://aws.amazon.com/route53/) 等平台提供管理 DNS 的功能。某些 DNS 服务通过集中方式来路由流量: -* [Weighted round robin](http://g33kinfo.com/info/archives/2657) - * Prevent traffic from going to servers under maintenance - * Balance between varying cluster sizes - * A/B testing -* Latency-based -* Geolocation-based +* [加权轮询调度](http://g33kinfo.com/info/archives/2657) + * 防止流量进入维护中的服务器 + * 在不同大小集群间负载均衡 + * A/B 测试 +* 基于延迟路由 +* 基于地理位置路由 -### Disadvantage(s): DNS +### 缺陷:DNS -* Accessing a DNS server introduces a slight delay, although mitigated by caching described above. -* DNS server management could be complex, although they are generally managed by [governments, ISPs, and large companies](http://superuser.com/questions/472695/who-controls-the-dns-servers/472729). -* DNS services have recently come under [DDoS attack](http://dyn.com/blog/dyn-analysis-summary-of-friday-october-21-attack/), preventing users from accessing websites such as Twitter without knowing Twitter's IP address(es). +* 虽说缓存可以来减轻 DNS 延迟,但连接 DNS 服务器还是带来了轻微的延迟。 +* 虽然它们通常由[政府,网络服务提供商和大公司](http://superuser.com/questions/472695/who-controls-the-dns-servers/472729)管理,但 DNS 服务管理仍可能是复杂的。 +* DNS 服务最近遭受 [DDoS 攻击](http://dyn.com/blog/dyn-analysis-summary-of-friday-october-21-attack/),防止不知道 Twtter IP 地址的用户访问 Twiiter。 -### Source(s) and further reading +### 来源及延伸阅读 * [DNS architecture](https://technet.microsoft.com/en-us/library/dd197427(v=ws.10).aspx) * [Wikipedia](https://en.wikipedia.org/wiki/Domain_Name_System) * [DNS articles](https://support.dnsimple.com/categories/dns/) -## Content delivery network +## 内容分发网络


- Source: Why use a CDN + 来源: Why use a CDN

-A content delivery network (CDN) is a globally distributed network of proxy servers, serving content from locations closer to the user. Generally, static files such as HTML/CSS/JS, photos, and videos are served from CDN, although some CDNs such as Amazon's CloudFront support dynamic content. The site's DNS resolution will tell clients which server to contact. +内容分发网络是一个全球性的代理服务器分布式网络,它从靠近用户的位置提供内容。通常,HTML/CSS/JS,图片和视频等静态内容由 CDN 提供,虽然亚马逊 CloudFront 等也支持动态内容。CDN 的 DNS 解析会告知客户端连接哪台服务器。 -Serving content from CDNs can significantly improve performance in two ways: +将内容存储在 CDN 上可以从两个方面来提供性能: -* Users receive content at data centers close to them -* Your servers do not have to serve requests that the CDN fulfills +* 从靠近用户的数据中心提供资源 +* 通过 CDN 你的服务器不必真的处理请求 -### Push CDNs +### CDN 推送(push) -Push CDNs receive new content whenever changes occur on your server. You take full responsibility for providing content, uploading directly to the CDN and rewriting URLs to point to the CDN. You can configure when content expires and when it is updated. Content is uploaded only when it is new or changed, minimizing traffic, but maximizing storage. +当你服务器上内容发生变动时,推送给 CDN 接受新的内容。你负责提供内容,直接推送给 CDN 并重写 URL 地址以指向 CDN 地址。你可以配置内容到期时间及何时更新。内容只有在更改或新增是才推送,最小化流量,但最大化存储空间。 -Sites with a small amount of traffic or sites with content that isn't often updated work well with push CDNs. Content is placed on the CDNs once, instead of being re-pulled at regular intervals. -### Pull CDNs -Pull CDNs grab new content from your server when the first user requests the content. You leave the content on your server and rewrite URLs to point to the CDN. This results in a slower request until the content is cached on the server. -A [time-to-live (TTL)](https://en.wikipedia.org/wiki/Time_to_live) determines how long content is cached. Pull CDNs minimize storage space on the CDN, but can create redundant traffic if files expire and are pulled before they have actually changed. +### CDN 拉取(pull) -Sites with heavy traffic work well with pull CDNs, as traffic is spread out more evenly with only recently-requested content remaining on the CDN. +CDN 拉取是当第一个用户请求该资源时,从服务器上拉取资源。你将内容留在自己的服务器上并重写 URL 指向 CDN 地址。这样请求会更慢,直到内容被缓存在 CDN 上,。 -### Disadvantage(s): CDN +[存活时间(TTL)](https://en.wikipedia.org/wiki/Time_to_live)决定缓存多久时间。CDN 拉取方式最小化 CDN 上的储存空间,但如果过期文件并在实际更改之前被拉取,则会导致冗余的流量。 -* CDN costs could be significant depending on traffic, although this should be weighed with additional costs you would incur not using a CDN. -* Content might be stale if it is updated before the TTL expires it. -* CDNs require changing URLs for static content to point to the CDN. +高流量站点使用 CDN 拉取效果不错,因为只有最近请求的内容保存在 CDN 中,流量才能更平衡地分散。 -### Source(s) and further reading +### 缺陷:CDN + +* CDN 成本可能因流量而异,可能在权衡之后你将不会使用 CDN。 +* 如果在 TTL 过期之前更新内容,CDN 缓存内容可能会过时。 +* CDN 需要更改静态内容的 URL 地址以指向 CDN。 + +### 来源及延伸阅读 * [Globally distributed content delivery](http://repository.cmu.edu/cgi/viewcontent.cgi?article=2112&context=compsci) * [The differences between push and pull CDNs](http://www.travelblogadvice.com/technical/the-differences-between-push-and-pull-cdns/) * [Wikipedia](https://en.wikipedia.org/wiki/Content_delivery_network) -## Load balancer +## 负载均衡器

@@ -607,59 +609,58 @@ Sites with heavy traffic work well with pull CDNs, as traffic is spread out more Source: Scalable system design patterns

-Load balancers distribute incoming client requests to computing resources such as application servers and databases. In each case, the load balancer returns the response from the computing resource to the appropriate client. Load balancers are effective at: +负载均衡器将传入的请求分发到应用服务器和数据库等计算资源。无论哪种情况,负载均衡器将从计算资源来的响应返回给恰当的客户端。负载均衡器的效用在于: -* Preventing requests from going to unhealthy servers -* Preventing overloading resources -* Helping eliminate single points of failure +* 防止请求进入不好的服务器 +* 防止资源过载 +* 帮助消除单一的故障点 -Load balancers can be implemented with hardware (expensive) or with software such as HAProxy. +负载均衡器可以通过硬件(昂贵)或 HAProxy 等软件来实现。 +增加的益处包括: -Additional benefits include: +* **SSL 终结** - 解密传入的请求并加密服务器响应,这样的话后端服务器就不必再执行这些潜在高消耗运算了。 + * 不需要再每台服务器上安装 [X.509 证书](https://en.wikipedia.org/wiki/X.509)。 +* **Session 留存** - 如果 Web 应用程序不追踪会话,发出 cookie 并将特定客户端的请求路由到同一实例。 -* **SSL termination** - Decrypt incoming requests and encrypt server responses so backend servers do not have to perform these potentially expensive operations - * Removes the need to install [X.509 certificates](https://en.wikipedia.org/wiki/X.509) on each server -* **Session persistence** - Issue cookies and route a specific client's requests to same instance if the web apps do not keep track of sessions +通常会设置采用[工作-备用](#active-passive) 或 [双工作](#active-active) 模式的多个负载均衡器,以免发生故障。 -To protect against failures, it's common to set up multiple load balancers, either in [active-passive](#active-passive) or [active-active](#active-active) mode. +负载均衡器能基于多种方式来路由流量: -Load balancers can route traffic based on various metrics, including: - -* Random -* Least loaded +* 随机 +* 最少负载 * Session/cookies -* [Round robin or weighted round robin](http://g33kinfo.com/info/archives/2657) -* [Layer 4](#layer-4-load-balancing) -* [Layer 7](#layer-7-load-balancing) +* [轮询调度或加权轮询调度算法](http://g33kinfo.com/info/archives/2657) +* [四层负载均衡](#layer-4-load-balancing) +* [七层负载均衡](#layer-7-load-balancing) -### Layer 4 load balancing +### 四层负载均衡 -Layer 4 load balancers look at info at the [transport layer](#communication) to decide how to distribute requests. Generally, this involves the source, destination IP addresses, and ports in the header, but not the contents of the packet. Layer 4 load balancers forward network packets to and from the upstream server, performing [Network Address Translation (NAT)](https://www.nginx.com/resources/glossary/layer-4-load-balancing/). +四层负载均衡根据监看[传输层](#communication)的信息来决定如何分发请求。通常,这会涉及来源,目标 IP 地址和请求头中的端口,但不包括数据包(报文)内容。四层负载均衡执行[网络地址转换(NAT)](https://www.nginx.com/resources/glossary/layer-4-load-balancing/)来向上游服务器转发网络数据包。 -### layer 7 load balancing +### 七层负载均衡器 -Layer 7 load balancers look at the [application layer](#communication) to decide how to distribute requests. This can involve contents of the header, message, and cookies. Layer 7 load balancers terminates network traffic, reads the message, makes a load-balancing decision, then opens a connection to the selected server. For example, a layer 7 load balancer can direct video traffic to servers that host videos while directing more sensitive user billing traffic to security-hardened servers. +七层负载均衡器根据监看[应用层](#communication)来决定怎样分发请求。这会涉及请求头的内容,消息和 cookie。七层负载均衡器终结网络流量,读取消息,做出负载均衡判定,然后传送给特定服务器。比如,一个七层负载均衡器能直接将视频流量连接到托管视频的服务器,同时将更敏感的用户账单流量引导到安全性更强的服务器。 -At the cost of flexibility, layer 4 load balancing requires less time and computing resources than Layer 7, although the performance impact can be minimal on modern commodity hardware. +以损失灵活性为代价,四层负载均衡比七层负载均衡只需更少时间和计算资源,虽然这在现代商用硬件上的性能影响甚微。 -### Horizontal scaling +### 水平扩展 -Load balancers can also help with horizontal scaling, improving performance and availability. Scaling out using commodity machines is more cost efficient and results in higher availability than scaling up a single server on more expensive hardware, called **Vertical Scaling**. It is also easier to hire for talent working on commodity hardware than it is for specialized enterprise systems. +负载均衡器还能帮助水平扩展,提高性能和可用性。使用商业硬件的性价比更高,并且比在单台硬件上**纵向扩展**更贵的硬件具有更高的可用性。招聘商业硬件的人才比特定企业系统的人才更容易。 -#### Disadvantage(s): horizontal scaling +#### 缺陷:水平扩展 -* Scaling horizontally introduces complexity and involves cloning servers - * Servers should be stateless: they should not contain any user-related data like sessions or profile pictures - * Sessions can be stored in a centralized data store such as a [database](#database) (SQL, NoSQL) or a persistent [cache](#cache) (Redis, Memcached) -* Downstream servers such as caches and databases need to handle more simultaneous connections as upstream servers scale out +* 水平扩展引入了复杂度并设计服务器复制 + * 服务器应该是无状态的:它们也不该包含任何与用户关联的数据,像 session 或资料图片。 + * session 可以集中存储在数据库或持久化[缓存](#cache)(Redis, Memcached)的数据存储区中。 +* 缓存和数据库等下游服务器需要随着上游服务器进行扩展,以处理更多的并发连接。 -### Disadvantage(s): load balancer +### 缺陷:负载均衡器 -* The load balancer can become a performance bottleneck if it does not have enough resources or if it is not configured properly. -* Introducing a load balancer to help eliminate single points of failure results in increased complexity. -* A single load balancer is a single point of failure, configuring multiple load balancers further increases complexity. +* 如果没有足够的资源配置或配置错误,负载均衡器会变成一个性能瓶颈。 +* 引入负载均衡器以帮助消除单点故障但导致了额外的复杂性。 +* 单个负载均衡器会导致单点故障,但配置多个负载均衡器会进一步增加复杂性。 -### Source(s) and further reading +### 来源及延伸阅读 * [NGINX architecture](https://www.nginx.com/blog/inside-nginx-how-we-designed-for-performance-scale/) * [HAProxy architecture guide](http://www.haproxy.org/download/1.2/doc/architecture.txt) From 69f57b9952cfdb0b43429da1b533b8e1bd5a33b8 Mon Sep 17 00:00:00 2001 From: AidenLiudm Date: Tue, 11 Apr 2017 12:01:27 +0800 Subject: [PATCH 12/16] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A0=A1=E5=AF=B9?= =?UTF-8?q?=E8=80=85=E5=8F=91=E7=8E=B0=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README-zh-Hant.md | 130 +++++++++++++++++++++++----------------------- 1 file changed, 65 insertions(+), 65 deletions(-) diff --git a/README-zh-Hant.md b/README-zh-Hant.md index 4693a384..5b8e5136 100755 --- a/README-zh-Hant.md +++ b/README-zh-Hant.md @@ -404,25 +404,25 @@ 另一个角度来看待性能与可扩展性: -* 如果你的系统有 **性能** 问题,对于单个用户来说是缓慢的。 -* 如果你的系统有 **可扩展性** 问题,单个用户较快但在高负载下会变慢。 +* 如果你的系统有**性能**问题,对于单个用户来说是缓慢的。 +* 如果你的系统有**可扩展性**问题,单个用户较快但在高负载下会变慢。 ### 来源及延伸阅读 -* [A word on scalability](http://www.allthingsdistributed.com/2006/03/a_word_on_scalability.html) -* [Scalability, availability, stability, patterns](http://www.slideshare.net/jboner/scalability-availability-stability-patterns/) +* [简单谈谈可扩展性](http://www.allthingsdistributed.com/2006/03/a_word_on_scalability.html) +* [可扩展性,可用性,稳定性和](http://www.slideshare.net/jboner/scalability-availability-stability-patterns/) ## 延迟与吞吐量 **延迟**是执行操作或运算结果所花费的时间。 -**吞吐量**是单位时间内(执行)此类操作或运算的数量。 +**吞吐量**是单位时间内(执行)此类操作或运算的数量。 通常,你应该以**可接受级延迟**下**最大化吞吐量**为目标。 ### 来源及延伸阅读 -* [Understanding latency vs throughput](https://community.cadence.com/cadence_blogs_8/b/sd/archive/2010/09/13/understanding-latency-vs-throughput) +* [理解延迟与吞吐量](https://community.cadence.com/cadence_blogs_8/b/sd/archive/2010/09/13/understanding-latency-vs-throughput) ## 可用性与一致性 @@ -436,42 +436,42 @@ 在一个分布式计算系统中,只能同时满足下列的两点: -* **一致性** - 每次访问都能获得最新数据但可能会收到错误响应 -* **可用性** - 每次访问都能收到非错响应,但不保证获取到最新数据 -* **分区容错性** - 在任意分区网络故障的情况下系统仍能继续运行 +* **一致性** ─ 每次访问都能获得最新数据但可能会收到错误响应 +* **可用性** ─ 每次访问都能收到非错响应,但不保证获取到最新数据 +* **分区容错性** ─ 在任意分区网络故障的情况下系统仍能继续运行 *网络并不可靠,所以你应要支持分区容错性,并需要在软件可用性和一致性间做出取舍。* -#### CP - 一致性和分区容错性 +#### CP ─ 一致性和分区容错性 等待分区节点的响应可能会导致延时错误。如果你的业务需求需要原子读写,CP 是一个不错的选择。 -#### AP - 可用性与分区容错性 +#### AP ─ 可用性与分区容错性 -响应返回的最近版本数据可能并不是最新的。当分区解析完后,写入(操作)可能要花一些时间来传播。 +响应返回的最近版本数据可能并不是最新的。当分区解析完后,写入(操作)可能需要一些时间来传播。 如果业务需求允许[最终一致性](#eventual-consistency),或当有外部故障时要求系统继续运行,AP 是一个不错的选择。 ### 来源及延伸阅读 -* [CAP theorem revisited](http://robertgreiner.com/2014/08/cap-theorem-revisited/) -* [A plain english introduction to CAP theorem](http://ksat.me/a-plain-english-introduction-to-cap-theorem/) +* [再看 CAP 理论](http://robertgreiner.com/2014/08/cap-theorem-revisited/) +* [通俗易懂地介绍 CAP 理论](http://ksat.me/a-plain-english-introduction-to-cap-theorem/) * [CAP FAQ](https://github.com/henryr/cap-faq) ## 一致性模式 -有同一份数据的多份副本,我们面临着怎样同步它们的选择,以便让客户端有一致的显示数据。回想 [CAP 定理](#cap-theorem)中的一致性定义 - 每次访问都能获得最新数据但可能会收到错误响应 +有同一份数据的多份副本,我们面临着怎样同步它们的选择,以便让客户端有一致的显示数据。回想 [CAP 定理](#cap-theorem)中的一致性定义 ─ 每次访问都能获得最新数据但可能会收到错误响应 ### 弱一致性 -在写入之后,访问可能看到,也可能看不到(写入数据)。尽力优化之让其可见。 +在写入之后,访问可能看到,也可能看不到(写入数据)。尽力优化之让其能访问最新数据。 这种方式可以 memcached 等系统中看到。弱一致性在 VoIP,视频聊天和实时多人游戏等真实用例中表现不错。打个比方,如果你在通话中丢失信号几秒钟时间,当重新连接时你是听不到这几秒钟所说的话的。 ### 最终一致性 -在写入后,访问最终能看到写入数据(通常在数毫秒内)。数据被异步复制。 +在写入后,访问最终能看到写入数据(通常在数毫秒内)。数据被异步复制。 DNS 和 email 等系统使用的是此种方式。最终一致性在高可用性系统中效果不错。 @@ -479,7 +479,7 @@ DNS 和 email 等系统使用的是此种方式。最终一致性在高可用性 在写入后,访问立即可见。数据被同步复制。 -文件系统和关系型数据库(RDBMS)中使用的是此种方式。强一致性在需要记录的系统中运作良好。 +文件系统和关系型数据库(RDBMS)中使用的是此种方式。强一致性在需要记录的系统中运作良好。 ### 来源及延伸阅读 @@ -487,19 +487,19 @@ DNS 和 email 等系统使用的是此种方式。最终一致性在高可用性 ## 可用性模式 -有两种支持高可用性的模式: **故障切换(fail-over)**和**复制(replication)**。 +有两种支持高可用性的模式: **故障切换(fail-over)**和**复制(replication)**。 ### 故障切换 -#### 工作到备用切换(Active-passive) +#### 工作到备用切换(Active-passive) -关于工作到备用的故障切换,工作服务器发送周期信号给等待中的备用服务器。如果周期信号中断,备用服务器切换成工作服务器的 IP 地址并恢复服务。 +关于工作到备用的故障切换流程是,工作服务器发送周期信号给待机中的备用服务器。如果周期信号中断,备用服务器切换成工作服务器的 IP 地址并恢复服务。 -宕机时间取决于备用服务器处于‘热‘等待状态还是需要从‘冷‘等待状态进行启动。只有工作服务器处理流量。 +宕机时间取决于备用服务器处于“热”待机状态还是需要从“冷”待机状态进行启动。只有工作服务器处理流量。 工作到备用的故障切换也被称为主从切换。 -#### 双工作切换(Active-active) +#### 双工作切换(Active-active) 在双工作切换中,双方都在管控流量,在它们之间分散负载。 @@ -514,12 +514,12 @@ DNS 和 email 等系统使用的是此种方式。最终一致性在高可用性 ### 复制 -#### 主-从复制和主-主复制 +#### 主─从复制和主─主复制 这个主题进一步探讨了[数据库](#database)部分: -* [主-从复制](#master-slave-replication) -* [主-主复制](#master-master-replication) +* [主─从复制](#master-slave-replication) +* [主─主复制](#master-master-replication) ## 域名系统 @@ -531,12 +531,12 @@ DNS 和 email 等系统使用的是此种方式。最终一致性在高可用性 域名系统是把 www.example.com 等域名转换成 IP 地址。 -域名系统是分层次的,一些 DNS 服务器位于顶层。当查询(域名) IP 时,路由或 ISP 提供连接 DNS 服务器的信息。较低层 DNS 服务器缓存映射,它可能会因为 DNS 传播延时而失效。DNS 结果可以缓存在浏览器或操作系统中一段时间,时间长短取决于[存活时间 TTL](https://en.wikipedia.org/wiki/Time_to_live)。 +域名系统是分层次的,一些 DNS 服务器位于顶层。当查询(域名) IP 时,路由或 ISP 提供连接 DNS 服务器的信息。较底层的 DNS 服务器缓存映射,它可能会因为 DNS 传播延时而失效。DNS 结果可以缓存在浏览器或操作系统中一段时间,时间长短取决于[存活时间 TTL](https://en.wikipedia.org/wiki/Time_to_live)。 -* **NS 记录(域名服务)** - 指定解析域名或子域名的 DNS 服务器。 -* **MX 记录(邮件交换)** - 指定接收信息的邮件服务器。 -* **A 记录(地址)** - 指定域名对应的 IP 地址记录。 -* **CNAME(规范)** - 一个域名映射到另一个域名或 `CNAME` 记录(example.com 指向 www.example.com)或映射到一个 `A` 记录。 +* **NS 记录(域名服务)** ─ 指定解析域名或子域名的 DNS 服务器。 +* **MX 记录(邮件交换)** ─ 指定接收信息的邮件服务器。 +* **A 记录(地址)** ─ 指定域名对应的 IP 地址记录。 +* **CNAME(规范)** ─ 一个域名映射到另一个域名或 `CNAME` 记录(example.com 指向 www.example.com)或映射到一个 `A` 记录。 [CloudFlare](https://www.cloudflare.com/dns/) 和 [Route 53](https://aws.amazon.com/route53/) 等平台提供管理 DNS 的功能。某些 DNS 服务通过集中方式来路由流量: @@ -549,15 +549,15 @@ DNS 和 email 等系统使用的是此种方式。最终一致性在高可用性 ### 缺陷:DNS -* 虽说缓存可以来减轻 DNS 延迟,但连接 DNS 服务器还是带来了轻微的延迟。 +* 虽说缓存可以减轻 DNS 延迟,但连接 DNS 服务器还是带来了轻微的延迟。 * 虽然它们通常由[政府,网络服务提供商和大公司](http://superuser.com/questions/472695/who-controls-the-dns-servers/472729)管理,但 DNS 服务管理仍可能是复杂的。 -* DNS 服务最近遭受 [DDoS 攻击](http://dyn.com/blog/dyn-analysis-summary-of-friday-october-21-attack/),防止不知道 Twtter IP 地址的用户访问 Twiiter。 +* DNS 服务最近遭受 [DDoS 攻击](http://dyn.com/blog/dyn-analysis-summary-of-friday-october-21-attack/),阻止不知道 Twtter IP 地址的用户访问 Twiiter。 ### 来源及延伸阅读 -* [DNS architecture](https://technet.microsoft.com/en-us/library/dd197427(v=ws.10).aspx) +* [DNS 架构](https://technet.microsoft.com/en-us/library/dd197427(v=ws.10).aspx) * [Wikipedia](https://en.wikipedia.org/wiki/Domain_Name_System) -* [DNS articles](https://support.dnsimple.com/categories/dns/) +* [关于 DNS 的文章](https://support.dnsimple.com/categories/dns/) ## 内容分发网络 @@ -574,22 +574,22 @@ DNS 和 email 等系统使用的是此种方式。最终一致性在高可用性 * 从靠近用户的数据中心提供资源 * 通过 CDN 你的服务器不必真的处理请求 -### CDN 推送(push) +### CDN 推送(push) -当你服务器上内容发生变动时,推送给 CDN 接受新的内容。你负责提供内容,直接推送给 CDN 并重写 URL 地址以指向 CDN 地址。你可以配置内容到期时间及何时更新。内容只有在更改或新增是才推送,最小化流量,但最大化存储空间。 +当你服务器上内容发生变动时,推送 CDN 接受新内容。你负责提供内容,直接推送给 CDN 并重写 URL 地址以指向 CDN 地址。你可以配置内容到期时间及何时更新。内容只有在更改或新增是才推送,最小化流量,但最大化存储空间。 -### CDN 拉取(pull) +### CDN 拉取(pull) -CDN 拉取是当第一个用户请求该资源时,从服务器上拉取资源。你将内容留在自己的服务器上并重写 URL 指向 CDN 地址。这样请求会更慢,直到内容被缓存在 CDN 上,。 +CDN 拉取是当第一个用户请求该资源时,从服务器上拉取资源。你将内容留在自己的服务器上并重写 URL 指向 CDN 地址。这样请求会更慢,直到内容被缓存在 CDN 上。 -[存活时间(TTL)](https://en.wikipedia.org/wiki/Time_to_live)决定缓存多久时间。CDN 拉取方式最小化 CDN 上的储存空间,但如果过期文件并在实际更改之前被拉取,则会导致冗余的流量。 +[存活时间(TTL)](https://en.wikipedia.org/wiki/Time_to_live)决定缓存多久时间。CDN 拉取方式最小化 CDN 上的储存空间,但如果过期文件并在实际更改之前被拉取,则会导致冗余的流量。 高流量站点使用 CDN 拉取效果不错,因为只有最近请求的内容保存在 CDN 中,流量才能更平衡地分散。 -### 缺陷:CDN +### 缺陷:CDN * CDN 成本可能因流量而异,可能在权衡之后你将不会使用 CDN。 * 如果在 TTL 过期之前更新内容,CDN 缓存内容可能会过时。 @@ -597,8 +597,8 @@ CDN 拉取是当第一个用户请求该资源时,从服务器上拉取资源 ### 来源及延伸阅读 -* [Globally distributed content delivery](http://repository.cmu.edu/cgi/viewcontent.cgi?article=2112&context=compsci) -* [The differences between push and pull CDNs](http://www.travelblogadvice.com/technical/the-differences-between-push-and-pull-cdns/) +* [全球性内容分发网络](http://repository.cmu.edu/cgi/viewcontent.cgi?article=2112&context=compsci) +* [CDN 拉取和 CDN 推送的区别](http://www.travelblogadvice.com/technical/the-differences-between-push-and-pull-cdns/) * [Wikipedia](https://en.wikipedia.org/wiki/Content_delivery_network) ## 负载均衡器 @@ -615,46 +615,46 @@ CDN 拉取是当第一个用户请求该资源时,从服务器上拉取资源 * 防止资源过载 * 帮助消除单一的故障点 -负载均衡器可以通过硬件(昂贵)或 HAProxy 等软件来实现。 -增加的益处包括: +负载均衡器可以通过硬件(昂贵)或 HAProxy 等软件来实现。 +增加的好处包括: -* **SSL 终结** - 解密传入的请求并加密服务器响应,这样的话后端服务器就不必再执行这些潜在高消耗运算了。 +* **SSL 终结** ─ 解密传入的请求并加密服务器响应,这样的话后端服务器就不必再执行这些潜在高消耗运算了。 * 不需要再每台服务器上安装 [X.509 证书](https://en.wikipedia.org/wiki/X.509)。 -* **Session 留存** - 如果 Web 应用程序不追踪会话,发出 cookie 并将特定客户端的请求路由到同一实例。 +* **Session 留存** ─ 如果 Web 应用程序不追踪会话,发出 cookie 并将特定客户端的请求路由到同一实例。 -通常会设置采用[工作-备用](#active-passive) 或 [双工作](#active-active) 模式的多个负载均衡器,以免发生故障。 +通常会设置采用[工作─备用](#active-passive) 或 [双工作](#active-active) 模式的多个负载均衡器,以免发生故障。 负载均衡器能基于多种方式来路由流量: * 随机 * 最少负载 -* Session/cookies +* Session/cookie * [轮询调度或加权轮询调度算法](http://g33kinfo.com/info/archives/2657) * [四层负载均衡](#layer-4-load-balancing) * [七层负载均衡](#layer-7-load-balancing) ### 四层负载均衡 -四层负载均衡根据监看[传输层](#communication)的信息来决定如何分发请求。通常,这会涉及来源,目标 IP 地址和请求头中的端口,但不包括数据包(报文)内容。四层负载均衡执行[网络地址转换(NAT)](https://www.nginx.com/resources/glossary/layer-4-load-balancing/)来向上游服务器转发网络数据包。 +四层负载均衡根据监看[传输层](#communication)的信息来决定如何分发请求。通常,这会涉及来源,目标 IP 地址和请求头中的端口,但不包括数据包(报文)内容。四层负载均衡执行[网络地址转换(NAT)](https://www.nginx.com/resources/glossary/layer-4-load-balancing/)来向上游服务器转发网络数据包。 ### 七层负载均衡器 -七层负载均衡器根据监看[应用层](#communication)来决定怎样分发请求。这会涉及请求头的内容,消息和 cookie。七层负载均衡器终结网络流量,读取消息,做出负载均衡判定,然后传送给特定服务器。比如,一个七层负载均衡器能直接将视频流量连接到托管视频的服务器,同时将更敏感的用户账单流量引导到安全性更强的服务器。 +七层负载均衡器根据监控[应用层](#communication)来决定怎样分发请求。这会涉及请求头的内容,消息和 cookie。七层负载均衡器终结网络流量,读取消息,做出负载均衡判定,然后传送给特定服务器。比如,一个七层负载均衡器能直接将视频流量连接到托管视频的服务器,同时将更敏感的用户账单流量引导到安全性更强的服务器。 -以损失灵活性为代价,四层负载均衡比七层负载均衡只需更少时间和计算资源,虽然这在现代商用硬件上的性能影响甚微。 +以损失灵活性为代价,四层负载均衡比七层负载均衡花费更少时间和计算资源,虽然这对现代商用硬件的性能影响甚微。 ### 水平扩展 -负载均衡器还能帮助水平扩展,提高性能和可用性。使用商业硬件的性价比更高,并且比在单台硬件上**纵向扩展**更贵的硬件具有更高的可用性。招聘商业硬件的人才比特定企业系统的人才更容易。 +负载均衡器还能帮助水平扩展,提高性能和可用性。使用商业硬件的性价比更高,并且比在单台硬件上**垂直扩展**更贵的硬件具有更高的可用性。相比招聘特定企业系统人才,招聘商业硬件方面的人才更加容易。 -#### 缺陷:水平扩展 +#### 缺陷:水平扩展 -* 水平扩展引入了复杂度并设计服务器复制 - * 服务器应该是无状态的:它们也不该包含任何与用户关联的数据,像 session 或资料图片。 - * session 可以集中存储在数据库或持久化[缓存](#cache)(Redis, Memcached)的数据存储区中。 +* 水平扩展引入了复杂度并涉及服务器复制 + * 服务器应该是无状态的:它们也不该包含像 session 或资料图片等与用户关联的数据。 + * session 可以集中存储在数据库或持久化[缓存](#cache)(Redis, Memcached)的数据存储区中。 * 缓存和数据库等下游服务器需要随着上游服务器进行扩展,以处理更多的并发连接。 -### 缺陷:负载均衡器 +### 缺陷:负载均衡器 * 如果没有足够的资源配置或配置错误,负载均衡器会变成一个性能瓶颈。 * 引入负载均衡器以帮助消除单点故障但导致了额外的复杂性。 @@ -662,13 +662,13 @@ CDN 拉取是当第一个用户请求该资源时,从服务器上拉取资源 ### 来源及延伸阅读 -* [NGINX architecture](https://www.nginx.com/blog/inside-nginx-how-we-designed-for-performance-scale/) -* [HAProxy architecture guide](http://www.haproxy.org/download/1.2/doc/architecture.txt) -* [Scalability](http://www.lecloud.net/post/7295452622/scalability-for-dummies-part-1-clones) +* [NGINX 架构](https://www.nginx.com/blog/inside-nginx-how-we-designed-for-performance-scale/) +* [HAProxy 架构指南](http://www.haproxy.org/download/1.2/doc/architecture.txt) +* [可扩展性](http://www.lecloud.net/post/7295452622/scalability-for-dummies-part-1-clones) * [Wikipedia](https://en.wikipedia.org/wiki/Load_balancing_(computing)) -* [Layer 4 load balancing](https://www.nginx.com/resources/glossary/layer-4-load-balancing/) -* [Layer 7 load balancing](https://www.nginx.com/resources/glossary/layer-7-load-balancing/) -* [ELB listener config](http://docs.aws.amazon.com/elasticloadbalancing/latest/classic/elb-listener-config.html) +* [四层负载平衡](https://www.nginx.com/resources/glossary/layer-4-load-balancing/) +* [七层负载平衡](https://www.nginx.com/resources/glossary/layer-7-load-balancing/) +* [ELB 监听器配置](http://docs.aws.amazon.com/elasticloadbalancing/latest/classic/elb-listener-config.html) ## Reverse proxy (web server) @@ -1261,7 +1261,7 @@ def set_user(user_id, values): - [从缓存到内存数据](http://www.slideshare.net/tmatyashovsky/from-cache-to-in-memory-data-grid-introduction-to-hazelcast) - [可扩展系统设计模式](http://horicky.blogspot.com/2010/10/scalable-system-design-patterns.html) - [大型系统架构介绍](http://lethain.com/introduction-to-architecting-systems-for-scale/) -- [可扩展性,可用性,稳定性,模式](http://www.slideshare.net/jboner/scalability-availability-stability-patterns/) +- [可扩展性,可用性,稳定性和模式](http://www.slideshare.net/jboner/scalability-availability-stability-patterns/) - [可扩展性](http://www.lecloud.net/post/9246290032/scalability-for-dummies-part-3-cache) - [AWS ElastiCache 策略](http://docs.aws.amazon.com/AmazonElastiCache/latest/UserGuide/Strategies.html) - [维基百科](https://en.wikipedia.org/wiki/Cache_(computing)) From 660193defbf62f6c05aeda85efd590632b39b866 Mon Sep 17 00:00:00 2001 From: AidenLiudm Date: Tue, 11 Apr 2017 12:04:38 +0800 Subject: [PATCH 13/16] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=BB=B6=E4=BC=B8?= =?UTF-8?q?=E9=98=85=E8=AF=BB=E4=B8=AD=E7=9A=84=E6=A0=87=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README-zh-Hant.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README-zh-Hant.md b/README-zh-Hant.md index 5b8e5136..59d723bc 100755 --- a/README-zh-Hant.md +++ b/README-zh-Hant.md @@ -410,7 +410,7 @@ ### 来源及延伸阅读 * [简单谈谈可扩展性](http://www.allthingsdistributed.com/2006/03/a_word_on_scalability.html) -* [可扩展性,可用性,稳定性和](http://www.slideshare.net/jboner/scalability-availability-stability-patterns/) +* [可扩展性,可用性,稳定性和模式](http://www.slideshare.net/jboner/scalability-availability-stability-patterns/) ## 延迟与吞吐量 From 4b057e849e19d852cafc405652857c00c209581d Mon Sep 17 00:00:00 2001 From: AidenLiudm Date: Tue, 11 Apr 2017 12:11:46 +0800 Subject: [PATCH 14/16] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E4=B8=8B=E9=9D=A2=E7=9A=84=E6=8F=8F=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README-zh-Hant.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README-zh-Hant.md b/README-zh-Hant.md index 59d723bc..b9ea2b3b 100755 --- a/README-zh-Hant.md +++ b/README-zh-Hant.md @@ -431,7 +431,7 @@


- 来源:CAP theorem revisited + 来源:再看 CAP 理论

在一个分布式计算系统中,只能同时满足下列的两点: @@ -526,7 +526,7 @@ DNS 和 email 等系统使用的是此种方式。最终一致性在高可用性


- 来源: DNS security presentation + 来源:DNS 安全介绍

域名系统是把 www.example.com 等域名转换成 IP 地址。 @@ -564,7 +564,7 @@ DNS 和 email 等系统使用的是此种方式。最终一致性在高可用性


- 来源: Why use a CDN + 来源:为什么使用 CDN

内容分发网络是一个全球性的代理服务器分布式网络,它从靠近用户的位置提供内容。通常,HTML/CSS/JS,图片和视频等静态内容由 CDN 提供,虽然亚马逊 CloudFront 等也支持动态内容。CDN 的 DNS 解析会告知客户端连接哪台服务器。 From 561b9d2c063aeb45452576e840c5d337e70c5f44 Mon Sep 17 00:00:00 2001 From: xujifa Date: Tue, 11 Apr 2017 20:39:59 +0800 Subject: [PATCH 15/16] =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E6=A0=A1=E5=AF=B9?= =?UTF-8?q?=E6=84=8F=E8=A7=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README-zh-Hant.md | 48 ++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/README-zh-Hant.md b/README-zh-Hant.md index 74451879..5b8a29e1 100644 --- a/README-zh-Hant.md +++ b/README-zh-Hant.md @@ -1328,11 +1328,11 @@ A basic HTTP request consists of a verb (method) and a resource (endpoint). Bel | Verb | Description | Idempotent* | Safe | Cacheable | | ------ | ---------------------------------------- | ----------- | ---- | --------------------------------------- | -| 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 | -| PUT | Creates or replace a resource | Yes | No | No | -| PATCH | Partially updates a resource | No | No | Yes if response contains freshness info | -| DELETE | Deletes a resource | Yes | No | No | +| GET | 获取一个资源 | Yes | Yes | Yes | +| POST | 创建资源或触发处理数据的进程 | No | No | Yes if response contains freshness info | +| PUT | 创建或替换一个资源 | Yes | No | No | +| PATCH | 更新部分资源 | No | No | Yes if response contains freshness info | +| DELETE | 删除一个资源 | Yes | No | No | *Can be called many times without different outcomes. @@ -1375,13 +1375,13 @@ Use TCP over UDP when: UDP 是无连接的。数据报(类似于数据包)只在数据报级别有保证。数据报可能会无序的到达目的地,也有可能会遗失。UDP 不支持拥塞控制。虽然不如 TCP 那样有保证,但 UDP 通常效率更高。 -UDP 可以通过广播将数组报发送至子网内的所有设备。这对 [DHCP](https://en.wikipedia.org/wiki/Dynamic_Host_Configuration_Protocol) 很有用,因为子网内的设备还没有分配 IP 地址,而 IP 对于 TCP 是必须的。 +UDP 可以通过广播将数据报发送至子网内的所有设备。这对 [DHCP](https://en.wikipedia.org/wiki/Dynamic_Host_Configuration_Protocol) 很有用,因为子网内的设备还没有分配 IP 地址,而 IP 对于 TCP 是必须的。 -UDP 可靠性更低但适合用在网络电话、视频聊天,流(这个不知具体指啥)和实时多人游戏上。 +UDP 可靠性更低但适合用在网络电话、视频聊天,流媒体和实时多人游戏上。 以下情况使用 UDP 代替 TCP: -* 你需要更快的相应速度 +* 你需要低延迟 * 相对于数据丢失更糟的是数据延迟 * 你想实现自己的错误校正方法 @@ -1392,7 +1392,7 @@ UDP 可靠性更低但适合用在网络电话、视频聊天,流(这个不 * [TCP 与 UDP 的不同](http://stackoverflow.com/questions/5970383/difference-between-tcp-and-udp) * [传输控制协议](https://en.wikipedia.org/wiki/Transmission_Control_Protocol) * [用户数据报协议](https://en.wikipedia.org/wiki/User_Datagram_Protocol) -* [Facebook 对内存缓存的扩展](http://www.cs.bu.edu/~jappavoo/jappavoo.github.com/451/papers/memcache-fb.pdf) +* [Memcache 在 Facebook 的扩展](http://www.cs.bu.edu/~jappavoo/jappavoo.github.com/451/papers/memcache-fb.pdf) ### 远程过程调用协议(RPC) @@ -1402,15 +1402,15 @@ UDP 可靠性更低但适合用在网络电话、视频聊天,流(这个不 Source: Crack the system design interview

-在一个 RPC 里,客户端会去调用另一个地址空间(通常是一个远程服务器)里的方法。调用代码看起来就像是调用的是一个本地方法,客户端和服务器交互的具体过程被抽象。远程调用相对于本地调用一般较慢而且可靠性更差,因此区分两者是有帮助的。热门的 RPC 框架包括 [Protobuf](https://developers.google.com/protocol-buffers/), [Thrift](https://thrift.apache.org/) 和 [Avro](https://avro.apache.org/docs/current/)。 +在 RPC 中,客户端会去调用另一个地址空间(通常是一个远程服务器)里的方法。调用代码看起来就像是调用的是一个本地方法,客户端和服务器交互的具体过程被抽象。远程调用相对于本地调用一般较慢而且可靠性更差,因此区分两者是有帮助的。热门的 RPC 框架包括 [Protobuf](https://developers.google.com/protocol-buffers/), [Thrift](https://thrift.apache.org/) 和 [Avro](https://avro.apache.org/docs/current/)。 RPC 是一个“请求-响应”协议: * **客户端程序** ── 调用客户端存根程序。就像调用本地方法一样,参数会被压入栈中。 -* **客户端存根程序** ── 将请求过程的 id 和参数打包进请求信息中。 +* **客户端 stub 程序** ── 将请求过程的 id 和参数打包进请求信息中。 * **客户端通信模块** ── 将信息从客户端发送至服务端。 * **服务端通信模块** ── 将接受的包传给服务端存根程序。 -* **服务端存根程序** ── 将结果解包,依据过程 id 调用服务端方法并将参数传递过去。 +* **服务端 stub 程序** ── 将结果解包,依据过程 id 调用服务端方法并将参数传递过去。 RPC 调用示例: @@ -1427,7 +1427,7 @@ POST /anotheroperation RPC 专注于暴露方法。RPC 通常用于处理内部通讯的性能问题,这样你可以手动处理本地调用以更好的适应你的情况。 -当以下情况时选择本地库或者 SDK: +当以下情况时选择本地库(也就是 SDK): * 你知道你的目标平台。 * 你想控制如何访问你的“逻辑”。 @@ -1443,15 +1443,15 @@ RPC 专注于暴露方法。RPC 通常用于处理内部通讯的性能问题, * RPC 很难调试。 * 你可能没办法很方便的去修改现有的技术。举个例子,如果你希望在 [Squid](http://www.squid-cache.org/) 这样的缓存服务器上确保 [RPC 被正确缓存](http://etherealbits.com/2012/12/debunking-the-myths-of-rpc-rest/)的话可能需要一些额外的努力了。 -### 具象状态传输(REST) +### 表述性状态转移(REST) REST 是一种强制的客户端/服务端架构设计模型,客户端基于服务端管理的一系列资源操作。服务端提供修改或获取资源的接口。所有的通信必须是无状态和可缓存的。 RESTful 接口有四条规则: * **标志资源(HTTP 里的 URI)** ── 无论什么操作都使用同一个 URI。 -* **表示的改变(HTTP 的 Verbs)** ── 使用 verbs, headers 和 body。 -* **可自我描述的错误信息(HTTP 中的 状态相应)** ── 使用状态码,不要重新造轮子。 +* **表示的改变(HTTP 的动作)** ── 使用动作, headers 和 body。 +* **可自我描述的错误信息(HTTP 中的 status code)** ── 使用状态码,不要重新造轮子。 * **[HATEOAS](http://restcookbook.com/Basics/hateoas/)(HTTP 中的HTML 接口)** ── 你的 web 服务器应该能够通过浏览器访问。 REST 请求的例子: @@ -1463,16 +1463,16 @@ PUT /someresources/anId {"anotherdata": "another value"} ``` -REST 关注于暴露数据。它最小化了客户端与服务端的联系并经常被用户公共 HTTP API。REST 使用更通常与规范化的方法来通过 URI 暴露资源,[通过 header 来表述](https://github.com/for-GET/know-your-http-well/blob/master/headers.md)并通过 GET, POST, PUT, DELETE 和 PATCH 这些 verbs 来进行操作。因为无状态的特性,REST 易于横向扩展和隔离。 +REST 关注于暴露数据。它减少了客户端/服务端的耦合程度,经常用于公共 HTTP API 接口设计。REST 使用更通常与规范化的方法来通过 URI 暴露资源,[通过 header 来表述](https://github.com/for-GET/know-your-http-well/blob/master/headers.md)并通过 GET, POST, PUT, DELETE 和 PATCH 这些动作来进行操作。因为无状态的特性,REST 易于横向扩展和隔离。 #### 缺点:REST * 由于 REST 将重点放在暴露数据,所以当资源不是自然组织的或者结构复杂的时候它可能无法很好的适应。举个例子,返回过去一小时中与特定事件集匹配的更新记录这种操作就很难表示为路径。使用 REST,可能会使用 URI 路径,查询参数和可能的请求体来实现。 -* REST 一般依赖几个 verbs(GET, POST, PUT, DELETE 和 PATCH),但有时候仅仅这些没法满足你的需要。举个例子,将过期的文档移动到归档文件夹里去,这样的操作可能没法简单的用上面这几个 verbs 表达。 -* 使用嵌套层次结构来获取复杂资源需要客户端和服务端多次交互来渲染单个视图。比如,获取博客的内容和其下的评论。对于在可变网络环境下的移动应用,是不希望看到这种多次请求。 +* REST 一般依赖几个动作(GET, POST, PUT, DELETE 和 PATCH),但有时候仅仅这些没法满足你的需要。举个例子,将过期的文档移动到归档文件夹里去,这样的操作可能没法简单的用上面这几个 verbs 表达。 +* 为了渲染单个页面,获取被嵌套在层级结构中的复杂资源需要客户端,服务器之间多次往返通信。例如,获取博客内容及其关联评论。对于使用不确定网络环境的移动应用来说,这些多次往返通信是非常麻烦的。 * 随着时间的推移,更多的字段可能会被添加到 API 响应中,较旧的客户端将会接收到所有新的数据字段,即使是那些它们不需要的字段,结果它会增加负载大小并引起更大的延迟。 -### PRC 与 REST 比较 +### RPC 与 REST 比较 | 操作 | RPC | REST | | ------------------------------- | ---------------------------------------- | ---------------------------------------- | @@ -1496,14 +1496,14 @@ REST 关注于暴露数据。它最小化了客户端与服务端的联系并经 * [揭开 RPC 和 REST 的神秘面纱](http://etherealbits.com/2012/12/debunking-the-myths-of-rpc-rest/) * [使用 REST 的缺点是什么](https://www.quora.com/What-are-the-drawbacks-of-using-RESTful-APIs) * [破解系统设计面试](http://www.puncsky.com/blog/2016/02/14/crack-the-system-design-interview/) -* [节约](https://code.facebook.com/posts/1468950976659943/) +* [Thrift](https://code.facebook.com/posts/1468950976659943/) * [为什么在内部使用 REST 而不是 RPC](http://arstechnica.com/civis/viewtopic.php?t=1190508) ## 安全 这一部分需要更多内容。[一起来吧](#contributing)! -安全是一个宽泛的话题。下面这些知识对你应该足够了除非你有很多的经验、安全背景或者你正在申请一个需要安全知识的职位。 +安全是一个宽泛的话题。除非你有相当的经验、安全方面背景或者正在申请的职位要求安全知识,你不需要了解安全基础知识以外的内容: * 在运输和等待过程中加密 * 对所有的用户输入和从用户那里发来的参数进行处理以防止 [XSS](https://en.wikipedia.org/wiki/Cross-site_scripting) 和 [SQL 注入](https://en.wikipedia.org/wiki/SQL_injection)。 @@ -1624,7 +1624,7 @@ Notes Source: Twitter timelines at scale

-** 不要专注于一下文章的细节,专注于以下方面:** +** 不要专注于以下文章的细节,专注于以下方面:** * 发现这些文章中的共同的原则、技术和模式。 * 学习每个组件解决哪些问题,什么情况下使用,什么情况下不适用 @@ -1739,10 +1739,12 @@ Notes * 使用 MapReduce 进行分布式计算 * 一致性哈希 +* 直接存储器访问(DMA)控制器 * [Contribute](#contributing) ## Credits +整个仓库都提供了证书和源 特别鸣谢: From 8afd1d80c016de726ad3f242a6607ca649a1db2e Mon Sep 17 00:00:00 2001 From: xujifa Date: Tue, 11 Apr 2017 22:47:15 +0800 Subject: [PATCH 16/16] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README-zh-Hant.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/README-zh-Hant.md b/README-zh-Hant.md index 86cf649c..90a08dce 100755 --- a/README-zh-Hant.md +++ b/README-zh-Hant.md @@ -1475,13 +1475,13 @@ REST 关注于暴露数据。它减少了客户端/服务端的耦合程度, | 操作 | RPC | REST | | ------------------------------- | ---------------------------------------- | ---------------------------------------- | -| Signup | **POST** /signup | **POST** /persons | -| Resign | **POST** /resign
{
"personid": "1234"
} | **DELETE** /persons/1234 | -| Read a person | **GET** /readPerson?personid=1234 | **GET** /persons/1234 | -| Read a person’s items list | **GET** /readUsersItemsList?personid=1234 | **GET** /persons/1234/items | -| Add an item to a person’s items | **POST** /addItemToUsersItemsList
{
"personid": "1234";
"itemid": "456"
} | **POST** /persons/1234/items
{
"itemid": "456"
} | -| Update an item | **POST** /modifyItem
{
"itemid": "456";
"key": "value"
} | **PUT** /items/456
{
"key": "value"
} | -| Delete an item | **POST** /removeItem
{
"itemid": "456"
} | **DELETE** /items/456 | +| 注册 | **POST** /signup | **POST** /persons | +| 注销 | **POST** /resign
{
"personid": "1234"
} | **DELETE** /persons/1234 | +| 读取用户信息 | **GET** /readPerson?personid=1234 | **GET** /persons/1234 | +| 读取用户物品列表 | **GET** /readUsersItemsList?personid=1234 | **GET** /persons/1234/items | +| 向用户物品列表添加一项 | **POST** /addItemToUsersItemsList
{
"personid": "1234";
"itemid": "456"
} | **POST** /persons/1234/items
{
"itemid": "456"
} | +| 更新一个物品 | **POST** /modifyItem
{
"itemid": "456";
"key": "value"
} | **PUT** /items/456
{
"key": "value"
} | +| 删除一个物品 | **POST** /removeItem
{
"itemid": "456"
} | **DELETE** /items/456 |

Source: Do you really know why you prefer REST over RPC @@ -1598,7 +1598,7 @@ Notes | 设计类似 Memcached 的缓存系统 | [slideshare.net](http://www.slideshare.net/oemebamo/introduction-to-memcached) | | 设计类似亚马逊的推荐系统 | [hulu.com](http://tech.hulu.com/blog/2011/09/19/recommendation-system.html)
[ijcai13.org](http://ijcai13.org/files/tutorial_slides/td3.pdf) | | 设计类似 Bitly 的短链接系统 | [n00tc0d3r.blogspot.com](http://n00tc0d3r.blogspot.com/) | -| 设计类似 WhatsApp 的聊天应用 | [highscalability.com](http://highscalability.com/blog/2014/2/26/the-whatsapp-architecture-facebook-bought-for-19-billion.html) +| 设计类似 WhatsApp 的聊天应用 | [highscalability.com](http://highscalability.com/blog/2014/2/26/the-whatsapp-architecture-facebook-bought-for-19-billion.html) | | 设计类似 Instagram 的图片分享系统| [highscalability.com](http://highscalability.com/flickr-architecture)
[highscalability.com](http://highscalability.com/blog/2011/12/6/instagram-architecture-14-million-users-terabytes-of-photos.html) | | 设计 Facebook 的新闻推荐方法 | [quora.com](http://www.quora.com/What-are-best-practices-for-building-something-like-a-News-Feed)
[quora.com](http://www.quora.com/Activity-Streams/What-are-the-scaling-issues-to-keep-in-mind-while-developing-a-social-network-feed)
[slideshare.net](http://www.slideshare.net/danmckinley/etsy-activity-feeds-architecture) | | 设计 Facebook 的时间线系统 | [facebook.com](https://www.facebook.com/note.php?note_id=10150468255628920)
[highscalability.com](http://highscalability.com/blog/2012/1/23/facebook-timeline-brought-to-you-by-the-power-of-denormaliza.html) | @@ -1637,7 +1637,7 @@ Notes | | | | | Data store | **Bigtable** - Distributed column-oriented database from Google | [harvard.edu](http://www.read.seas.harvard.edu/~kohler/class/cs239-w08/chang06bigtable.pdf) | | Data store | **HBase** - Open source implementation of Bigtable | [slideshare.net](http://www.slideshare.net/alexbaranau/intro-to-hbase) | -| Data store | **Cassandra** - Distributed column-oriented database from Facebook | [slideshare.net](http://www.slideshare.net/planetcassandra/cassandra-introduction-features-30103666) +| Data store | **Cassandra** - Distributed column-oriented database from Facebook | [slideshare.net](http://www.slideshare.net/planetcassandra/cassandra-introduction-features-30103666) | | Data store | **DynamoDB** - Document-oriented database from Amazon | [harvard.edu](http://www.read.seas.harvard.edu/~kohler/class/cs239-w08/decandia07dynamo.pdf) | | Data store | **MongoDB** - Document-oriented database | [slideshare.net](http://www.slideshare.net/mdirolf/introduction-to-mongodb) | | Data store | **Spanner** - Globally-distributed database from Google | [research.google.com](http://research.google.com/archive/spanner-osdi2012.pdf) | @@ -1648,7 +1648,7 @@ Notes | File system | **Hadoop File System (HDFS)** - Open source implementation of GFS | [apache.org](https://hadoop.apache.org/docs/r1.2.1/hdfs_design.html) | | | | | | Misc | **Chubby** - Lock service for loosely-coupled distributed systems from Google | [research.google.com](http://static.googleusercontent.com/external_content/untrusted_dlcp/research.google.com/en/us/archive/chubby-osdi06.pdf) | -| Misc | **Dapper** - Distributed systems tracing infrastructure | [research.google.com](http://static.googleusercontent.com/media/research.google.com/en//pubs/archive/36356.pdf) +| Misc | **Dapper** - Distributed systems tracing infrastructure | [research.google.com](http://static.googleusercontent.com/media/research.google.com/en//pubs/archive/36356.pdf) | | Misc | **Kafka** - Pub/sub message queue from LinkedIn | [slideshare.net](http://www.slideshare.net/mumrah/kafka-talk-tri-hug) | | Misc | **Zookeeper** - Centralized infrastructure and services enabling synchronization | [slideshare.net](http://www.slideshare.net/sauravhaloi/introduction-to-apache-zookeeper) | | | Add an architecture | [Contribute](#contributing) |