├── README.md ├── README_EN.md ├── TERM.md ├── _config.yml ├── concepts ├── README.md ├── README_EN.md ├── assets │ ├── availability.jpeg │ ├── background.jpg │ ├── background.svg │ ├── concepts.jpeg │ ├── database.png │ └── protocols.jpeg ├── availability │ ├── README.md │ ├── README_EN.md │ └── assets │ │ ├── availability-system-design-concept-cover.svg │ │ ├── single-point-of-failure.png │ │ └── the-nine-of-availability.jpeg ├── caching │ ├── README.md │ ├── README_EN.md │ ├── assets │ │ ├── advantages.png │ │ ├── caching-system-design-interview-concept-cover.svg │ │ ├── cdn.png │ │ ├── real-world-analogy-of-caching.png │ │ └── what-do-you-mean-by-caching.png │ └── src │ │ ├── .gitignore │ │ ├── app.js │ │ ├── package-lock.json │ │ └── package.json ├── cap-theorem │ ├── README.md │ ├── README_EN.md │ └── assets │ │ ├── 5676830073815040.png │ │ ├── cap-theorem-in-rdbms.svg │ │ └── cap-theorem.svg ├── consistent-hashing │ ├── README.md │ ├── README_EN.md │ ├── assets │ │ ├── adding-of-new-user.png │ │ ├── consistent-hashing.jpg │ │ ├── consistent-hashing.svg │ │ ├── non-uniform.png │ │ └── removal-of-server.png │ └── src │ │ ├── .gitignore │ │ ├── app.js │ │ ├── libs │ │ └── consistent_hashing.js │ │ ├── node_modules │ │ ├── .package-lock.json │ │ └── crypto │ │ │ ├── README.md │ │ │ └── package.json │ │ ├── package-lock.json │ │ └── package.json ├── databases │ ├── README_EN.md │ ├── assets │ │ ├── compare.png │ │ ├── composite-partitioning.gif │ │ ├── database.svg │ │ ├── features.jpeg │ │ ├── horizontal-partition.jpeg │ │ ├── key-value-concepts.jpeg │ │ ├── key-value.svg │ │ ├── list-partitioning.gif │ │ ├── partition-problem.png │ │ ├── partition-solution.gif │ │ ├── partition.jpeg │ │ └── vertical-partition.jpeg │ ├── key-value │ │ └── README_EN.md │ ├── partition │ │ ├── README.md │ │ └── README_EN.md │ └── sql-nosql │ │ └── README_EN.md ├── distributed-system │ ├── README_EN.md │ ├── assets │ │ ├── distributed-systems.jpg │ │ ├── example.png │ │ ├── graph.png │ │ ├── leader-election-in-distributed-systems.svg │ │ └── workflow-in-distributed-system.svg │ ├── leader-election │ │ └── README_EN.md │ └── workflow │ │ └── README_EN.md ├── latency │ ├── README.md │ ├── README_EN.md │ └── assets │ │ └── latency.svg ├── load-balancers │ ├── README.md │ ├── README_EN.md │ ├── assets │ │ ├── algorithms.svg │ │ ├── approach.png │ │ ├── load-balancers.svg │ │ └── problems.png │ ├── src │ │ ├── .gitignore │ │ ├── app.js │ │ ├── config.js │ │ ├── package-lock.json │ │ └── package.json │ └── types-of-load-balancing-algorithms │ │ └── README_EN.md ├── network-protocols │ ├── README.md │ ├── README_EN.md │ ├── assets │ │ ├── advanced.png │ │ ├── client-server-architecture.svg │ │ ├── client-server.png │ │ ├── compare.png │ │ ├── ip-address.png │ │ ├── ip-package-transfer.gif │ │ ├── network-architecture.png │ │ ├── network-protocols.svg │ │ ├── osi-model.png │ │ ├── peer-to-peer-networks.svg │ │ └── tcp.png │ ├── client-server │ │ └── README_EN.md │ └── p2p │ │ └── README_EN.md ├── others │ ├── long-polling │ │ ├── README.md │ │ ├── README_EN.md │ │ └── assets │ │ │ └── long-polling-cover.svg │ ├── mapreduce │ │ ├── README.md │ │ ├── README_EN.md │ │ └── assets │ │ │ ├── dataflow.png │ │ │ ├── mapreduce.svg │ │ │ └── phase.png │ ├── polling-sse-websocket │ │ ├── README_EN.md │ │ └── assets │ │ │ ├── high-level-comparsing.png │ │ │ ├── osi-model.png │ │ │ ├── sse-browsers.png │ │ │ └── websocket-data.png │ ├── process-in-os │ │ ├── README.md │ │ ├── README_EN.md │ │ └── assets │ │ │ ├── execution.jpeg │ │ │ ├── medium-term.jpeg │ │ │ ├── memory.jpeg │ │ │ ├── pcb.jpeg │ │ │ ├── process.svg │ │ │ ├── schedulers.jpeg │ │ │ └── states.jpeg │ ├── pubsub-pattern │ │ ├── README.md │ │ ├── README_EN.md │ │ └── assets │ │ │ ├── example.png │ │ │ ├── pubsub.svg │ │ │ ├── work-2.png │ │ │ ├── work-3.png │ │ │ └── work.png │ ├── redundancy │ │ ├── README.md │ │ ├── README_EN.md │ │ └── assets │ │ │ └── redundancy.png │ ├── sse │ │ ├── README.md │ │ ├── README_EN.md │ │ └── assets │ │ │ └── sse.svg │ └── websockets │ │ ├── README.md │ │ ├── README_EN.md │ │ └── assets │ │ ├── osi.jpeg │ │ └── websocket.avif ├── proxies │ ├── README.md │ ├── README_EN.md │ ├── assets │ │ ├── forward-proxy.png │ │ ├── how-proxy-work.png │ │ ├── proxies.svg │ │ ├── proxy-vs-load-balancer.png │ │ ├── reverse-proxy.png │ │ ├── use-case.png │ │ └── what-are-proxies.png │ └── src │ │ ├── .gitignore │ │ ├── app.js │ │ ├── package-lock.json │ │ └── package.json └── throughput │ ├── README.md │ ├── README_EN.md │ └── assets │ └── throughput.svg └── examples ├── README.md ├── REAMDE_EN.md ├── assets ├── What-Is-System-Design.jpg ├── dropbox-logo.png ├── facebook-logo.png ├── instagram-logo.png ├── messsenger-logo.png ├── rate-limiter-logo.png ├── system-in-realworld.jpg ├── tinyurl-logo.png ├── twitter-logo.png ├── typeahead-logo.png ├── uber-logo.png ├── web-crawler-logo.png ├── yelp-logo.png └── youtube-logo.png ├── dropbox ├── README.md ├── README_EN.md └── assets │ ├── component-design.png │ ├── high-level-design.png │ ├── logo.png │ ├── message-queue.png │ └── storage.png ├── facebook ├── README_EN.md └── assets │ ├── database.png │ ├── high-level-design.png │ └── logo.png ├── instagram ├── README.md ├── README_EN.md └── assets │ ├── database.png │ ├── design.png │ ├── high-level.png │ ├── logo.png │ └── redundancy.png ├── messenger ├── README_EN.md └── assets │ ├── high-level-design.png │ ├── logo.jpg │ ├── manage-user.png │ ├── workflow-1.png │ ├── workflow-2.png │ ├── workflow-3.png │ ├── workflow-4.png │ ├── workflow-5.png │ ├── workflow-6.png │ ├── workflow-7.png │ └── workflow-8.png ├── rate-limiter ├── README_EN.md └── assets │ ├── atomicity.svg │ ├── basic-design.svg │ ├── example.svg │ ├── fixed-window.svg │ ├── high-level.png │ ├── logo.png │ ├── problem-fixed-window.svg │ ├── sliding-window-counter.svg │ ├── sliding-window-example.svg │ └── sliding-window.svg ├── tinyurl ├── README.md ├── README_EN.md └── assets │ ├── base62-encoding.png │ ├── cache.png │ ├── database.svg │ ├── databases-schema.png │ ├── design-a-url-shortening-service-like-tiny-url-cover.jpg │ ├── example.png │ ├── keys-offline.png │ ├── load-balancer.png │ ├── logo.png │ ├── purging.png │ ├── skeleton.png │ ├── workflow.png │ ├── workflow1.png │ ├── workflow2.png │ ├── workflow3.png │ ├── workflow4.png │ ├── workflow5.png │ ├── workflow6.png │ ├── workflow7.png │ ├── workflow8.png │ └── workflow9.png ├── twitter ├── README.md ├── README_EN.md └── assets │ ├── cache.png │ ├── database-schema.svg │ ├── high-level-design.png │ ├── logo.jpg │ ├── logo.png │ └── period.png ├── typeahead-suggestion ├── README_EN.md └── assets │ ├── algorithm-1.png │ ├── algorithm-2.png │ ├── logo.png │ └── permanent.png ├── uber ├── README_EN.md └── assets │ ├── design.png │ └── logo.jpeg ├── web-crawler ├── README_EN.md └── assets │ ├── detail-component-design.png │ ├── high-level-design.png │ └── logo.jpg ├── yelp ├── README_EN.md └── assets │ ├── design.png │ ├── grids.png │ ├── logo.jpg │ └── quadtree.png └── youtube ├── README_EN.md └── assets ├── detail-component.png ├── high-level-design.png ├── logo.png └── logo.webp /README.md: -------------------------------------------------------------------------------- 1 | # System Design 2 | 3 | ## Concepts 4 | 5 | | Latency | Availability | Throughput | 6 | |-|-|-| 7 | | [![](./concepts/latency/assets/latency.svg)](./concepts/latency) | [![](./concepts/availability/assets/availability-system-design-concept-cover.svg)](./concepts/availability) | [![](./concepts/throughput/assets/throughput.svg)](./concepts/throughput) | 8 | | Caching | Load Balancers | Proxies | 9 | | [![](./concepts/caching/assets/caching-system-design-interview-concept-cover.svg)](./concepts/caching) | [![](./concepts/load-balancers/assets/load-balancers.svg)](./concepts/load-balancers) | [![](./concepts/proxies/assets/proxies.svg)](./concepts/proxies) | 10 | | CAP Theorem | Database | Distributed System | 11 | | [![](./concepts/cap-theorem/assets/cap-theorem-in-rdbms.svg)](./concepts/cap-theorem) | [![](./concepts/databases/assets/database.svg)](./concepts/databases) | [![](./concepts/distributed-system/assets/workflow-in-distributed-system.svg)](./concepts/distributed-system) | 12 | | Network Protocols | Consistent Hashing | Process in OS | 13 | | [![](./concepts/network-protocols/assets/network-protocols.svg)](./concepts/network-protocols) | [![](./concepts/consistent-hashing/assets/consistent-hashing.jpg)](./concepts/consistent-hashing) | [![](./concepts/others/process-in-os/assets/process.svg)](./concepts/others/process-in-os) | 14 | | Long Polling | WebSockets | Server-Sent Events | 15 | | [![](./concepts/others/long-polling/assets/long-polling-cover.svg)](./concepts/others/long-polling) | [![](./concepts/others/websockets/assets/websocket.avif)](./concepts/others/websockets) | [![](./concepts/others/sse/assets/sse.svg)](./concepts/others/sse) | 16 | | Map Reduce | Storage and Redundancy | PubSub Pattern | 17 | | [![](./concepts/others/mapreduce/assets/mapreduce.svg)](./concepts/others/mapreduce) | [![](./concepts/others/redundancy/assets/redundancy.png)](./concepts/others/redundancy) | [![](./concepts/others/pubsub-pattern/assets/pubsub.svg)](./concepts/others/pubsub) | 18 | 19 | ## Examples 20 | 21 | | Dropbox | Instagram | Facebook | Uber | 22 | |-|-|-|-| 23 | | ![](./examples/assets/dropbox-logo.png) | ![](./examples/assets/instagram-logo.png) | ![](./examples/assets/facebook-logo.png) | ![](./examples/assets/uber-logo.png) | 24 | | Youtube | Messenger | Yelp | Twitter | 25 | | ![](./examples/assets/youtube-logo.png) | ![](./examples/assets/messsenger-logo.png) | ![](./examples/assets/yelp-logo.png) | ![](./examples/assets/twitter-logo.png) | 26 | | TinyURL | Rate Limiter | Web Crawler | Typeadead Suggestion | 27 | | ![](./examples/assets/tinyurl-logo.png) | ![](./examples/assets/rate-limiter-logo.png) | ![](./examples/assets/web-crawler-logo.png) | ![](./examples/assets/typeahead-logo.png) | -------------------------------------------------------------------------------- /README_EN.md: -------------------------------------------------------------------------------- 1 | # System Design 2 | 3 | ## Concepts 4 | 5 | | Latency | Availability | Throughput | 6 | |-|-|-| 7 | | ![](./concepts/latency/assets/latency.svg) | ![](./concepts/availability/assets/availability-system-design-concept-cover.svg)| ![](./concepts/throughput/assets/throughput.svg) | 8 | | Caching | Load Balancers | Proxies | 9 | | ![](./concepts/caching/assets/caching-system-design-interview-concept-cover.svg) | ![](./concepts/load-balancers/assets/load-balancers.svg) | ![](./concepts/proxies/assets/proxies.svg) | 10 | | CAP Theorem | Database | Distributed System | 11 | | ![](./concepts/cap-theorem/assets/cap-theorem-in-rdbms.svg) | ![](./concepts/databases/assets/database.svg) | ![](./concepts/distributed-system/assets/workflow-in-distributed-system.svg) | 12 | | Network Protocols | Consistent Hashing | Process in OS | 13 | | ![](./concepts/network-protocols/assets/network-protocols.svg) | ![](./concepts/consistent-hashing/assets/consistent-hashing.jpg) | ![](./concepts/others/process-in-os/assets/process.svg) | 14 | | Long Polling | WebSockets | Server-Sent Events | 15 | | ![](./concepts/others/long-polling/assets/long-polling-cover.svg) | ![](./concepts/others/websockets/assets/websocket.avif) | ![](./concepts/others/sse/assets/sse.svg) | 16 | | Map Reduce | Storage and Redundancy | PubSub Pattern | 17 | | ![](./concepts/others/mapreduce/assets/mapreduce.svg) | ![](./concepts/others/redundancy/assets/redundancy.png) | ![](./concepts/others/pubsub-pattern/assets/pubsub.svg) | 18 | 19 | ## Examples 20 | 21 | | Dropbox | Instagram | Facebook | Uber | 22 | |-|-|-|-| 23 | | ![](./examples/assets/dropbox-logo.png) | ![](./examples/assets/instagram-logo.png) | ![](./examples/assets/facebook-logo.png) | ![](./examples/assets/uber-logo.png) | 24 | | Youtube | Messenger | Yelp | Twitter | 25 | | ![](./examples/assets/youtube-logo.png) | ![](./examples/assets/messsenger-logo.png) | ![](./examples/assets/yelp-logo.png) | ![](./examples/assets/twitter-logo.png) | 26 | | TinyURL | Rate Limiter | Web Crawler | Typeadead Suggestion | 27 | | ![](./examples/assets/tinyurl-logo.png) | ![](./examples/assets/rate-limiter-logo.png) | ![](./examples/assets/web-crawler-logo.png) | ![](./examples/assets/typeahead-logo.png) | -------------------------------------------------------------------------------- /TERM.md: -------------------------------------------------------------------------------- 1 | # Danh sách thuật ngữ 2 | 3 | Các từ ngữ chuyên ngành phổ biến được dùng: 4 | 5 | - server: máy chủ 6 | - client: máy khách 7 | - availability: khả dụng 8 | - cache: bộ nhớ đệm 9 | - schedule: định thời (lập lịch) 10 | - load balancer: bộ cân bằng tải 11 | - distribute: phân tán 12 | - latency: độ trễ 13 | - throughput: thông lượng 14 | - traffic: lưu lượng truy cập 15 | - redundancy: dự phòng 16 | - scaling: mở rộng 17 | - partition: phân vùng 18 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman -------------------------------------------------------------------------------- /concepts/assets/availability.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/assets/availability.jpeg -------------------------------------------------------------------------------- /concepts/assets/background.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/assets/background.jpg -------------------------------------------------------------------------------- /concepts/assets/concepts.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/assets/concepts.jpeg -------------------------------------------------------------------------------- /concepts/assets/database.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/assets/database.png -------------------------------------------------------------------------------- /concepts/assets/protocols.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/assets/protocols.jpeg -------------------------------------------------------------------------------- /concepts/availability/README.md: -------------------------------------------------------------------------------- 1 | # Tính Khả Dụng 2 | 3 | [Version English](./README_EN.md) 4 | 5 |
6 | 7 |
8 | 9 | Tính khả dụng là khái niệm được đề cập nhiều nhất trong các câu hỏi phỏng vấn thiết kế hệ thống. Bản thân chúng ta cũng có thể đã từng trải qua những khoảnh khắc mà chúng ta không thể truy cập một ứng dụng nhất định do ngừng hoạt động hoặc không khả dụng. Gần đây, YouTube phải đối mặt với sự cố ngừng hoạt động toàn cầu khiến người dùng không thể phát video trong khoảng một giờ. Bạn đã bao giờ tự hỏi lý do đằng sau những sự cố này là gì và làm thế nào người ta có thể ngăn nó xảy ra? Hãy cùng tìm hiểu. 10 | 11 | ## Tính khả dụng là gì? 12 | 13 | Tính khả dụng là tỉ lệ phần trăm trong một khoảng thời gian nhất định mà một hệ thống sẵn sàng thực hiện các tác vụ và chức năng của nó trong điều kiện bình thường. Tỷ lệ khả dụng mà hệ thống yêu cầu phụ thuộc vào logic nghiệp vụ hoặc cách sử dụng hệ thống. Hãy lấy một số ví dụ. 14 | 15 | Hệ thống kiểm soát không lưu là một trong những ví dụ điển hình về các hệ thống yêu cầu **tính khả dụng cao**. Trong thế giới ngày nay, việc di chuyển bằng đường hàng không rất phổ biến và được đông đảo người sử dụng, một sai sót trong việc điều khiển máy bay có thể dẫn đến một kết quả thảm khốc. 16 | 17 | Ngược lại, một hệ thống có ít người truy cập và không dễ bị hỏng hóc nghiêm trọng thì lại yêu cầu tính khả dụng ít hơn một chút. Tính khả dụng cao đi kèm với chi phí đắt, vì vậy chúng ta phải tối ưu hóa theo nhu cầu của mình. 18 | 19 | ## Tính khả dụng được đo lường như thế nào? 20 | 21 | Tính khả dụng của hệ thống được đo bằng phần trăm thời gian hoạt động của hệ thống trong một khoảng thời gian nhất định hoặc bằng cách chia thời gian hoạt động cho tổng thời gian hoạt động cộng với thời gian ngừng hoạt động trong một khoảng thời gian nhất định. 22 | 23 | **Tính khả dụng = Thời gian hoạt động ÷ (Thời gian hoạt động + thời gian ngừng hoạt động)** 24 | 25 | ### Tính khả dụng của số 9 26 | 27 | Tính khả dụng cũng có thể được thể hiện dưới con số **9**. Trong các ứng dụng có yêu cầu cao, chúng ta thường đo lường tính khả dụng theo con số 9 hơn là tỷ lệ phần trăm. Nếu tính khả dụng là 99,00 phần trăm, nó được cho là có "2 nines" khả dụng và nếu nó là 99,9 phần trăm, nó được gọi là "3 nines"... Hệ thống có 5 nines (tức là 99,999%) khả dụng được cho là đạt tiêu chuẩn vàng về tính khả dụng. Chúng ta hãy xem bảng dưới đây. 28 | 29 | ![](./assets/the-nine-of-availability.jpeg) 30 | 31 | Tính khả dụng cao luôn có sự đánh đổi của nó, chẳng hạn như độ trễ cao hơn hoặc thông lượng thấp hơn và việc đạt được tính khả dụng cao là rất khó. Chúng ta cần xem xét sự cân bằng mà chúng ta cần thực hiện dựa trên yêu cầu hệ thống của chúng ta. 32 | 33 | Để tạo ra các hệ thống có tính khả dụng cao, chúng ta cần đảm bảo rằng hệ thống không có bất kỳ **SPOF** nào. SPOF - Single point of failure, một điểm lỗi duy nhất trong hệ thống là một điểm hay một vị trí nào đó trong hệ thống mà nó có thể dẫn đến sự cố sập toàn bộ hệ thống. 34 | 35 | Vậy, làm thế nào để chúng ta loại bỏ một điểm lỗi duy nhất trong một hệ thống? 36 | Để loại bỏ bất kỳ điểm lỗi nào, chúng ta cần tạo cho hệ thống có nhiều phiên bản dự phòng hơn. Dự phòng là hành động sao chép hoặc thêm một số thành phần nhất định vào trong hệ thống. Hãy lấy một ví dụ; hãy tưởng tượng bạn có một hệ thống bao gồm hai server giống hệt nhau được cài đặt phía sau bộ cân bằng tải. Lưu lượng đến từ client sẽ được phân phối giữa các server, nhưng nếu một trong các server gặp sự cố, bộ cân bằng tải sẽ chuyển hướng tất cả lưu lượng đến server còn lại, hệ thống vẫn sẽ hoạt động. 37 | 38 | ![](./assets/single-point-of-failure.png) 39 | 40 | Bây giờ chúng ta đã tạo dự phòng cho server của mình và bộ cân bằng tải có thể phát hiện lỗi và phản hồi phù hợp. Tuy nhiên, trong trường hợp này, bản thân bộ cân bằng tải vẫn là một điểm lỗi duy nhất khác. Để tránh điều này, ta tiếp tục tạo dự phòng cho bộ cân bằng tải. 41 | 42 | Một điều quan trọng cần lưu ý ở đây là chỉ với dự phòng không thể đảm bảo tính khả dụng cao. Một thiết bị luôn cần có các cơ chế để phát hiện các hư hỏng. Điều quan trọng nữa là có thể thực hiện kiểm tra tính khả dụng cao và có thể thực hiện hành động khắc phục bất cứ khi nào một trong các thành phần của hệ thống không khả dụng. Cả hai cách tiếp cận là *top-to-bottom* và *phân tán tính khả dụng* đều hoạt động trên phần cứng, đồng thời cũng có thể sử dụng các kỹ thuật *giảm downtime* dựa trên phần mềm. 43 | 44 | Dự phòng là một cách tiếp cận dựa trên phần cứng. Mặt khác, việc thực hiện các kỹ thuật khả dụng cao, hầu như luôn luôn yêu cầu phần mềm. 45 | 46 | - **Dự phòng chủ động (Active redundancy):** Khi bạn có nhiều máy hoạt động cùng nhau, nhưng chỉ một hoặc một số máy sẽ xử lý lưu lượng truy cập hoặc thực hiện công việc. Nếu một trong số chúng bị lỗi, các máy khác sẽ nhận biết bằng cách nào đó và sau đó tiếp quản. 47 | - **Dự phòng thụ động (Passive redundancy):** Khi bạn có nhiều thành phần tại một lớp nhất định trong hệ thống của mình và nếu vào bất kỳ thời điểm nào, một trong số chúng sập, các máy chủ còn lại sẽ tiếp quản và ngăn chặn bất kỳ lỗi nào. 48 | 49 | ## Sự khác biệt giữa tính khả dụng cao và khả năng chịu lỗi 50 | 51 | Cả tính khả dụng cao và khả năng chịu lỗi đều áp dụng cho các phương pháp cung cấp mức thời gian hoạt động cao. Tuy nhiên, các phương pháp chịu lỗi và tính khả dụng cao sẽ hoàn thành mục tiêu theo cách khác nhau. 52 | 53 | Việc tính toán khả năng chịu lỗi yêu cầu dự phòng phần cứng đầy đủ. Để đạt được khả năng chịu lỗi, một số hệ thống chạy song song, sao chép các chương trình giống nhau và thực hiện các lệnh cùng nhau. Nếu hệ thống chính bị lỗi, không thể hoạt động, hệ thống khác có thể đảm nhận. 54 | 55 | Sẽ là tốt nhất nếu bạn có phần cứng tiên tiến để đạt được khả năng chịu lỗi của máy tính. Nó phải có khả năng phát hiện các lỗi thành phần ngay lập tức và cho phép các hệ thống khác nhau hoạt động cùng lúc. 56 | 57 | Ưu điểm chính của dạng máy này là bảo toàn bộ nhớ và bản ghi của chương trình. Tuy nhiên, có thể mất nhiều thời gian hơn đối với các sự cố của mạng hay thiết bị phức tạp hơn. Trong khi đó, các vấn đề kỹ thuật gây ra sự cố hệ thống cũng có thể gây ra sự cố tương tự đối với các hệ thống dự phòng đang chạy song song, tạo ra sự cố trên toàn hệ thống. 58 | 59 | Thay vào đó, chiến lược high-value sử dụng phương pháp dựa trên phần mềm để giảm thiểu thời gian ngừng hoạt động của máy chủ thay vì phương pháp dựa trên phần cứng. Một cụm high-display sử dụng một tập hợp các máy chủ hoạt động cùng nhau thay vì sử dụng phần cứng vật lý để đạt được khả năng dự phòng tối đa. 60 | -------------------------------------------------------------------------------- /concepts/availability/README_EN.md: -------------------------------------------------------------------------------- 1 | # Availability: System Design Concept 2 | 3 | Many of us may have experienced moments where we could not access certain applications due to an outage or unavailability. Recently, YouTube faced a global outage that stopped users from streaming videos for about an hour. You may wonder about the reason behind it and How one can prevent it from happening? Let’s Find Out. 4 | 5 | ## What is Availability? 6 | 7 | Availability is the percentage of time in a given period that a system is available to perform its task and function under normal conditions. One way to look at is how resistant a system is to failures. The percentage of availability that a system requires depends on the business logic or usage of the system. Let us take some examples. 8 | 9 | Air Traffic Control systems are among the best examples of systems that require high availability. In today’s world, where air travel is so complex and busy, a single error in directing airplanes can lead to catastrophic results. In contrast, a system with few visitors and not prone to catastrophic failures require slightly lesser available systems. High Availability comes with a cost, so we have to optimize according to our needs. 10 | 11 | ## How is Availability Measured? 12 | 13 | A system’s availability is measured as the percentage of a system’s uptime in a given time period or by dividing the total uptime by the total uptime and downtime in a given period of time. 14 | 15 | Availability = Uptime ÷ (Uptime + downtime) 16 | 17 | ### The Nine’s of Availability 18 | 19 | Availability can also be expressed in terms of Nines. In high-demand applications, we usually measure availability in terms of Nines rather than percentages. If availability is 99.00 percent available, it is said to have “2 nines” of availability, and if it is 99.9 percent, it is called “3 nines,” and so on. A system with 5 nines (i.e., 99.999%) of availability is said to have a Gold Standard of Availability. Let's take a look at different Nines of Availability. 20 | 21 | ![](./assets/availability-system-design-concept-cover.svg) 22 | 23 | ## How do we achieve High Availability? 24 | 25 | High Availability comes with its own tradeoffs, such as higher latency or lower throughput, and achieving high availability is very difficult. To make highly available systems, we need to make sure that the system does not have any **single point of failure**. So, How do we eliminate a single point of failure in a system? To eliminate any single point of failure, we need to make our system more redundant. 26 | 27 | Redundancy is the act of duplicating or adding certain parts of our system. Let's take an example; imagine you have a system consisting of two identical web servers that are installed behind a load balancer. The traffic coming from clients will be distributed between the web servers, but if one of the servers goes down, the load balancer will redirect all traffic to the remaining server, which is working. 28 | 29 | ![](./assets/single-point-of-failure.png) 30 | 31 | Now that we have made our servers redundant and prone to failure as the load balancer can detect the failure and respond accordingly. But, in this scenario, the load balancing layer itself remains the single point of failure. To avoid this, a simple way out is to make the load balancing layer redundant. An essential thing to note here is that redundancy alone cannot ensure high availability. A device also needs mechanisms for detecting failures. It is also important to be able to perform high-availability testing and to be able to take corrective action any time one of the stack’s components becomes unavailable. 32 | 33 | Top-to-bottom or distributed highavailability approaches may include both work and hardware, or software-based downtime reduction techniques are also successful. Redundancy is a hardware-based approach. The implementation of high availability techniques, on the other hand, almost always requires software. 34 | - **Passive Redundancy**: When you have multiple components at a given layer in your system, and if at any point, one of them dies, the remaining servers take over and prevent any failure. 35 | - **Active Redundancy**: When you have multiple machines that work together, only one or a few of the machines will typically be handling traffic or doing work. If one of them fails, the other machines are going to know somehow and then take over. 36 | 37 | ## Difference Between High Availability and Fault Tolerance 38 | 39 | Both high availability and fault tolerance apply to methods for providing high uptime levels. Fault-tolerant and high availability methods, however, accomplish the objective differently. 40 | 41 | Fault-tolerant computing requires full hardware redundancy. To achieve fault tolerance, several systems run in parallel, mirroring programs identically and executing instructions together. If the main system fails, with no loss in uptime, another system can take charge. 42 | 43 | It would be best if you had advanced hardware to achieve fault-tolerant computing. It must be able to detect component faults immediately and allow the various systems to operate in conjunction. 44 | 45 | This form of machine preserves the programs’ memory and records, a major advantage. However, it may take longer for networks and devices that are more complicated to respond to malfunctions. In comparison, technical issues that cause crashing systems may also cause a similar breakdown of redundant systems running parallel, creating a system-wide failure. 46 | 47 | A high-value strategy instead uses a software-based approach to minimize server downtime rather than a hardware-based approach. A high-display cluster finds a collection of servers together instead of using physical hardware to achieve maximum redundancy. 48 | -------------------------------------------------------------------------------- /concepts/availability/assets/single-point-of-failure.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/availability/assets/single-point-of-failure.png -------------------------------------------------------------------------------- /concepts/availability/assets/the-nine-of-availability.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/availability/assets/the-nine-of-availability.jpeg -------------------------------------------------------------------------------- /concepts/caching/assets/advantages.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/caching/assets/advantages.png -------------------------------------------------------------------------------- /concepts/caching/assets/cdn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/caching/assets/cdn.png -------------------------------------------------------------------------------- /concepts/caching/assets/real-world-analogy-of-caching.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/caching/assets/real-world-analogy-of-caching.png -------------------------------------------------------------------------------- /concepts/caching/assets/what-do-you-mean-by-caching.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/caching/assets/what-do-you-mean-by-caching.png -------------------------------------------------------------------------------- /concepts/caching/src/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /concepts/caching/src/app.js: -------------------------------------------------------------------------------- 1 | const express = require("express"); 2 | const axios = require("axios"); 3 | const redis = require("redis"); 4 | const app = express(); 5 | 6 | const redisPort = 6379 7 | const client = redis.createClient(redisPort); 8 | 9 | client.on("error", (err) => { 10 | console.log(err); 11 | }) 12 | 13 | app.get("/jobs", (req, res) => { 14 | const searchTerm = req.query.search; 15 | try { 16 | client.get(searchTerm, async (err, jobs) => { 17 | if (err) throw err; 18 | 19 | if (jobs) { 20 | res.status(200).send({ 21 | jobs: JSON.parse(jobs), 22 | message: "data retrieved from the cache" 23 | }); 24 | } 25 | else { 26 | const jobs = await axios.get(`https://jobs.github.com/positions.json?search=${searchTerm}`); 27 | client.setex(searchTerm, 600, JSON.stringify(jobs.data)); 28 | res.status(200).send({ 29 | jobs: jobs.data, 30 | message: "cache miss" 31 | }); 32 | } 33 | }); 34 | } catch(err) { 35 | res.status(500).send({message: err.message}); 36 | } 37 | }); 38 | 39 | app.listen(process.env.PORT || 3000, () => { 40 | console.log("Node server started"); 41 | }); -------------------------------------------------------------------------------- /concepts/caching/src/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "src", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "node app.js", 8 | "test": "echo \"Error: no test specified\" && exit 1" 9 | }, 10 | "keywords": [], 11 | "author": "", 12 | "license": "ISC", 13 | "dependencies": { 14 | "axios": "^0.27.2", 15 | "express": "^4.18.1", 16 | "redis": "^4.1.0" 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /concepts/cap-theorem/README.md: -------------------------------------------------------------------------------- 1 | # Định lý CAP: Khái niệm Thiết kế Hệ thống 2 | 3 | [Version English](./README_EN.md) 4 | 5 | ![](./assets/cap-theorem-in-rdbms.svg) 6 | 7 | Định lý CAP là một trong những khái niệm quan trọng được sử dụng trong hệ thống phân tán. Trong bài viết này, chúng ta sẽ đề cập đến các khái niệm cơ bản liên quan đến định lý CAP và khả năng áp dụng của nó cho các hệ thống khác nhau. 8 | 9 | ## Định lý CAP là gì? 10 | 11 | Định lý CAP là khái niêmj cốt lõi cho việc thiết kế các hệ thống dữ liệu chia sẻ trên toàn mạng. Nó nói rằng một hệ thống cơ sở dữ liệu phân tán chỉ có thể đáp ứng hai trong số ba chức năng sau: *tính nhất quán*, *tính khả dụng* và *dung sai phân vùng*. Chúng ta có thể cân bằng giữa ba chức năng trên dựa trên các trường hợp cụ thể sử dụng cho hệ thống. 12 | 13 | ## Tại sao định lý CAP lại quan trọng? 14 | 15 | Trong một hệ thống phân tán, chúng ta cần lưu trữ dữ liệu qua nhiều nút và đồng thời cần giao tiếp qua mạng. Do sự phụ thuộc quá lớn vào các cuộc gọi mạng, hệ thống phân tán thường rơi vào bẫy lỗi mạng. Vì vậy dung sai phân vùng là điều cần thiết. Trong trường hợp như vậy, chúng ta cần phải lựa chọn giữa tính nhất quán hoặc tính khả dụng dựa trên yêu cầu của chúng ta. 16 | 17 | Bất cứ khi nào tính nhất quán được ưu tiên hơn tính khả dụng, thì sẽ là một thách thức đối với hệ thống để trả về dữ liệu gần đây nhất. Nó sẽ trả về một lỗi nếu thông tin cụ thể không thể được đảm bảo là đã cập nhật. Tương tự, bất cứ khi nào tính khả dụng được ưu tiên hơn tính nhất quán, hệ thống sẽ trả về phiên bản thông tin có sẵn gần đây nhất. Vì vậy, điều cần thiết là phải hiểu định lý CAP khi thiết kế bất kỳ ứng dụng đám mây hoặc hệ thống nối mạng nào. Việc lựa chọn một hệ thống quản lý dữ liệu đáp ứng các yêu cầu quan trọng của hệ thống trở nên thuận tiện. 18 | 19 | Chúng ta hãy hiểu các chức năng của cả ba khái niệm. 20 | 21 | ## Tính nhất quán trong định lý CAP 22 | 23 | Nhất quán có nghĩa là mọi thứ phải diễn ra theo cách phối hợp nhịp nhàng với sự đồng bộ hóa thích hợp. Nó đảm bảo rằng tất cả các client sẽ thấy cùng một dữ liệu đồng thời, bất kể chúng được kết nối với nút nào. Thực hiện thao tác đọc sẽ trả về giá trị thao tác ghi gần đây nhất, khiến tất cả các nút trả về cùng một dữ liệu. Bất cứ khi nào dữ liệu được ghi trên nút, thì trách nhiệm cao nhất của nút là chuyển ngay dữ liệu đến tất cả các nút khác trong hệ thống. 24 | 25 | ## Tính khả dụng trong định lý CAP 26 | 27 | Tính khả dụng có nghĩa là hệ thống luôn ở đó và sẵn sàng bất cứ khi nào có yêu cầu. Khi bất kỳ ứng dụng phía client nào yêu cầu dữ liệu, nó sẽ nhận được phản hồi, ngay cả khi một hoặc nhiều nút gặp sự cố. Do đó, để đạt được tính khả dụng trong một hệ thống phân tán, hệ thống phải duy trì hoạt động mọi lúc. Mọi client sẽ nhận được phản hồi, bất kể trạng thái của bất kỳ nút riêng lẻ nào trong hệ thống. 28 | 29 | ## Dung sai phân vùng trong định lý CAP 30 | 31 | Dung sai phân vùng là cần thiết cho một hệ thống phân tán. Vì vậy, ở hầu hết trường hợp chúng ta luôn cần phải lựa chọn giữa tính khả dụng và tính nhất quán. Nó tương ứng với điều kiện hệ thống phải hoạt động bất kể có sự cố nào xảy ra với các nút hay độ trễ giữa các nút hay không. Nói cách khác, điều kiện này nói rằng hệ thống sẽ tiếp tục chạy, bất kể độ trễ và không nhất quán. Nó sẽ duy trì bất kỳ sự cố mạng nào bằng cách sao chép đầy đủ các bản ghi dữ liệu qua các nút và mạng có thể có khác nhau để ngăn hệ thống khỏi bất kỳ lỗi nào. 32 | 33 | ## Định lý CAP trong kiến trúc Cơ sở dữ liệu 34 | 35 | Các mạng phân tán phụ thuộc rất nhiều vào cơ sở dữ liệu NoSQL vì chúng cung cấp khả năng mở rộng theo chiều ngang và chúng có tính phân tán cao. Do đó, chúng có thể dễ dàng và nhanh chóng mở rộng quy mô trên một mạng lưới ngày càng tăng gồm nhiều nút kết nối với nhau. Nhưng như đã thảo luận ở trên, người ta chỉ có thể có hai trong ba chức năng có sẵn. Các cách kết hợp khác nhau và các trường hợp sử dụng của chúng được thảo luận dưới đây: 36 | - **Hệ thống CP**: Hệ thống này tập trung nhiều hơn vào tính nhất quán và dung sai phân vùng. Vì vậy, các hệ thống này không khả dụng ở hầu hết thời gian. Khi bất kỳ sự cố nào xảy ra trong hệ thống, nó phải tắt nút không nhất quán cho đến khi phân vùng được giải quyết và trong thời gian đó, nó không khả dụng. 37 | - **Hệ thống AP**: Loại cơ sở dữ liệu này tập trung nhiều hơn vào tính khả dụng và khả năng chịu phân vùng hơn là tính nhất quán. Khi bất kỳ sự cố nào xảy ra trong hệ thống, thì nó sẽ không còn ở trạng thái nhất quán nữa. Tuy nhiên, tất cả các nút vẫn khả dụng và các nút bị ảnh hưởng có thể trả về phiên bản dữ liệu trước đó và hệ thống sẽ mất một thời gian để trở nên nhất quán. 38 | - **Hệ thống CA**: Loại cơ sở dữ liệu này tập trung nhiều hơn vào tính nhất quán và tính khả dụng trên tất cả các nút hơn là dung sai phân vùng. Dung sai lỗi là điều cần thiết cơ bản của bất kỳ hệ thống phân tán nào, do đó hầu khi sử dụng kiểu kiến ​​trúc CA cho bất kỳ mục đích thực tế nào. 39 | 40 | ## Các trường hợp sử dụng của Định lý CAP 41 | 42 | MongoDB là một hệ quản trị cơ sở dữ liệu NoSQL phổ biến tập trung vào kiểu cơ sở dữ liệu CP. Nó giải quyết các phân vùng mạng bằng cách duy trì tính nhất quán trong khi vẫn ảnh hưởng đến tính khả dụng. 43 | 44 | Cassandra cũng là một cơ sở dữ liệu NoSql phổ biến tập trung vào kiểu cơ sở dữ liệu AP. Nó tập trung hoàn toàn vào tính khả dụng và dung sai phân vùng hơn là tính nhất quán. Nhưng Cassandra cung cấp sự nhất quán cuối cùng bằng cách tìm ra tất cả các điểm mâu thuẫn trong một khoảng thời gian nhất định. 45 | 46 | Các ứng dụng dựa trên microservices cũng phụ thuộc nhiều vào định lý CAP để thiết kế cơ sở dữ liệu hiệu quả nhất cho ứng dụng. Ví dụ: nếu khả năng mở rộng theo chiều ngang là cần thiết đối với ứng dụng với tính nhất quán cuối cùng, thì cơ sở dữ liệu AP như Cassandra có thể giúp đáp ứng các yêu cầu triển khai và đơn giản hóa việc triển khai. Mặt khác, nếu ứng dụng phụ thuộc nhiều vào tính nhất quán của dữ liệu như trong dịch vụ thanh toán, thì sẽ tốt hơn nếu chọn cơ sở dữ liệu quan hệ như PostgreSQL. 47 | 48 | ## Kết luận 49 | 50 | Hệ thống phân tán cho phép chúng ta đạt được mức độ khả dụng, tính sẵn sàng tương đối cao hơn và cung cấp phạm vi cho khả năng mở rộng. Điều cần thiết là thiết kế các hệ thống bằng cách xem xét các kết quả thực tế trong đời sống thực và chọn thiết kế thích hợp nhất phù hợp với ứng dụng của chúng ta. Nó là một kiến ​​trúc phức tạp đòi hỏi quản lý mạng hiệu quả. Vì vậy, điều cần thiết là phải hiểu sự phức tạp phát sinh trong các hệ thống phân tán, thực hiện các đánh đổi thích hợp cho yêu cầu và chọn công cụ phù hợp. -------------------------------------------------------------------------------- /concepts/cap-theorem/README_EN.md: -------------------------------------------------------------------------------- 1 | # CAP Theorem: System Design Concept 2 | 3 | CAP Theorem is one of the important concepts used in Distributed Systems. In this blog, we’ll cover basic concepts related to the CAP theorem and its applicability to various systems. 4 | 5 | ## What is the CAP Theorem? 6 | 7 | CAP Theorem is necessary for designing networked shared data systems. It allows a distributed database system to have only two of these functionalities: Consistency, Availability, and Partition Tolerance. We can make tradeoffs between the three available functionalities based on the unique use case for our system. 8 | 9 | ## Why is the CAP theorem important? 10 | 11 | In a distributed system, we need to store data over multiple nodes and simultaneously need to communicate over the network. Due to massive dependency on network calls, it is prevalent for a distributed system to fall into the trap of network failures. So partition tolerance is essential. In such a case, we need to choose between consistency or availability based on our requirements. 12 | 13 | Whenever consistency is preferred over availability, it is challenging for the system to return the most recent writing. It will return an error if specific information cannot be guaranteed to be up to date. Similarly, whenever availability is preferred over consistency, the system will return the most recent available version of the information. So, it is essential to understand the CAP theorem when designing any cloud app or networked system. It becomes convenient to choose a data management system that meets the critical requirements of the system. 14 | 15 | Let’s understand the functionalities of all three concepts. 16 | 17 | ## Consistency in the CAP theorem 18 | 19 | Consistency means that everything should go on in a well-coordinated manner and with proper synchronization. It ensures that all clients should see the same data simultaneously, regardless of which node they are connected with. Performing a read operation will return the most recent write operation value, causing all nodes to return the same data. Whenever data is written on the node, it is the node’s utmost responsibility to instantly pass on the data to all other nodes in the system. 20 | 21 | ## Availability in the CAP theorem 22 | 23 | Availability means that the system is always there and ready whenever any request is made. When any client requests data, it should get a response, even if one or more nodes are down. Hence, to achieve availability in a distributed system, the system must remain operational every time. Every client should get a response, regardless of the state of any individual node in the system. 24 | 25 | ## Partition Tolerance in the CAP theorem 26 | 27 | Partition Tolerance is necessary for a distributed system. So mostly, we always need to choose between availability and consistency. It corresponds to the condition that the system should work irrespective of any breakdown of nodes or delay between nodes. In other words, this condition states that the system should continue running, irrespective of delay and inconsistency. It should sustain any network failure by sufficiently replicating the data records across various possible nodes and networks to prevent the system from any failure. 28 | 29 | ## CAP theorem Database Architecture 30 | 31 | Distributed networks heavily depend on NoSQL databases as they offer horizontal scalability, and they are highly distributed. Hence, they can easily and rapidly scale across a growing network of multiple interconnected nodes. But as discussed above, one can only have two of the three available functionalities. The different combinations and their use cases are discussed below: 32 | - **CP System**: This system focuses more on consistency and partition tolerance. So these systems are not available most of the time. When any issue occurs in the system, it has to shut down the non-consistent node until the partition is resolved, and during that time, it is not available. 33 | - **AP System**: This type of database focuses more on availability and partition tolerance rather than consistency. When any issue occurs in the system, then it will no longer remain in a consistent state. However, all the nodes remain available, and affected nodes might return a previous version of data, and the system will take some time to become consistent. 34 | - **CA System**: This type of database focuses more on consistency and availability across all nodes than partition tolerance. Fault-Tolerance is the basic necessity of any distributed system, and hence it is almost rare to use a CA type of architecture for any practical purpose. 35 | 36 | ## Use Cases of CAP Theorem 37 | 38 | MongoDB is a popular NoSQL database management system that focuses on a CP database style. It resolves network partitions by maintaining consistency while compromising on availability. 39 | 40 | Cassandra is also a popular NoSql database that focuses on AP database style. It concentrates entirely on availability and partition tolerance rather than consistency. But Cassandra provides eventual consistency by figuring out all the inconsistencies in a certain period of time. 41 | 42 | Microservices-based applications are also heavily dependent on the CAP theorem to design the most efficient databases for the application. For example, if horizontal scalability is essential to the application with eventual consistency, then an AP database like Cassandra can help meet deployment requirements and simplify deployment. On the other hand, if the application depends heavily on data consistency as in a payment service, it would be better to opt for a relational database like PostgreSQL. 43 | 44 | ## Conclusion 45 | 46 | Distributed systems allow us to achieve a relatively higher level of computing power, availability and give the scope of scalability. It is essential to design the systems by considering real-life practical consequences and choosing the most appropriate design suitable for our application. It is a complex architecture that requires effective network management. So it becomes essential to understand the complexity incurred in distributed systems, make the appropriate trade-offs for the task, and select the right tool. -------------------------------------------------------------------------------- /concepts/cap-theorem/assets/5676830073815040.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/cap-theorem/assets/5676830073815040.png -------------------------------------------------------------------------------- /concepts/consistent-hashing/README_EN.md: -------------------------------------------------------------------------------- 1 | # Consistent Hashing: System Design Concept 2 | 3 | This blog discusses the key concepts and approaches which come in handy while scaling out the distributed storage systems. Consistent hashing is beneficial and frequently applied to solving various system-related challenges and helpful in System Design Interviews. It is also useful for alleviating the bottlenecks while designing any back-end system and scaling an application. 4 | 5 | ## What is Consistent Hashing? 6 | 7 | Before diving deep into Consistent Hashing, let’s first understand what Hashing is? Hashing is a computationally efficient way of information retrieval and helpful in enhancing the performance of various programs. In hashing, a hash function is generally used to map the information to a storage pool by generating a hash value using a welldefined logic. 8 | 9 | For example, we can generate a random number that can map to storage by taking mod using the total number of servers. Hence, the hashing is used to map the requests to various servers and get the work done. However, this concept is valid only when the servers don’t change and memory locations are known. Distributed systems often involve changing the underlying servers to handle the requests over a network. Hence to deal with such shortcomings of distributed systems and handle the requests over a network, we need a more efficient manner of handling and organizing requests for a scalable application. This is compensated using Consistent Hashing. 10 | 11 | Consistent hashing is an improvement over normal Hashing. Here, the user and servers are located virtually in a circular ring structure called the Hash ring. The ring is considered infinite and can accommodate any number of servers with/having no fixed allocation and assign them to random locations based on some hash function. 12 | 13 | ## Why do we need Consistent Hashing? 14 | 15 | The traditional hashing method is very ineffective to use and handling requests over a network. This classical method assumes that we have a fixed number of servers, and all the mapping location is known beforehand. This condition is quite problematic in dealing with distributed systems where multiple users are requesting multiple servers. If in case of some servers breakdown, then to map the work to different servers, it requires a large and heavy computation that is very inefficient and affects the throughput of the service and increases the latency of the application. 16 | 17 | In distributed systems, multiple nodes keep on interacting with each other. Suppose we have five nodes in the system and there is a sudden increase in traffic, and to deal with this, we have to add more nodes to the system. Let us say we added two more nodes which make total nodes seven. If we are using normal hashing, we have again recompute the mapping of requests as previously we were taking hash using five nodes, but now we have seven. Similarly, in case of maintenance or failure, the number of nodes decreases, and hence we again need to re-compute the mapping, which is genuinely very inefficient. 18 | 19 | Hence in situations when we are not sure about the number of servers that are operational at any moment, we can not go with the classical hashing method as this requires a lot of redundant computations and reshuffling of the data or requests around the cluster. Moreover, when the number of servers increases, then this approach becomes more and more inefficient as there would be more and more re-computation and re-assignment of requests to the remaining nodes. We need some dynamic way to mitigate all these shortcomings, and hence the idea of Consistent Hashing comes in. 20 | 21 | ## How Consistent Hashing Works? 22 | 23 | Consistent Hashing helps us in effective organization and distribution of resources by ensuring minimum reorganization of requests or users in any failure. In Consistent Hashing, a hash function is used to map servers to locations in a virtual ring. The position of the server is just a random position obtained using the hash function. Consistent Hashing is organized in the following manner: 24 | 1. The servers are hashed using their IP addresses and assigned the position based on the hashing function. 25 | 2. Similarly, the keys are hashed to positions using the same hashing function and placed in the virtual ring. 26 | 3. Map the keys with the server having the same position, and in case the position doesn’t match, then assign the key to the first server that we get while moving in a clockwise direction. 27 | 28 | Hence in this manner, the keys are assigned to the server in Consistent Hashing. The beauty of Consistent Hashing comes when we add or remove servers. 29 | 30 | ## Addition of new server 31 | 32 | When a new server is added to the application, it is mapped using the hash function and allocated to the hash ring’s desired location. After its allotment, all the keys will map on these newly added servers passing its location. This is depicted in the figure below. When server 5 is added between 1and 4, all the requests after 4 are assigned to 5 instead of mapping to 1. Hence in this way, Consistent Hashing helps reduce loads of massive servers and proves highly effective in scaling and increasing the throughput, and improves the latency of the application. 33 | 34 | ![](./assets/adding-of-new-user.png) 35 | 36 | ## Removal of server 37 | 38 | Whenever any server fails in the system, then all the keys previously mapped to the failed server will redirect to the next server, which is located after the failed server in the clockwise direction. Hence in this manner, the service remains active and provides fault tolerant service. This is depicted in the figure below. When server 4 breakdowns, then all the keys mapped to 4 are reallocated to 1, preventing the system from breaking down. 39 | 40 | ![](./assets/removal-of-server.png) 41 | 42 | ## Non-Uniform Distribution 43 | 44 | There is a shortcoming of this approach. All the keys may get mapped to the same server, and hence one server will get all the workload, and all the other servers will remain idle. This situation is very inefficient and is very prone to failure. To deal with this, a new concept has been introduced. All the servers are replicated and arranged at different positions in the ring. In this manner, with an increased number of servers, the distribution becomes much more uniform and helps in the service’s scaling. This is depicted in the figure below. All the servers are replicated and allocated to different locations, and hence this makes the distribution of keys uniform in the hash ring. 45 | 46 | ![](./assets/non-uniform.png) 47 | 48 | ## Conclusion 49 | 50 | Consistent Hashing is one of the most crucial concepts in designing distributed systems as it tackles the scalability challenges with dynamic nodes assignment and provides fault tolerance. It is also very useful in system design interviews. This concept allows the distribution of requests or data in the servers and their mapping to servers efficiently. It helps in achieving Horizontal Scaling and increases the throughput and improves the latency of the application -------------------------------------------------------------------------------- /concepts/consistent-hashing/assets/adding-of-new-user.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/consistent-hashing/assets/adding-of-new-user.png -------------------------------------------------------------------------------- /concepts/consistent-hashing/assets/consistent-hashing.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/consistent-hashing/assets/consistent-hashing.jpg -------------------------------------------------------------------------------- /concepts/consistent-hashing/assets/consistent-hashing.svg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/consistent-hashing/assets/consistent-hashing.svg -------------------------------------------------------------------------------- /concepts/consistent-hashing/assets/non-uniform.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/consistent-hashing/assets/non-uniform.png -------------------------------------------------------------------------------- /concepts/consistent-hashing/assets/removal-of-server.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/consistent-hashing/assets/removal-of-server.png -------------------------------------------------------------------------------- /concepts/consistent-hashing/src/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /concepts/consistent-hashing/src/app.js: -------------------------------------------------------------------------------- 1 | const ConsistentHashing = require('./libs/consistent_hashing'); 2 | const load_balancer = new ConsistentHashing(["node1", "node2", "node3", "node4", "node5"], 10, 'md5', 1500); 3 | 4 | const nodes = {}; 5 | 6 | //incoming req or data 7 | const chars = [ 8 | 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 9 | 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 10 | 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' 11 | ]; 12 | 13 | const run_time_task = [] 14 | 15 | for (let i = 0; i < chars.length; i++) { 16 | run_time_task.push( 17 | new Promise((resolve, reject) => { 18 | 19 | setTimeout(() => { 20 | //get address where need to go/save 21 | const node = load_balancer.getNode(chars[i]); 22 | 23 | if (nodes[node]) { 24 | nodes[node].push(chars[i]); 25 | } else { 26 | nodes[node] = []; 27 | nodes[node].push(chars[i]); 28 | } 29 | 30 | console.log(nodes) 31 | resolve(nodes) 32 | 33 | }, 1000 * i) 34 | 35 | }) 36 | ) 37 | } 38 | 39 | Promise.all(run_time_task).then(() => { 40 | console.log(nodes) 41 | }) -------------------------------------------------------------------------------- /concepts/consistent-hashing/src/libs/consistent_hashing.js: -------------------------------------------------------------------------------- 1 | const crypto = require('crypto'); 2 | 3 | class Consistent_hashing { 4 | constructor(nodes, replicas = 4, algorithm = 'md5', add_note_dynamically_time = 2000) { 5 | this.replicas = replicas; 6 | this.algorithm = algorithm 7 | this.ring = {}; 8 | this.keys = []; 9 | this.nodes = []; 10 | 11 | for (let i = 0; i < nodes.length; i++) { 12 | setTimeout(() => { 13 | this.addNode(nodes[i]); 14 | }, add_note_dynamically_time * i) 15 | } 16 | } 17 | addNode(node) { 18 | this.nodes.push(node); 19 | 20 | for (let i = 0; i < this.replicas; i++) { 21 | const key = this.crypto((node.id || node) + ':' + i); 22 | 23 | this.keys.push(key); 24 | this.ring[key] = node; 25 | } 26 | 27 | this.keys.sort(); 28 | } 29 | removeNode(node) { 30 | for (let i = 0; i < this.nodes.length; i++) { 31 | if (this.nodes[i] == node) { 32 | this.nodes.splice(i, 1); 33 | i--; 34 | } 35 | } 36 | 37 | for (let i = 0; i < this.replicas; i++) { 38 | const key = this.crypto((node.id || node) + ':' + i); 39 | delete this.ring[key]; 40 | 41 | for (let j = 0; j < this.keys.length; j++) { 42 | if (this.keys[j] == key) { 43 | this.keys.splice(j, 1); 44 | j--; 45 | } 46 | } 47 | } 48 | } 49 | getNode(key) { 50 | if (this.getRingLength() == 0) return 0; 51 | 52 | const hash = this.crypto(key); //get hash of data/key 53 | const pos = this.getNodePosition(hash); 54 | 55 | return this.ring[this.keys[pos]]; 56 | } 57 | getNodePosition(hash) { 58 | 59 | //simple binary searching as keys.sort[] was sorted so it will 60 | //searching on basis on javascript string comparison 61 | 62 | let upper = this.getRingLength() - 1; 63 | let lower = 0; 64 | let idx = 0; 65 | let comp = 0; 66 | 67 | if (upper == 0) return 0; 68 | 69 | while (lower <= upper) { 70 | idx = Math.floor((lower + upper) / 2); 71 | comp = this.compare(this.keys[idx], hash); 72 | 73 | 74 | if (comp == 0) { 75 | //if got exact match return pos 76 | return idx; 77 | } else if (comp > 0) { 78 | upper = idx - 1; 79 | } else { 80 | lower = idx + 1; 81 | } 82 | } 83 | 84 | //upper will always be in range between (lower-upper) 85 | //if upper get less than lower, attach data to last node then 86 | if (upper < 0) { 87 | upper = this.getRingLength() - 1; 88 | } 89 | 90 | return upper; 91 | } 92 | getRingLength() { 93 | return Object.keys(this.ring).length; 94 | } 95 | compare(v1, v2) { 96 | //simple string comparison of hash 97 | return v1 > v2 ? 1 : v1 < v2 ? -1 : 0; 98 | } 99 | crypto(str) { 100 | return crypto.createHash(this.algorithm).update(str).digest('hex'); 101 | } 102 | } 103 | 104 | module.exports = Consistent_hashing -------------------------------------------------------------------------------- /concepts/consistent-hashing/src/node_modules/.package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "src", 3 | "version": "1.0.0", 4 | "lockfileVersion": 2, 5 | "requires": true, 6 | "packages": { 7 | "node_modules/crypto": { 8 | "version": "1.0.1", 9 | "resolved": "https://registry.npmjs.org/crypto/-/crypto-1.0.1.tgz", 10 | "integrity": "sha512-VxBKmeNcqQdiUQUW2Tzq0t377b54N2bMtXO/qiLa+6eRRmmC4qT3D4OnTGoT/U6O9aklQ/jTwbOtRMTTY8G0Ig==", 11 | "deprecated": "This package is no longer supported. It's now a built-in Node module. If you've depended on crypto, you should switch to the one that's built-in." 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /concepts/consistent-hashing/src/node_modules/crypto/README.md: -------------------------------------------------------------------------------- 1 | # Deprecated Package 2 | 3 | This package is no longer supported and has been deprecated. To avoid malicious use, npm is hanging on to the package name. 4 | 5 | It's now a built-in Node module. If you've depended on crypto, you should switch to the one that's built-in. 6 | 7 | Please contact support@npmjs.com if you have questions about this package. 8 | -------------------------------------------------------------------------------- /concepts/consistent-hashing/src/node_modules/crypto/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "crypto", 3 | "version": "1.0.1", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/npm/deprecate-holder.git" 12 | }, 13 | "author": "", 14 | "license": "ISC", 15 | "bugs": { 16 | "url": "https://github.com/npm/deprecate-holder/issues" 17 | }, 18 | "homepage": "https://github.com/npm/deprecate-holder#readme" 19 | } 20 | -------------------------------------------------------------------------------- /concepts/consistent-hashing/src/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "src", 3 | "version": "1.0.0", 4 | "lockfileVersion": 2, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "src", 9 | "version": "1.0.0", 10 | "license": "ISC", 11 | "dependencies": { 12 | "crypto": "^1.0.1" 13 | } 14 | }, 15 | "node_modules/crypto": { 16 | "version": "1.0.1", 17 | "resolved": "https://registry.npmjs.org/crypto/-/crypto-1.0.1.tgz", 18 | "integrity": "sha512-VxBKmeNcqQdiUQUW2Tzq0t377b54N2bMtXO/qiLa+6eRRmmC4qT3D4OnTGoT/U6O9aklQ/jTwbOtRMTTY8G0Ig==", 19 | "deprecated": "This package is no longer supported. It's now a built-in Node module. If you've depended on crypto, you should switch to the one that's built-in." 20 | } 21 | }, 22 | "dependencies": { 23 | "crypto": { 24 | "version": "1.0.1", 25 | "resolved": "https://registry.npmjs.org/crypto/-/crypto-1.0.1.tgz", 26 | "integrity": "sha512-VxBKmeNcqQdiUQUW2Tzq0t377b54N2bMtXO/qiLa+6eRRmmC4qT3D4OnTGoT/U6O9aklQ/jTwbOtRMTTY8G0Ig==" 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /concepts/consistent-hashing/src/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "src", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "node app.js", 8 | "test": "echo \"Error: no test specified\" && exit 1" 9 | }, 10 | "author": "", 11 | "license": "ISC", 12 | "dependencies": { 13 | "crypto": "^1.0.1" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /concepts/databases/assets/compare.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/databases/assets/compare.png -------------------------------------------------------------------------------- /concepts/databases/assets/composite-partitioning.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/databases/assets/composite-partitioning.gif -------------------------------------------------------------------------------- /concepts/databases/assets/database.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /concepts/databases/assets/features.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/databases/assets/features.jpeg -------------------------------------------------------------------------------- /concepts/databases/assets/horizontal-partition.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/databases/assets/horizontal-partition.jpeg -------------------------------------------------------------------------------- /concepts/databases/assets/key-value-concepts.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/databases/assets/key-value-concepts.jpeg -------------------------------------------------------------------------------- /concepts/databases/assets/key-value.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /concepts/databases/assets/list-partitioning.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/databases/assets/list-partitioning.gif -------------------------------------------------------------------------------- /concepts/databases/assets/partition-problem.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/databases/assets/partition-problem.png -------------------------------------------------------------------------------- /concepts/databases/assets/partition-solution.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/databases/assets/partition-solution.gif -------------------------------------------------------------------------------- /concepts/databases/assets/partition.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/databases/assets/partition.jpeg -------------------------------------------------------------------------------- /concepts/databases/assets/vertical-partition.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/databases/assets/vertical-partition.jpeg -------------------------------------------------------------------------------- /concepts/databases/partition/README.md: -------------------------------------------------------------------------------- 1 | # Phân Vùng Cơ Sở Dữ Liệu 2 | 3 | ![](./assets/data-partitioning-system-design-concept-cover.jpeg) 4 | 5 | ## Phân vùng cơ sở dữ liệu là gì? 6 | 7 | Phân vùng cơ sở dữ liệu là xương sống trong việc quản lý các hệ thống cơ sở dữ liệu phân tán. Nó là quá trình phân chia một tập dữ liệu lớn thành các phần nhỏ hơn ở những máy khác nhau. Nói cách khác, nó là cách chia các dữ liệu dạng bảng thành các phần nhỏ hơn để dễ dàng truy cập và quản lý. 8 | 9 | - Dữ liệu được phân tán trên nhiều phân vùng sẽ cải thiện hiệu suất về độ khả dụng, khả năng mở rộng và quá trình truy vấn. Dữ liệu được gộp trên tất cả phân vùng sẽ giống với dữ liệu ban đầu của cơ sở dữ liệu. 10 | - Kiến trúc phân vùng này là vô hình ở phía client, họ sẽ không biết là mình đang giao tiếp với các phân vùng vì nó giống như đang giao tiếp với một cơ sở dữ liệu duy nhất. 11 | 12 | ![](./assets/what-is-data-partition.png) 13 | 14 | ## Phân vùng dữ liệu giải quyết được những vấn đề gì? 15 | 16 | Với sự phát triển của dịch vụ và nhu cầu người dùng, cái yêu cầu về cơ sở dữ liệu cũng tăng theo đó. Kiến trúc một server cơ sở dữ liệu di nhất là không đủ để phục vụ các yêu cầu từ client. Nó có thể dẫn đến một vài trường hợp phát sinh như sau: 17 | - Các thao tác trên cơ sở dữ liệu chậm. 18 | - Băng thông mạng bắt đầu tiến đến trạng thái đầy. 19 | - Server cơ sở dữ liệu có thể tràn ổ đĩa cùng thời điểm chạy. 20 | 21 | Phân vùng cơ sở dữ liệu giúp ta giải quyết tất cả những vấn đề trên bằng cách phân phối dữ liệu trên nhiều phân vùng. Mỗi phân vùng có thể chạy trên cùng một máy hoặc chạy ở máy khác. Ý tưởng phân vùng cùng máy có thể giúp giảm kích cơ chỉ mục, và dung lượng I/O cần cho cập nhật bản ghi. Tương tự ý tưởng phân vùng khác máy giúp tăng băng thông cho truy cập dữ liệu vì có nhiều RAM hơn, tránh việc truy cập ổ đĩa, hay có thể các interface mạng và kênh I/O khả dụng. 22 | 23 | Một góc nhìn phân vùng bảng. 24 | 25 | ![](./assets/view-of-partitioned-table.gif) 26 | 27 | ## Khi nào cần phân vùng bảng? 28 | 29 | Phân vùng trông có vẻ rất hữu ích, nhưng không phải tất cả trường hợp đều bắt buộc chúng ta phân vùng dữ liệu. Các kịch bản mà phân vùng dữ liệu hữu ích thường là: 30 | - Khi kích thước bảng quá lớn so với bộ nhớ. 31 | - Khi dữ liệu cần thêm vào hoặc cập nhật mỗi ngày. Ví dụ như một bảng lưu dữ liệu hành trình, chỉ có thể cập nhật ở tháng hiện tại, 11 tháng trước chỉ có thể đọc. 32 | - Khi bảng dữ liệu cần phân phối trên nhiều thiết bị lưu trữ. Tác vụ truy vấn sẽ trở nên dễ dàng hơn nếu dữ liệu được lưu trữ phân tán trên nhiều server. 33 | 34 | ## Tại sao cần phân vùng dữ liệu? 35 | 36 | - **Cải thiện độ khả dụng**: -------------------------------------------------------------------------------- /concepts/databases/sql-nosql/README_EN.md: -------------------------------------------------------------------------------- 1 | # SQL vs NoSQL 2 | 3 | Have you ever been in a dilemma while choosing the most appropriate storage type for your application? What could be the most viable storage type that could meet the business expectations and offers efficient services? If it is so, then this blog comes to rescue you. This blog will give you complete insight while designing your database to make your application work efficiently. 4 | 5 | Nowadays, most businesses have heavily relied on the processing and management of large amounts of data. The core decision behind choosing any type of database depends on the business logic of the application, the system’s critical functionalities, the structure of the system’s data, and requirements. The primary factor behind selecting the database is the data structure and the kind of operations associated with it. But before diving deep into selecting a suitable database, it is necessary to have a clear understanding of the structure and the functionalities of each kind of database. Databases are broadly categorized into Relational (SQL) and Non-Relational (NoSQL) databases. 6 | 7 | ## SQL Database 8 | 9 | SQL (Structured Query Language) is a programming language used for writing the relational database. SQL is a table-oriented database. The relational database mainly comprises tables, and each table consists of rows and columns. This database is highly structured in nature. Relational Databases have a predefined schema. A schema is a relationship between the tables and the field types. It is an essential tool that keeps the data in synchronization and minimizes data redundancy. Relational Databases come with ACID compliance. Hence such types of databases are highly preferable for transaction-oriented systems and for storing financial data. ACID compliance offers error-free services even in case of failures, which is necessary for the validity of transactions. Types of SQL Databases are: MySQL, Oracle, PostgreSQL, MariaDB, IBM DB2 10 | 11 | ## NoSQL 12 | 13 | NoSQL is a non-relational database system that is very flexible and highly scalable. NoSQL databases offer dynamic schemas and are most suitable for storing unstructured data like article content, video, social media posts, and various types of unstructured data. There are various types of NoSQL Databases like Key-Value Store, Document Oriented Database, Column Oriented Database, and Graph database. NoSQL databases are query inefficient. Due to the highly distributed and flexible nature, NoSQL databases are highly suited to modern frameworks like Hadoop and are suitable for Big data and real-time processing services. 14 | 15 | NoSQL database offers BASE compliance because of which NoSQL database offers high flexibility. NoSQL is highly suitable for storing hierarchical data and solving data availability problems. Types of NoSQL Databases are MongoDB, Redis, Neo4j, Cassandra, Hbase. 16 | 17 | ![](../assets/compare.png) 18 | 19 | ## Why use SQL Database? 20 | 21 | One should prefer SQL databases when: 22 | 1. Data is highly structured and requires fewer updates 23 | 2. Data Integrity is essential 24 | 3. Service requires a large number of complex queries 25 | 4. ACID compliance is very necessary 26 | 27 | ## Why use NoSQL Database? 28 | 29 | One should prefer SQL databases when: 30 | 1. The flexibility, scalability, and speed is the key requirement of the system 31 | 2. The size of data is huge, and data needs flexible schemas 32 | 3. ACID compliance is not necessary 33 | 4. The service requires distributed architecture and cloud computing 34 | 5. The system requires rapid development 35 | 36 | ## Scalability 37 | 38 | To handle the increasing amount of traffic efficiently, one needs to scale the system. Scalability improves the throughput of the system and offers minimum latency. However, SQL and NoSQL databases differ highly in the way they are scaled. Horizontal scaling means scaling by adding more machines to the system. Similarly, vertical scaling means increasing the capacity of the same machine so that it could handle a larger amount of traffic. 39 | 40 | SQL databases support vertical scaling while NoSQL databases support horizontal scaling. In SQL or relational databases, the data is present in a highly structured manner, and hence while scaling, one needs to maintain the structure of the data. Hence to maintain the service’s integrity, SQL databases are designed to run using a single server. In NoSQL databases, there is no need to maintain data structure; hence, such types of systems such be easily scaled using horizontal scaling as each entity is independent of the other. Hence to scale such a system, one can add more and more servers to increase the service’s power. 41 | 42 | ## Combining the best of two 43 | 44 | With the increase in the systems’ complexity, sometimes it becomes handy to use both types of databases for various tasks associated with the service. For example, YouTube stores the video content in NoSQL databases and stores user metadata and some other information in relational databases. Hence, to meet the business requirements, one can integrate both types of services and use them in conjunction with each other by taking each database’s best characteristics. 45 | 46 | Various databases offer both types of services like MySQL Document Store offers the structure of the SQL database and the features and flexibility of the NoSQL database. Similarly, MongoDB being a NoSQL database, also offers ACID transactions. 47 | 48 | ## Conclusion 49 | 50 | The choice of database is entirely dependent on the type of application and the type of services it offers. However, there is no such database that fits all conditions. There are various aspects of businesses that require relational or non-relational databases or sometimes a combination of both. There are applications in which data structure and integrity are necessary, and schemas are well defined. Hence relational databases are suitable for them, while some applications focus more on speed and scalability; hence NoSQL databases are suitable for them. Hence, with newer technologies, real-time processing, and highly distributed systems, NoSQL databases are gaining popularity. But the final call for choosing the type of storage is application dependent. One needs to know all the edge cases while going with any particular type of architectural design. -------------------------------------------------------------------------------- /concepts/distributed-system/assets/distributed-systems.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/distributed-system/assets/distributed-systems.jpg -------------------------------------------------------------------------------- /concepts/distributed-system/assets/example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/distributed-system/assets/example.png -------------------------------------------------------------------------------- /concepts/distributed-system/assets/graph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/distributed-system/assets/graph.png -------------------------------------------------------------------------------- /concepts/distributed-system/assets/leader-election-in-distributed-systems.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /concepts/latency/assets/latency.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /concepts/load-balancers/README_EN.md: -------------------------------------------------------------------------------- 1 | # Load Balancer 2 | 3 | ![](./assets/load-balancers.svg) 4 | 5 | Load balancing is essential for building high-performance and scalable applications in system design. It is also a popular topic for system design tech interviews. 6 | 7 | ## What is a load balancer? 8 | 9 | A load balancer is a software or a hardware device that sits between clients and a set of servers and balances workload across resources. It saves our servers from overloading and increases the throughput of the system. 10 | 11 | ## Why do we require a load balancer? 12 | 13 | We use various web services in real life, which quickly respond to our requests. But most of us are unaware of the background process and scale of the system responsible for providing the fast response. This involves the allocation of requests across several servers when thousands of users request the service simultaneously. 14 | 15 | On the other side, the load on servers keeps increasing with the traffic growth, and the website gets slower to serve the user request. To deliver a fast and reliable response, one idea would be to increase the number of servers. But this situation brings a new challenge: how to distribute the requests across several servers? We can solve this problem using the idea of a load balancer! 16 | 17 | **Let's understand it from another perspective!** 18 | 19 | Suppose we have several clients sending requests to a single server. When the number of requests increases significantly, the server experiences an overload, leading to failure in the system. 20 | 21 | ![](./assets/problems.png) 22 | 23 | There will be two critical issues: 24 | - **Server overloading**: There is always a limitation on a server to handle requests. After growth in the number of requests, the server may get overloaded. 25 | - **Single point of failure**: If the single server goes down, the whole application will be unavailable for the users for a certain period of time. It will create a bad user experience. 26 | 27 | **So, how do we handle the above problem?** 28 | 29 | We can try to scale our system. The first way is to vertically scale our system or increase the power of our server. But, there's only so much that we can do about it to increase a single machine's power. 30 | 31 | Another way is to scale the system horizontally by adding more servers to our system. Now for handling the request, we can add a load balancer and distribute the request across multiple servers. This could allow our services to handle a large number of requests by adding more servers. 32 | 33 | ![](./assets/approach.png) 34 | 35 | Even if one of the servers goes offline due to some reason, the service will be available. It continuously checks the health of backend resources and prevents sending traffic to servers that cannot fulfill requests. 36 | 37 | ## Where do we add a load balancer? 38 | 39 | We can add load balancers at various places in the system, especially with multiple resources like servers, databases, or caches. 40 | - Between the client and the server 41 | - Between the server and application servers 42 | - Between the application and cache servers 43 | - Between the cache and database servers 44 | 45 | ## What are the types of load balancers? 46 | 47 | There can be two types of load balancers: **software load balancer** and **hardware load balancer**. The main difference between them is that we can do more with a software load balancer. We have more power for customization and scaling with software load balancers. With hardware load balancers, we are limited to the hardware we are given. 48 | 49 | ### Pros and cons of software load balancers 50 | 51 | * Flexible in adjusting to changing needs 52 | * Able to scale beyond initial capacity by adding more software instances. 53 | * Lower cost than purchasing and maintaining physical hardware. The software can run on any standard device, which tends to be cheaper. 54 | * It can allow cloud-based load balancing. 55 | * There can be some delay when scaling beyond initial capacity while configuring load balancer software. 56 | * There will be some extra costs for ongoing upgrades. 57 | 58 | ### Examples of software load balancers 59 | 60 | - HAProxy: A TCP load balancer. 61 | - NGINX: An HTTP load balancer with SSL termination support. 62 | - mod_athena: Apache-based HTTP load balancer. 63 | - Varnish: A reverse proxy-based load balancer. 64 | - Balance: Open-source TCP load balancer. 65 | - LVS: Linux virtual server offering layer 4 load balancing. 66 | 67 | ### Pros and cons of hardware load balancers 68 | 69 | * Provide fast throughput due to software running on specialized processors. 70 | * Increase security because only the organization can access the servers physically. 71 | * Need more human resources and expertise to configure and manage the machines. 72 | * It fails to scale when the number of requests exceeds a specific limit. 73 | * It requires a higher cost for purchase and maintenance. 74 | 75 | ### Examples of hardware load balancers 76 | 77 | - F5 BIG-IP load balancer 78 | - CISCO system catalyst 79 | - Barracuda load balancer 80 | - Coytepoint load balancer 81 | - Citrix NetScaler 82 | 83 | ## Advantages of load balancing 84 | 85 | - We use a load balancer for better user experience and uninterrupted service by distributing the client requests to an available and responsive server. In other words, it ensures the availability and scalability of the application. 86 | - It prevents server overload and a single point of failure. In other words, it ensures that no single server bears too many requests that degrade the application's overall performance. 87 | - It can also offer functionalities like encryption, authentication, etc. to provide a single control point for securing, managing, and monitoring the application. It can provide efficient protection from the DoS attack. 88 | - The end-user only needs to know the address of the load balancer, not the address of every server in the cluster. So it also provides a layer of Abstraction. 89 | - We can roll out software updates without taking the whole service down by using the load balancer to take out one server at a time. 90 | - It minimizes server response time and maximizes throughput. 91 | - It can do health checks and monitor the request handling capability of servers. 92 | - Based on the number of requests, it can add or remove the number of servers. 93 | 94 | ## Critical concepts to explore further 95 | 96 | - What is the difference between Load Balancer and Reverse Proxy? 97 | - Different Categories of Load Balancing: 98 | 1. Layer 4 (L4) load balancer 99 | 2. Layer 7 (L7) load balancer 100 | 3. Global server load balancing (GSLB) 101 | - Health check feature of the load balancer. 102 | - DNS load balancing vs Hardware load balancing 103 | - The application load balancer in designing several systems 104 | - Cloud load balancing 105 | 106 | -------------------------------------------------------------------------------- /concepts/load-balancers/assets/algorithms.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /concepts/load-balancers/assets/approach.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/load-balancers/assets/approach.png -------------------------------------------------------------------------------- /concepts/load-balancers/assets/problems.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/load-balancers/assets/problems.png -------------------------------------------------------------------------------- /concepts/load-balancers/src/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /concepts/load-balancers/src/app.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const app1 = express(); 3 | const app2 = express(); 4 | 5 | // Handler method 6 | const handler = num => (req,res)=>{ 7 | const { method, url, headers, body } = req; 8 | res.send('Response from server ' + num); 9 | } 10 | 11 | // Only handle GET and POST requests 12 | // Receive request and pass to handler method 13 | app1.get('*', handler(1)).post('*', handler(1)); 14 | app2.get('*', handler(2)).post('*', handler(2)); 15 | 16 | // Start server on PORT 3000 17 | app1.listen(3000, err =>{ 18 | err ? 19 | console.log("Failed to listen on PORT 3000"): 20 | console.log("Application Server listening on PORT 3000"); 21 | }); 22 | 23 | // Start server on PORT 3001 24 | app2.listen(3001, err =>{ 25 | err ? 26 | console.log("Failed to listen on PORT 3001"): 27 | console.log("Application Server listening on PORT 3001"); 28 | }); -------------------------------------------------------------------------------- /concepts/load-balancers/src/config.js: -------------------------------------------------------------------------------- 1 | const express = require('express'); 2 | const path = require('path'); 3 | const app = express(); 4 | const axios = require('axios'); 5 | 6 | // Application servers 7 | const servers = [ 8 | "http://localhost:3000", 9 | "http://localhost:3001" 10 | ] 11 | 12 | // Track the current application server to send request 13 | let current = 0; 14 | 15 | // Receive new request 16 | // Forward to application server 17 | const handler = async (req, res) =>{ 18 | 19 | // Destructure following properties from request object 20 | const { method, url, headers, body } = req; 21 | 22 | // Select the current server to forward the request 23 | const server = servers[current]; 24 | 25 | // Update track to select next server 26 | current === (servers.length-1)? current = 0 : current++ 27 | 28 | try{ 29 | // Requesting to underlying application server 30 | const response = await axios({ 31 | url: `${server}${url}`, 32 | method: method, 33 | headers: headers, 34 | data: body 35 | }); 36 | // Send back the response data 37 | // from application server to client 38 | res.send(response.data) 39 | } 40 | catch(err){ 41 | // Send back the error message 42 | res.status(500).send("Server error!") 43 | } 44 | } 45 | 46 | // Serve favicon.ico image 47 | app.get('/favicon.ico', (req, res 48 | ) => res.sendFile('/favicon.ico')); 49 | 50 | // When receive new request 51 | // Pass it to handler method 52 | app.use((req,res)=>{handler(req, res)}); 53 | 54 | // Listen on PORT 8080 55 | app.listen(8080, err =>{ 56 | err ? 57 | console.log("Failed to listen on PORT 8080"): 58 | console.log("Load Balancer Server " 59 | + "listening on PORT 8080"); 60 | }); -------------------------------------------------------------------------------- /concepts/load-balancers/src/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "src", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "concurrently \"node config.js\" \"node app.js\"", 8 | "test": "echo \"Error: no test specified\" && exit 1" 9 | }, 10 | "keywords": [], 11 | "author": "", 12 | "license": "ISC", 13 | "dependencies": { 14 | "axios": "^0.27.2", 15 | "concurrently": "^7.2.1", 16 | "crypto": "^1.0.1", 17 | "express": "^4.18.1" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /concepts/load-balancers/types-of-load-balancing-algorithms/README_EN.md: -------------------------------------------------------------------------------- 1 | # Types of Load Balancing Algorithms 2 | 3 | ![](../assets/algorithms.svg) 4 | 5 | **Load Balancer** can receive and distribute requests to a particular server based on various load balancing techniques which use different load balancing algorithms to select servers based on a specific configuration. Load balancing algorithms are categorized into two parts: 6 | - **Static algorithms**: It works in the same way regardless of the state of the backend serving the requests. It is simpler and more efficient to implement but can lead to uneven distribution of requests. Some examples of static load balancing algorithms are **Round robin, Weighted Round Robin, Source IP Hash, URL Hash, Randomized algorithm, etc.** 7 | - **Dynamic algorithms**: It takes into account the state of the backend and considers server load when distributing requests. It requires communication between the load balancers and servers. So it would be a little complex but can distribute requests efficiently. Some examples of dynamic load balancing algorithms are the **Least connection method, Weighted least connections method, Least response time method, etc.** 8 | 9 | ## Round Robin Load Balancing 10 | 11 | Round robin is one of the simplest load balancing algorithms, ensuring client requests to a different server based on a rotating list. Here load balancer maintains the list of available servers and directs the incoming request in a round-robin fashion: 1st request to the 1st server, 2nd request to the 2nd server, so on. When the load balancer reaches the end of the list, it goes to the list's beginning and starts from the first server again. 12 | - Easy to implement. 13 | - Evenly balances the traffic between the servers. 14 | - Doesn't consider the server's load and specifications. So there is a risk that a server with low capacity receives many requests and becomes overloaded. 15 | - Works best if every server in the load balancer list has roughly the exact specification. 16 | - Otherwise, a low processing server may have the same load as a high processing serve 17 | 18 | ## Weighted Round Robin Balancing 19 | 20 | The weighted round-robin load-balancing algorithm is an advanced version of the simple round-robin algorithm. It distributes the incoming request based on the weighted score of the servers. Here weight can be an integer that can vary according to the server's processing power or specification. So, It considers server specifications and distributes the traffic based on that. 21 | - Little complex compared to a simple round-robin algorithm but works well with servers with different specifications. 22 | - The current load of each server and the relative computation cost of each request are not considered. 23 | - Based on the weighted score, some of the servers may get many requests of the overall request count. 24 | 25 | ## Random Load Balancing 26 | 27 | This algorithm randomly maps requests to the server using some random number generator. Whenever a load balancer receives requests, a randomized algorithm distributes the requests evenly to the servers. So like Round Robin, this algorithm also works well for the group of servers with similar configurations. 28 | 29 | ## Source IP Hash Load Balancing 30 | 31 | Here server is selected based on a unique hash key. It combines the source and destination IP address to generate a unique hash key and allocate the request to a particular server. The key can be regenerated if the session is broken and the client request is directed to the same server it was using previously. In other words, this is useful when a dropped connection needs to be returned to the same server initially handling it. 32 | 33 | ## URL Hash Load Balancing 34 | 35 | Load balancer generates the hash value based on the URL present in requests coming from the clients. Based on hash value, requests will be forwarded to servers. The load balancer caches the hashed value of the URL, and subsequent requests that use the same URL make a cache hit and are forwarded to the same server. 36 | - It improves the capacity of backend caches by avoiding cache duplication. 37 | - This method is used when load-balanced servers serve mostly unique content per server. So, basically, what this means is that all requests related to one process will go to one server, say “running code,” and all requests related to another process, say “payments,” will go to another server, and so on… 38 | 39 | ## Least Connection Method 40 | 41 | This algorithm considers the current load on a server and delivers better performance. Here load balancer sends requests to the server with the least number of active connections. 42 | - The load balancer does additional calculations to figure out the server with the least number of connections. 43 | - This algorithm is useful when there are many persistent connections in the traffic unevenly distributed between the servers. If the servers are busy in long computations, the connections between client and server stay alive for a long period of time. 44 | 45 | ## Weighted Least Connections Method 46 | 47 | In weighted least connections, the load distribution is based on both the factors – the number of current and active connections to each server and the relative capacity of the server. 48 | - Some servers can handle more connections than others 49 | - Servers are rated based on their processing capabilities. 50 | 51 | ## Least Response Time Method 52 | 53 | This algorithm is a little advanced form of the least connection method, where a request is forwarded to the server with the fewest active connections and the least average response time. 54 | - It relies on the time taken by a server to respond to a health monitoring request. 55 | - The speed of the response is an indicator of how loaded the server is. 56 | - Also, consider the number of active connections on each server. 57 | - The backend server that responds the fastest receives the subsequent request. 58 | 59 | **Note**: The interesting thing about all this is that it might make sense to have multiple load balancers that use different server selection strategies in a system. 60 | -------------------------------------------------------------------------------- /concepts/network-protocols/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/network-protocols/README.md -------------------------------------------------------------------------------- /concepts/network-protocols/assets/advanced.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/network-protocols/assets/advanced.png -------------------------------------------------------------------------------- /concepts/network-protocols/assets/client-server.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/network-protocols/assets/client-server.png -------------------------------------------------------------------------------- /concepts/network-protocols/assets/compare.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/network-protocols/assets/compare.png -------------------------------------------------------------------------------- /concepts/network-protocols/assets/ip-address.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/network-protocols/assets/ip-address.png -------------------------------------------------------------------------------- /concepts/network-protocols/assets/ip-package-transfer.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/network-protocols/assets/ip-package-transfer.gif -------------------------------------------------------------------------------- /concepts/network-protocols/assets/network-architecture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/network-protocols/assets/network-architecture.png -------------------------------------------------------------------------------- /concepts/network-protocols/assets/network-protocols.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /concepts/network-protocols/assets/osi-model.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/network-protocols/assets/osi-model.png -------------------------------------------------------------------------------- /concepts/network-protocols/assets/tcp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/network-protocols/assets/tcp.png -------------------------------------------------------------------------------- /concepts/others/long-polling/README.md: -------------------------------------------------------------------------------- 1 | # Long polling trong thiết kế hệ thống 2 | 3 | Bất kỳ khi nào chúng ta xây dựng bất kỳ ứng dụng Web xử lý dữ liệu thời gian thực nào, chúng ta cần xem xét việc cung cấp dữ liệu cho khách hàng. Khi xây dựng một loại ứng dụng Web như vậy, người ta cần xem xét cơ chế phân phối tốt nhất, đúng không! Trong bài viết này, chúng ta sẽ tập trung vào tính năng Long polling và sẽ cung cấp cho bạn cái nhìn sâu về các hoạt động nội bộ và các tính năng cơ bản của nó. 4 | 5 | ## Long Polling là gì? 6 | 7 | Trước tiên, chúng ta hãy xem polling là gì và mở rộng của nó như thế nào đối với long polling. Polling là một kỹ thuật cho phép server đẩy thông tin đến client. Long polling là một phiên bản của polling truyền thống cho phép server gửi dữ liệu đến client bất cứ khi nào có sẵn. Nó liên quan đến việc phía client yêu cầu thông tin từ server giống như cách mà polling tiêu chuẩn thực hiện, nhưng với cảnh báo rằng server có thể không phản hồi ngay lập tức. Câu trả lời đầy đủ sẽ được gửi đến client sau khi dữ liệu có thể truy cập được. 8 | 9 | Long polling làm giảm số lượng yêu cầu HTTP cần thiết để gửi cùng một lượng thông tin cho client. Tuy nhiên, server phải “giữ” các yêu cầu của client chưa được thực hiện và xử lý tình huống trong đó nó nhận được thông tin mới để cung cấp, nhưng client vẫn chưa đưa ra yêu cầu mới. Long polling có lợi thế là một phần của giao thức HTTP, có nghĩa là nó được chấp nhận rộng rãi và tạo ra ít băng thông hơn so với short polling vì nó yêu cầu ít truy vấn hơn. Nhìn chung, đây là một phương pháp đáng tin cậy để liên tục cập nhật thông tin mới cho client một cách đơn giản. 10 | 11 | Sau đây là vòng đời cơ bản của một ứng dụng sử dụng HTTP Long-Polling: 12 | 1. Client gửi một yêu cầu HTTP và sau đó chờ phản hồi. 13 | 2. Khi có bản cập nhật, server cung cấp cho client một phản hồi hoàn chỉnh. 14 | 3. Sau khi nhận được phản hồi, client thường gửi một yêu cầu long-poll mới, ngay lập tức hoặc sau khi tạm dừng, để cho phép một khoảng thời gian chờ thích hợp. 15 | 4. Thời gian chờ được đặt cho mỗi yêu cầu long-poll. Sau khi kết nối bị mất do hết thời gian chờ, client phải thường xuyên kết nối lại. 16 | 17 | ## Long polling hoạt động như thế nào? 18 | 19 | Long polling là một phiên bản hiệu quả hơn của phương pháp polling cơ bản. Các yêu cầu lặp đi lặp lại đến server sẽ lãng phí tài nguyên vì mỗi kết nối mới đến yêu cầu thiết lập một kết nối mới, phân tích tiêu đề HTTP, truy vấn dữ liệu mới, tạo và phân phối phản hồi. Sau đó, kết nối phải được kết thúc và mọi tài nguyên phải được dọn dẹp. Long polling là một chiến lược trong đó server chọn để giữ kết nối của client mở trong thời gian khả thi, chỉ phản hồi khi dữ liệu có sẵn hoặc đạt đến ngưỡng thời gian chờ, thay vì phải lặp lại quy trình cho từng client cho đến khi có dữ liệu mới. 20 | 21 | Trong long polling, phần lớn côn việc được thực hiện trên server. Chỉ một yêu cầu đến server là cần được quản lý ở phía client, khi client nhận được phản hồi. Họ có thể đưa ra yêu cầu mới, lặp lại quy trình nếu cần. Sự khác biệt giữa polling cơ bản và polling thiết yếu từ góc nhìn của client là nếu client thực hiện polling cơ bản, nó có thể cố ý để lại một khoảng thời gian nhỏ giữa mỗi yêu cầu để giảmm tải server. Nó có thể phản hồi với thời gian chờ khác với server không hỗ trợ long polling. 22 | 23 | Ví dụ: với long polling, client có thể được cấu hình để cho phép khoảng thời gian chờ lâu hơn khi lắng nghe phản hồi, điều này thường được tránh vì khoảng thời gian chờ được sử dụng để xác định các vấn đề giao tiếp với server. 24 | 25 | Ngoài những cân nhắc này, client không cần phải thực hiện nhiều điều khác mà chưa được đề cập trong polling ​​cơ bản. Mặt khác, server phải xử lý trạng thái của một số kết nối chưa được giải quyết. Khi một số server và bộ cân bằng tải được sử dụng, có thể cần tạo các giải pháp để duy trì trạng thái phiên. Nó cũng phải xử lý khéo léo các khó khăn về thời gian chờ kết nối, thường gặp hơn nhiều đối với các giao thức purpose-built. 26 | 27 | ## Những lưu ý khi sử dụng tính năng long polling 28 | 29 | Nếu polling ​​chỉ là một ứng biến được áp dụng cho một cơ chế phản hồi yêu cầu cơ bản, thì nó sẽ đi kèm với một mức độ phức tạp bổ sung trong việc triển khai. Do đó, có nhiều mối quan tâm khác nhau mà bạn cần giải quyết khi sử dụng HTTP long polling để xây dựng tính tương tác theo thời gian thực trong ứng dụng của bạn, cả phát triển và mở rộng. 30 | - Khi việc sử dụng ngày càng tăng, bạn sẽ sắp xếp chương trình backend thời gian thực của mình như thế nào? 31 | - Long polling có tự động thiết lập lại kết nối khi thiết bị di động chuyển đổi nhanh chóng giữa WiFi và mạng di động hoặc mất kết nối và địa chỉ IP thay đổi không? 32 | - Với long polling, bạn có thể quản lý hàng đợi tin nhắn và bắt kịp các tin nhắn bị bỏ lỡ không? 33 | - Long polling có cung cấp hỗ trợ cân bằng tải hoặc chuyển đổi dự phòng trên nhiều server không? 34 | 35 | ## Các thách thức với long polling 36 | 37 | 1. Sắp xếp và phân phối tin nhắn. 38 | 2. Khi kết nối mạng bị mất và client không khả dụng để nhận được nó. 39 | 3. Nếu client cùng lúc thiết lập kết nối đến nhiều server, thứ tự tin nhắn có thể không được đảm bảo. 40 | 4. Hiệu suất và mở rộng. 41 | 5. Thiết bị hỗ trợ và dự trữ 42 | 43 | ## Kết luận 44 | 45 | Long polling giúp cung cấp thông tin cập nhật thường xuyên. Nó liên quan đến việc client yêu cầu thông tin từ server theo như cách mà việc polling thông thường thực hiện nhưng hiểu rằng server có thể không phản hồi ngay lập tức. Thay vì trả về một phản hồi trống nếu server không có thông tin mới, server giữ yêu cầu mở và đợi thông tin phản hồi có sẵn. Server cung cấp phản hồi HTTP/S cho client ngay khi nhận được thông tin mới, hoàn thành yêu cầu HTTP/S đang mở. Client thường đưa ra một yêu cầu khác sau khi nhận được phản hồi từ server. 46 | 47 | Bằng cách này, độ trễ phản hồi thông thường liên quan đến ứng dụng do client polling sẽ bị loại bỏ, vì thế nó được sử dụng nhiều trong các ứng dụng khác nhau. -------------------------------------------------------------------------------- /concepts/others/long-polling/README_EN.md: -------------------------------------------------------------------------------- 1 | # Long Polling in System Design 2 | 3 | Whenever we build any Web Application dealing with real-time data, we need to consider delivering data to the Client. While building such a Web Application type, one needs to consider the best delivery mechanism, right! In this blog, we are focusing on long Polling, and here, we will give you a complete insight into its internal working and the underlying features. So Let’s dive in and get started :) 4 | 5 | ## What is Long Polling? 6 | 7 | Let’s first look at what polling is and how it extends to Long polling. Polling is a technique that allows the servers to push information to a client. Long polling is a version of traditional polling that allows the server to send data to a client whenever available. It involves the Client requesting information from the server in the same way that standard polling does, but with the caveat that the server may not respond right away. A complete answer is delivered to the Client once the data is accessible. 8 | 9 | Long polling reduces the number of HTTP requests required to send the same amount of information to the Client. However, the server must “hold” unfulfilled client requests and deal with the situation in which it receives new information to deliver, but the Client has not yet issued a new request. Long polling has the advantage of being part of the HTTP protocol, which means it’s widely accepted, and it generates less bandwidth than short polling because it requires fewer queries. Overall, it is a reliable method for continuously updating clients with new information straightforwardly. 10 | 11 | The following is the basic life cycle of an application that uses HTTP Long-Polling: 12 | 1. The Client sends an HTTP request and then waits for a response. 13 | 2. When an update is available, the server provides the Client a complete response. 14 | 3. After getting a response, the Client typically sends a new long-poll request, either immediately or after a pause, to allow for an appropriate latency duration. 15 | 4. A timeout is set for each Long-Poll request. After a connection is lost owing to timeouts, the Client must rejoin regularly. 16 | 17 | ## How does long polling work? 18 | 19 | Long polling is a more efficient version of the basic polling method. Repeated requests to the server waste resources since each new incoming connection requires establishing a new connection, the parsing of HTTP headers, a new data query, and the generation and delivery of a response. After that, the connection must be ended, and any resources must be cleaned up. Long polling is a strategy in which the server chooses to keep a client’s connection open for as long as feasible, only responding when data becomes available or a timeout threshold is reached, rather than having to repeat the procedure for each client until new data becomes available. 20 | 21 | In Long polling, the majority of the work is done on the server. Only one request to the server needs to be managed on the client-side. When the Client receives the response, he or she can make a new request, repeating the process as needed. The only difference between basic polling and essential polling from the Client’s perspective is that a client performing basic polling may intentionally leave a small time window between each request to reduce server load. It may respond to timeouts differently than a server that does not support long polling. 22 | 23 | For example, with long polling, the Client may be configured to allow for a longer timeout duration when listening for a response, which is typically avoided because the timeout period is used to identify communication issues with the server. 24 | 25 | Apart from these considerations, there isn’t much else a client needs to accomplish that isn’t already covered by basic polling. The server, on the other hand, must handle the state of several unresolved connections. When several servers and load balancers are employed, it may be necessary to create solutions for preserving the session state. It must also gracefully handle connection timeout difficulties, which are far more common than with purpose-built protocols. 26 | 27 | ## Considerations when using long-polling 28 | 29 | As long polling is just an improvisation applied to an underlying request-response mechanism, it comes with an additional degree of complexity in its implementation. As a result, there are various concerns you’ll need to account for when using HTTP long polling to build real-time interactivity in your application, both developing and scaling. 30 | - As usage grows, how will you orchestrate your real-time backend? 31 | - Does long polling automatically re-establish connections when mobile devices rapidly switch between WiFi and cellular networks or lose connections and the IP address changes? 32 | - With long polling, can you manage the message queue and catch up on missed messages? 33 | - Does long polling provide load balancing or failover support across multiple servers? 34 | 35 | When building a real-time application with HTTP long polling for server push, you’ll have to develop your communication management system. This means that you’ll be responsible for updating, maintaining, and scaling your backend infrastructure. 36 | 37 | ## Challenges in long polling 38 | 39 | 1. Message ordering and delivery 40 | 2. There is a chance that the communication will be lost if the Client was unable to receive it. 41 | 3. If the same Client establishes several connections to the server, message ordering cannot be guaranteed. 42 | 4. Performance and scaling 43 | 5. Device support and fallbacks. 44 | 45 | ## Conclusion 46 | 47 | Long polling helps provide frequent updates. It involves the Client requesting information from the server in the same way that regular polling does but understanding that the server may not respond immediately. Instead of returning an empty response if the server has no new information for the Client when the poll is received, the server keeps the request open and waits for response information to become available. The server provides an HTTP/S response to the Client as soon as it receives new information, completing the open HTTP/S request. The Client frequently issues another server request after receiving the response from the server. 48 | 49 | In this way, the usual response latency associated with polling clients is eliminated and as a result, it is heavily used in various applications. Hence, in this blog, a very generic understanding of long Polling is presented. I hope you liked it. 50 | 51 | -------------------------------------------------------------------------------- /concepts/others/long-polling/assets/long-polling-cover.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /concepts/others/mapreduce/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/others/mapreduce/README.md -------------------------------------------------------------------------------- /concepts/others/mapreduce/assets/dataflow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/others/mapreduce/assets/dataflow.png -------------------------------------------------------------------------------- /concepts/others/mapreduce/assets/phase.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/others/mapreduce/assets/phase.png -------------------------------------------------------------------------------- /concepts/others/polling-sse-websocket/assets/high-level-comparsing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/others/polling-sse-websocket/assets/high-level-comparsing.png -------------------------------------------------------------------------------- /concepts/others/polling-sse-websocket/assets/osi-model.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/others/polling-sse-websocket/assets/osi-model.png -------------------------------------------------------------------------------- /concepts/others/polling-sse-websocket/assets/sse-browsers.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/others/polling-sse-websocket/assets/sse-browsers.png -------------------------------------------------------------------------------- /concepts/others/polling-sse-websocket/assets/websocket-data.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/others/polling-sse-websocket/assets/websocket-data.png -------------------------------------------------------------------------------- /concepts/others/process-in-os/assets/execution.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/others/process-in-os/assets/execution.jpeg -------------------------------------------------------------------------------- /concepts/others/process-in-os/assets/medium-term.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/others/process-in-os/assets/medium-term.jpeg -------------------------------------------------------------------------------- /concepts/others/process-in-os/assets/memory.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/others/process-in-os/assets/memory.jpeg -------------------------------------------------------------------------------- /concepts/others/process-in-os/assets/pcb.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/others/process-in-os/assets/pcb.jpeg -------------------------------------------------------------------------------- /concepts/others/process-in-os/assets/process.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /concepts/others/process-in-os/assets/schedulers.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/others/process-in-os/assets/schedulers.jpeg -------------------------------------------------------------------------------- /concepts/others/process-in-os/assets/states.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/others/process-in-os/assets/states.jpeg -------------------------------------------------------------------------------- /concepts/others/pubsub-pattern/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/others/pubsub-pattern/README.md -------------------------------------------------------------------------------- /concepts/others/pubsub-pattern/assets/example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/others/pubsub-pattern/assets/example.png -------------------------------------------------------------------------------- /concepts/others/pubsub-pattern/assets/work-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/others/pubsub-pattern/assets/work-2.png -------------------------------------------------------------------------------- /concepts/others/pubsub-pattern/assets/work-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/others/pubsub-pattern/assets/work-3.png -------------------------------------------------------------------------------- /concepts/others/pubsub-pattern/assets/work.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/others/pubsub-pattern/assets/work.png -------------------------------------------------------------------------------- /concepts/others/redundancy/README.md: -------------------------------------------------------------------------------- 1 | # Bộ nhớ và Dự phòng 2 | 3 | Thiết bị lưu trữ là một phần cứng được sử dụng chủ yếu để lưu trữ dữ liệu. Lưu trữ là một cơ chế cho phép, tạm thời hoặc vĩnh viễn, máy tính bảo quản dữ liệu. Thành phần cơ bản của hầu hết các thiết bị kỹ thuật số là các thiết bị lưu trữ như ổ đĩa flash và ổ cứng. Chúng cho phép người dùng lưu trữ tất cả các loại thông tin, chẳng hạn như video, tài liệu, ảnh và dữ liệu thô. 4 | 5 | ** Tính bền bỉ **: Tính bền bỉ đề cập đến các đặc điểm của thực thể và quá trình tiếp tục tồn tại ngay cả sau khi quá trình tạo ra nó chấm dứt hoặc bị tắt bởi máy tính mà nó đang hoạt động. Khi một đối tượng hoặc trạng thái được tạo và cần phải được duy trì, nó sẽ được lưu ở vị trí lưu trữ không thay đổi, như ổ cứng, so với tệp tạm thời hoặc bộ nhớ truy cập ngẫu nhiên dễ bay hơi (RAM). 6 | 7 | ## Các loại kho lưu trữ 8 | 9 | Bộ nhớ là một trong những thành phần cốt lõi của hệ thống máy tính và có thể được phân loại thành 10 | nhiều loại, nhưng có hai loại chính: 11 | 12 | ### Bộ nhớ dễ bay hơi (Bộ nhớ) 13 | 14 | Cần cung cấp điện liên tục để lưu trữ / lưu giữ dữ liệu. Nó đóng vai trò là nơi lưu trữ chính của thiết bị để tạm thời lưu trữ dữ liệu và quản lý khối lượng công việc của các ứng dụng. Bộ nhớ đệm và bộ nhớ truy cập ngẫu nhiên là những ví dụ về bộ nhớ không linh hoạt (RAM). 15 | 16 | ### Không lưu trữ dễ bay hơi 17 | 18 | Một loại thiết bị lưu trữ lưu giữ dữ liệu kỹ thuật số ngay cả khi nó đã tắt hoặc nguồn điện không được cung cấp. Đây thường được coi là thiết bị lưu trữ thứ cấp và được sử dụng cho các hoạt động I / O liên quan đến việc lưu trữ dữ liệu vĩnh viễn. Đĩa cứng, bộ lưu trữ USB và phương tiện quang học là những ví dụ về lưu trữ dễ bay hơi. 19 | 20 | ## Dư 21 | 22 | Dự phòng là một khái niệm ngụ ý việc sao chép các thành phần hoặc chức năng thiết yếu của hệ thống để tăng độ tin cậy của hệ thống, thường ở dạng dự phòng hoặc dự phòng an toàn hoặc để nâng cao hiệu suất thực tế của hệ thống. Thuật ngữ dự phòng được sử dụng bởi vì nếu mọi thứ hoạt động bình thường, thiết bị trùng lặp hoặc thiết bị có thẩm quyền sẽ không làm gì cả và là dự phòng. 23 | 24 | Dự phòng phát huy tác dụng khi chúng ta cần ngăn chặn một điểm lỗi duy nhất (Một điểm lỗi duy nhất trong hệ thống là điểm có thể dẫn đến sự cố của hệ thống). Để loại bỏ bất kỳ điểm lỗi nào, chúng ta cần làm cho hệ thống của mình dư thừa hơn. Dự phòng là hành động sao chép hoặc thêm một số phần nhất định trong hệ thống của chúng tôi. Hãy lấy một ví dụ; Hãy tưởng tượng bạn có một hệ thống bao gồm hai máy chủ web dự phòng, giống hệt nhau được cài đặt sau bộ cân bằng tải. Lưu lượng đến từ các máy khách sẽ được phân phối giữa các máy chủ web, nhưng nếu một trong các máy chủ gặp sự cố, bộ cân bằng tải sẽ chuyển hướng tất cả lưu lượng đến máy chủ còn lại đang hoạt động. 25 | 26 | ** Dự phòng thụ động: ** Khi bạn có nhiều thành phần tại một lớp nhất định trong hệ thống của mình và nếu tại bất kỳ thời điểm nào, một trong số chúng chết, các máy chủ còn lại sẽ tiếp quản và ngăn chặn bất kỳ lỗi nào. 27 | 28 | ** Dự phòng hoạt động: ** Khi bạn có nhiều máy hoạt động cùng nhau, chỉ một hoặc một số máy thường xử lý lưu lượng truy cập hoặc thực hiện công việc. Nếu một trong số chúng bị lỗi, các máy khác sẽ biết bằng cách nào đó và sau đó tiếp quản. 29 | 30 | ## Dự phòng so với Nhân rộng 31 | 32 | Hai từ thoạt nhìn khá giống nhau, nhưng có một sự khác biệt đáng kể giữa chúng. Mỗi người trong số họ có một cái gì đó để làm với nhiều nút / thành phần / quy trình hơn trong một hệ thống và là một phần chung của hai khái niệm. 33 | + ** Dự phòng ** - Nó giải thích rằng bạn có nhiều hơn một nút / thành phần / quy trình trong hệ thống và nó khá có lợi trong việc quản lý chuyển đổi dự phòng. Một nút khác trong hệ thống sẽ tiếp quản và tiếp tục nếu một trong các nút bị lỗi. Dự phòng có thể là: 34 | - hoạt động: tất cả lưu lượng truy cập đến tất cả các nút cùng một lúc. 35 | - bị động: nơi một nút nhận được lưu lượng truy cập và trong trường hợp không thành công, một nút chuyển sẽ được thực hiện sang nút khác 36 | + ** Replication ** - Dự phòng được bao gồm, nhưng nó liên quan đến việc sao chép dữ liệu từ nút này sang nút khác hoặc đồng bộ hóa trạng thái giữa các nút. Một ví dụ về nơi thực hiện sao chép là ở cấp cơ sở dữ liệu. Nhân rộng có thể là: 37 | - ** hoạt động **: mỗi nút nhận từng thông báo để giữ đồng bộ với phần còn lại của các nút. 38 | - ** passive **: đây là mô hình master-slave, nơi chủ nhận tất cả các yêu cầu và sau đó chuyển tiếp chúng đến các nô lệ. 39 | 40 | Tóm lại, “Sao chép là sự đồng bộ hóa trạng thái giữa các nút dự phòng” trong khi “Dự phòng là sự sao chép của các nút, trong trường hợp một số nút bị lỗi.” 41 | 42 | > “Nhân rộng đảm bảo Tính nhất quán trong khi Dự phòng tăng độ tin cậy.” 43 | -------------------------------------------------------------------------------- /concepts/others/redundancy/README_EN.md: -------------------------------------------------------------------------------- 1 | # Storage and Redundancy 2 | 3 | A storage device is a piece of hardware used mostly for data storage. Storage is a mechanism that allows, either temporarily or permanently, a computer to preserve data. A fundamental component of most digital devices is storage devices such as flash drives and hard drives. They allow users to store all kinds of information, such as videos, documents, photographs, and raw data. 4 | 5 | **Persistence**: Persistence refers to characteristics of the entity and process that continue to exist even after the process that generated it ceases or is turned off by the computer on which it is operating. When an object or state is created and needs to be persistent, it is saved in a non-volatile storage location, like a hard drive, versus a temporary file or volatile random access memory (RAM). 6 | 7 | ## Types of Storages 8 | 9 | Storage is one of a computer system’s core components and can be categorized into 10 | many types, but there are two primary types: 11 | 12 | ### Volatile Storage (Memory) 13 | 14 | A continuous supply of electricity is required for data storage/retention. It serves as the primary storage of a device for temporarily storing data and managing workloads of applications. Cache memory and random access memory are examples of nonvolatile storage (RAM). 15 | 16 | ### Non-Volatile Storage 17 | 18 | A sort of storage device that preserves digital data even though it is turned off or electrical power is not supplied. This is often referred to as a secondary storage device and is used for I/O operations involving permanent data storage. A hard disc, USB storage, and optical media are examples of volatile storage. 19 | 20 | ## Redundancy 21 | 22 | Redundancy is a concept that implies the replication of a system’s essential components or functions to increase system reliability, typically in the form of a backup or fail-safe, or to enhance actual system performance. The term redundancy is used because if everything is working correctly, the duplicate device or competent does nothing and is redundant. 23 | 24 | Redundancy comes into play when we need to prevent a single point of failure (A single point of failure in a system is a point that can lead to the system’s failure). To eliminate any single point of failure, we need to make our system more redundant. Redundancy is the act of duplicating or adding certain parts of our system. Let’s take an example; imagine you have a system consisting of two identical, redundant web servers that are installed behind a load balancer. The traffic coming from clients will be distributed between the web servers, but if one of the servers goes down, the load balancer will redirect all traffic to the remaining server, which is working. 25 | 26 | **Passive Redundancy:** When you have multiple components at a given layer in your system, and if at any point, one of them dies, the remaining servers take over and prevent any failure. 27 | 28 | **Active Redundancy:** When you have multiple machines that work together, only one or a few of the machines will typically be handling traffic or doing work. If one of them fails, the other machines are going to know somehow and then take over. 29 | 30 | ## Redundancy vs. Replication 31 | 32 | The two words are quite similar at first look, but there is a considerable difference between them. Each of them has something to do with more nodes/components/processes in a system is a common part of the two concepts. 33 | + **Redundancy** — It explains that you have more than one node/component/process in a system, and it is quite beneficial in managing failovers. Another node in the system will take over and carry on if one of the nodes fails. Redundancy can be: 34 | - active: all the traffic goes to all nodes at the same time. 35 | - passive: where one node receives traffic, and in the case of failure, a switch will be made to another node 36 | + **Replication** — Redundancy is included, but it involves copying data from one node to another or synchronizing the state between nodes. An example of where replication is performed is at the level of databases. Replication can be: 37 | - **active**: each node receives each message to keep in sync with the rest of the nodes. 38 | - **passive**: this is the master-slave model, where the master receives all the requests and then forwards them to the slaves. 39 | 40 | In short, “Replication is the synchronization of state between redundant nodes” whereas “Redundancy is the duplication of nodes, in case of some of them are failing.” 41 | 42 | > “Replication ensures Consistency while Redundancy increases reliability.” -------------------------------------------------------------------------------- /concepts/others/redundancy/assets/redundancy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/others/redundancy/assets/redundancy.png -------------------------------------------------------------------------------- /concepts/others/websockets/README.md: -------------------------------------------------------------------------------- 1 | # Ổ cắm web là gì? - Khái niệm thiết kế hệ thống 2 | 3 | Trong khi xây dựng bất kỳ ứng dụng web nào, người ta cần xem xét cơ chế phân phối nào sẽ là tốt nhất. Web đã được xây dựng dựa trên mô hình yêu cầu và phản hồi của HTTP. Tuy nhiên, mô hình như vậy phải đối mặt với vấn đề chi phí của HTTP và do đó, chúng không phù hợp với các ứng dụng có độ trễ thấp. 4 | 5 | Trong blog này, chúng tôi tập trung vào Cổng kết nối web, là thành phần quan trọng đằng sau các ứng dụng như trò chơi nhiều người chơi hoặc bất kỳ ứng dụng nào dựa vào truyền dữ liệu thời gian thực. Chúng tôi sẽ cung cấp cho bạn thông tin chi tiết về cách thức hoạt động của ổ cắm web và các tính năng chính của nó. 6 | 7 | ## Hãy hiểu về Web Socket 8 | 9 | Web Socket là một giao thức truyền thông nhẹ hai chiều có thể gửi dữ liệu của máy khách đến máy chủ hoặc từ máy chủ đến máy khách. Nó nhằm cung cấp một kênh giao tiếp song công đầy đủ so với một kết nối TCP đơn lẻ. Sau khi kết nối được thiết lập, sau đó được duy trì tồn tại cho đến khi nó bị máy chủ hoặc máy khách chấm dứt. 10 | 11 | Web Sockets được sử dụng nhiều trong hầu hết các ứng dụng thời gian thực như giao dịch, nhiều người chơi và trò chơi trực tuyến để nhận dữ liệu trên một kênh liên lạc theo cách hai chiều. 12 | 13 | ! [] (./ asset / osi.jpeg) 14 | 15 | Web socket và HTTP khác nhau đáng kể, nhưng cả hai giao thức đều phụ thuộc vào TCP ở lớp 4 (lớp truyền tải) trong mô hình OSI và nằm ở lớp 7 (lớp ứng dụng). 16 | 17 | Giao thức ổ cắm web giảm thiểu chi phí liên quan đến HTTP bằng cách cho phép giao tiếp giữa máy khách và máy chủ với chi phí thấp hơn, nhằm cung cấp truyền dữ liệu theo thời gian thực qua kênh. 18 | 19 | Nó duy trì một kết nối TCP socket duy nhất lâu nay giữa máy khách và máy chủ để cho phép phân phối thông điệp hai chiều một cách hiệu quả, cung cấp kết nối không có độ trễ. 20 | 21 | ## Web Socket hoạt động như thế nào? 22 | 23 | Web Socket là một giao thức song công. Khi kết nối được thiết lập trong kiến ​​trúc máy khách-máy chủ, trao đổi thông báo bắt đầu ở chế độ hai chiều và nó sẽ vẫn tồn tại giữa máy khách và máy chủ cho đến khi một trong hai bên chấm dứt nó. 24 | - Tuy nhiên, để mở một kết nối web socket, người ta cần gọi hàm tạo web socket. Đối với ổ cắm web ** ws **: và ** wss **: lược đồ URL được sử dụng, trong khi đối với HTTP, HTTPS: được sử dụng. 25 | - Sau khi thiết lập kết nối với máy chủ, dữ liệu được gửi đến máy chủ bằng phương thức send () trên đối tượng kết nối. Trước đây nó chỉ hỗ trợ chuỗi, nhưng bây giờ trong thông số kỹ thuật mới nhất, nó có thể gửi cả tin nhắn nhị phân bằng cách sử dụng đối tượng ** Blob ** hoặc ** ArrayBuffer **. 26 | - Tương tự, máy chủ có thể gửi cho chúng tôi tin nhắn bằng cách kích hoạt lệnh gọi lại ** onmessage **. Lệnh gọi lại nhận một đối tượng sự kiện trong khi thuộc tính dữ liệu được sử dụng để truy cập thông báo thực tế. 27 | - Các ổ cắm web cũng có một tính năng bổ sung có tên là ** Phần mở rộng **, giúp gửi các khung hình nén hoặc ghép. 28 | 29 | ## Các tính năng chính của Web Sockets 30 | 31 | ** Trao đổi dữ liệu hai hướng **: Các ổ cắm web đóng một vai trò quan trọng trong việc giảm lưu lượng mạng bằng cách truyền dữ liệu theo cả hai hướng đồng thời bằng một kết nối duy nhất. 32 | 33 | ** Khả năng tương thích HTTP **: Các ổ cắm web tương thích cao với các phiên bản trước đó của kết nối HTTP, cho phép chúng tôi chuyển đổi giữa HTTP và WebSocket. 34 | 35 | ** Mẫu sự kiện Xuất bản / Đăng ký **: Các ổ cắm web cho phép mô hình truyền dữ liệu hiệu quả cao. Các kênh giao tiếp được thiết lập, cho phép gửi tin nhắn đến và đi từ máy chủ và nhận phản hồi theo hướng sự kiện mà không cần liên tục thăm dò máy chủ. 36 | 37 | ## Web Socket hữu ích như thế nào? 38 | 39 | ** Trò chuyện tức thì **: Web Sockets đóng một vai trò quan trọng trong việc nhắn tin thời gian thực. Chúng khá hữu ích trong việc xây dựng các tính năng phức tạp và thời gian thực như tin nhắn được mã hóa, chỉ báo nhập, v.v., cho các dịch vụ trò chuyện. 40 | 41 | ** Chơi game với nhiều người chơi **: Web Sockets khá hữu ích trong việc đồng bộ hóa trạng thái trò chơi giữa những người chơi và cho phép mạng có độ trễ thấp hoạt động. Chúng cho phép trải nghiệm liền mạch trên các thiết bị và cho phép nhiều tính năng tương tác trong thời gian thực để chơi game trực tuyến và được kết nối. 42 | 43 | ** Bản đồ trực tuyến **: Dữ liệu vị trí địa lý trực tiếp được sử dụng để xây dựng bản đồ trực tuyến theo thời gian thực. Web Sockets đóng một vai trò quan trọng trong việc định tuyến và điều hướng của bất kỳ tài sản di chuyển nào trên một bản đồ sống động. 44 | 45 | ** Kết quả trực tiếp **: Web Sockets giúp nâng cao nền tảng và liên tục cập nhật cho người dùng thông tin mới nhất và trạng thái nói dối như các cuộc thăm dò bầu cử và kết quả của họ, cập nhật tỷ số trực tiếp, v.v. 46 | 47 | ## Sự kết luận 48 | 49 | Web Sockets đã thực sự cách mạng hóa việc phát triển web. Sử dụng tính chất trạng thái và hai chiều, chúng có lợi trong các hệ thống yêu cầu cập nhật thời gian thực hoặc luồng dữ liệu liên tục. Tuy nhiên, nếu chúng ta chỉ cần tìm nạp một lần, thì một yêu cầu HTTP đơn giản sẽ được xem xét so với Web Sockets. 50 | -------------------------------------------------------------------------------- /concepts/others/websockets/README_EN.md: -------------------------------------------------------------------------------- 1 | # What are Web Sockets? - System Design Concept 2 | 3 | While building any web application, one needs to consider what delivery mechanism would be best. The web has been built around HTTP’s request and response paradigm. However, such a paradigm faces the overhead problem of HTTP, and as a result, they are not suitable for low latency applications. 4 | 5 | In this blog, we focus on Web Sockets, which are vital components behind the applications like multiplayer games or any application that rely on real-time data transfer. We will give you insight into how web-socket works and what are its key features. 6 | 7 | ## Let's Understand Web Socket 8 | 9 | Web Socket is a bidirectional lightweight communication protocol that can send the client’s data to the server or from the server to the client. It aimed to provide a fullduplex communication channel compared to a single TCP connection. Once the connection is established, then kept alive until it is terminated by either the server or the client. 10 | 11 | Web Sockets are highly used in almost every real-time application like trading, multiplayer, and online games to receive data on a single communication channel in a bidirectional manner. 12 | 13 | ![](./assets/osi.jpeg) 14 | 15 | Web sockets and HTTP differ significantly, but both protocols depend on TCP at layer 4 (transport layer) in the OSI model and are located at layer 7 (application layer). 16 | 17 | Web socket protocol mitigates the overhead associated with HTTP by enabling the communication between a client and a server with low-weight overheads, aiming to provide real-time data transfer across the channel. 18 | 19 | It maintains a long-held single TCP socket connection between the client and the server to enable the bi-directional messages to be distributed efficiently, providing a latency-free connection. 20 | 21 | ## How does Web Socket work? 22 | 23 | Web Socket is a full-duplex protocol. Once the connection is established in a clientserver architecture, the message exchange starts in a bidirectional mode and it will remain alive between client and server until either party terminates it. 24 | - However, for opening a web socket connection, one needs to call the web socket constructor. For web socket **ws**: and **wss**: URL schema is used, while for HTTP, https: is used. 25 | - After the establishment of a connection with the server, the data is sent to the server using the send() method on the connection object. Previously it used to support only strings, but now in the latest spec, it can send even the binary messages using **Blob** or **ArrayBuffer** object. 26 | - Similarly, the server might send us messages by firing the **onmessage** callback. The callback receives an event object while the data property is used to access the actual message. 27 | - Web sockets also have an additional feature named **Extension**, which helps in sending compressed or multiplexed frames. 28 | 29 | ## Key Features of Web Sockets 30 | 31 | **Bi-directional data exchange**: Web sockets play a significant role in reducing network traffic by transmitting data in both directions simultaneously using a single connection. 32 | 33 | **HTTP compatibility**: Web sockets are highly compatible with earlier versions of HTTP connection, which allow us to switch between HTTP and web socket. 34 | 35 | **Publish/Subscribe event pattern**: Web sockets allows a highly efficient data transfer model. Communication channels are established, allowing sending messages to and from a server and receiving event-driven responses without continuously polling the server. 36 | 37 | ## How is Web Socket useful? 38 | 39 | **Instant chat**: Web Sockets play a significant role in real-time messaging. They are quite useful in building real-time and complex features like encrypted messages, typing indicators, etc., for chat services. 40 | 41 | **Multi-Player gaming**: Web Sockets are quite helpful in synchronizing the game states between players and allow the low-latency network to work with. They allow seamless experiences across devices and allow many real-time interactive features for online and connected gaming. 42 | 43 | **Online maps**: Live geo-location data is used to build real-time online maps. Web Sockets play a significant role in routing and navigation of any moving asset on an alive map. 44 | 45 | **Live results**: Web Sockets help enhance the platform and keep updating the user with the latest information and lie status like election polls and their results, live score updates, etc. 46 | 47 | ## Conclusion 48 | 49 | Web Sockets have genuinely revolutionized web development. Using their stateful and bi-directional nature, they are beneficial in systems that require real-time updates or continuous data streams. However, if we only need to fetch only once, then a simple HTTP request would be considered compared to Web Sockets. 50 | -------------------------------------------------------------------------------- /concepts/others/websockets/assets/osi.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/others/websockets/assets/osi.jpeg -------------------------------------------------------------------------------- /concepts/others/websockets/assets/websocket.avif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/others/websockets/assets/websocket.avif -------------------------------------------------------------------------------- /concepts/proxies/README.md: -------------------------------------------------------------------------------- 1 | # Proxy trong Thiết kế Hệ thống là gì? 2 | 3 | [Version English](./README_EN.md) 4 | 5 | ![](./assets/proxies.svg) 6 | 7 | Trong bài viết này, chúng ta sẽ tìm hiểu về Proxy, một khái niệm phổ biến cho một cuộc phỏng vấn thiết kế hệ thống. Nhiều người trong chúng ta đã sử dụng các công cụ giúp chúng ta duy trì sự riêng tư hoặc ẩn danh của mình hoặc giữ an toàn trước những người dùng bên thứ ba nghe trộm trong kết nối của chúng ta. Bạn có biết nó hoạt động như thế nào và nó hữu ích như thế nào không? Hãy cùng tìm hiểu! 8 | 9 | ## Proxy là gì? 10 | 11 | Proxy là một thành phần đóng vai trò trung gian giữa client và server. Khi các client này gửi yêu cầu đến các trang web trên Internet, server proxy sẽ chặn các yêu cầu này, sau đó giao tiếp với server thay mặt cho các client này, giống như một gobetween cho phép chúng ta thực hiện điều gì đó trước hoặc sau khi yêu cầu được chuyển đến đích ban đầu. 12 | 13 | ![](./asset/what-are-proxies.png) 14 | 15 | ## Máy chủ proxy hoạt động như thế nào? 16 | 17 | Một proxy hoạt động thay mặt cho một khách hàng hoặc một nhóm khách hàng. Khi một client đưa ra yêu cầu giao tiếp với server, nó sẽ đi tới proxy thay vì đi trực tiếp đến server, sau đó sẽ chuyển tiếp yêu cầu tới server. Nói cách khác, client thực hiện một yêu cầu có nghĩa là đi tới server nhưng trước tiên hãy đi tới proxy để thay mặt client giao tiếp với server. 18 | 19 | ![](./asset/how-proxy-work.png) 20 | 21 | ## Proxy được sử dụng ở đâu? 22 | 23 | Proxy không chỉ được sử dụng để ẩn danh tính của client khỏi server, mà thay vào đó, nó có nhiều cách sử dụng khác: 24 | - Proxy được sử dụng để quản lý các yêu cầu và phản hồi. 25 | - Nó được sử dụng để lọc, ghi log và chuyển đổi các yêu cầu bằng cách thêm và bớt các header. 26 | - Nếu một số client truy cập vào một tài nguyên cụ thể, server proxy có thể lưu vào bộ nhớ cache và phản hồi cho tất cả các client mà không cần gửi yêu cầu đến server nhiều lần. 27 | - Nó cũng được sử dụng như một bộ cân bằng tải giữa các server. 28 | 29 | ## Forward Proxy là gì? 30 | 31 | Forward proxy, thường được gọi là proxy, là một proxy nằm giữa client và server. Ở đây, thay vì gửi yêu cầu trực tiếp đến server, các yêu cầu được gửi đến một forward proxy, sau đó sẽ gửi yêu cầu đến server. 32 | 33 | Các forward proxy được sử dụng như một thành phần trung gian thay vì tương tác trực tiếp với các server vì nhiều lý do như để tránh các hạn chế duyệt web, để truy cập nội dung bị chặn hoặc để bảo vệ danh tính của họ trực tuyến. 34 | 35 | ![](./asset/forward-proxy.png) 36 | 37 | ## Reverse Proxy là gì? 38 | 39 | Reverse Proxy là một proxy nằm giữa một hoặc nhiều server. Các reverse proxy hoàn toàn trái ngược với forward proxy về mô hình tương tác của chúng. Một forward proxy hoạt động thay mặt cho client, trong khi một reverse proxy hoạt động thay mặt cho server. 40 | 41 | ![](./asset/reverse-proxy.png) 42 | 43 | Trong trường hợp này, khi một client gửi một yêu cầu đến server, yêu cầu thực sự đi đến Reverse Proxy mà client không biết về nó. Client nghĩ rằng nó đang tương tác trực tiếp với server và đối với client, không có server nào khác ở đây và nó nghĩ rằng server mà nó đang tương tác là server mà nó muốn gửi yêu cầu. Chúng ta hãy lấy một ví dụ: 44 | 45 | > Giả sử, nếu chúng ta nhập https://www.enjoyalgorithm.com trong trình duyệt của mình, trình duyệt của chúng ta sẽ thực hiện truy vấn DNS để lấy địa chỉ IP của https://www.enjoyalgorithm.com. Nếu https://www.enjoyalgorithm.com sử dụng reverse proxy và xác định cấu hình chính xác, truy vấn DNS sẽ trả về địa chỉ IP của reverse proxy. 46 | 47 | ## Các trường hợp sử dụng của reverse proxy là gì? 48 | 49 | Reverse proxy rất tiện lợi khi chúng ta thiết kế một hệ thống phức tạp và nó có thể được sử dụng cho nhiều mục đích, chẳng hạn như: 50 | 51 | ![](./asset/use-case.png) 52 | 53 | - **Bảo mật**: Khi chúng ta sử dụng reverse proxy, địa chỉ IP gốc của trang web sẽ bị ẩn khỏi những kẻ tấn công. Vì vậy, để khai thác bất kỳ lỗ hổng nào, các người dùng độc hại không thể truy cập trực tiếp vào chúng. Nhiều server reverse proxy bao gồm các tính năng giúp bảo vệ server backend chống lại các cuộc tấn công từ chối dịch vụ phân tán (DDoS), chẳng hạn như từ chối lưu lượng truy cập từ các địa chỉ IP cụ thể của client (danh sách đen) hoặc giới hạn số lượng yêu cầu được chấp nhận từ mỗi client. 54 | - **Cân bằng tải**: Một trang web với hàng triệu người dùng truy cập mỗi ngày có thể khó xử lý lượng truy cập khổng lồ như vậy với một server duy nhất. Thay vào đó, chúng ta có thể sử dụng nhiều server và sử dụng reverse proxy như một giải pháp cân bằng tải để phân phối lưu lượng giữa các server và ngăn bất kỳ server nào bị quá tải. 55 | - **Bộ nhớ đệm**: Một reverse proxy cũng có thể được sử dụng để lưu các yêu cầu vào bộ đệm, dẫn đến hiệu suất nhanh hơn. 56 | 57 | ## Nhược điểm của Reverse Proxy 58 | 59 | Các reverse proxy không phải lúc nào cũng hữu ích và nó có những hạn chế riêng: 60 | - Thêm reverse proxy vào kiến ​​trúc làm tăng độ phức tạp của hệ thống của chúng ta. 61 | - Một reverse proxy duy nhất có thể hoạt động như một điểm lỗi duy nhất và việc thêm nhiều reverse proxy sẽ làm tăng độ phức tạp hơn nữa. 62 | - Khi chúng ta sử dụng các kết nối không được mã hóa với server proxy, server có thể sửa đổi các phản hồi mà chúng ta nhận được, dù tốt hay xấu, theo cả hai cách. 63 | - Ngay cả sau khi sử dụng các kết nối hoặc mạng được mã hóa, dữ liệu hoặc thông tin của chúng ta có thể bị rò rỉ bằng cách sử dụng kỹ thuật **kết nối được mã hóa TLS và SSL**. 64 | 65 | ## Reverse Proxy so với Load Balancer 66 | 67 | Reverse proxy và bộ cân bằng tải là các thành phần trong thiết kế hệ thống client-server. Trong tương tác giữa client và server, cả hai đều đóng vai trò trung gian, thực hiện các chức năng nâng cao hiệu quả. 68 | 69 | Bộ cân bằng tải phân phối các yêu cầu client đến giữa một nhóm server, trả lại phản hồi cho client thích hợp từ server đã chọn trong từng trường hợp. Khi một trang web cần nhiều server, bộ cân bằng tải thường được triển khai nhất vì khối lượng yêu cầu quá nhiều để xử lý hiệu quả cho một server duy nhất. Công việc của bộ cân bằng tải là phân phối các yêu cầu theo cách sử dụng tốt nhất khả năng của từng server, tránh quá tải trên bất kỳ server nào và dẫn đến phản hồi nhanh nhất có thể của client. 70 | 71 | ![](./asset/proxy-vs-load-balancer.png) 72 | 73 | Một reverse proxy chấp nhận một yêu cầu từ một client hoặc một nhóm client, chuyển tiếp nó đến một server và trả lại phản hồi của client từ server. Trong khi việc triển khai bộ cân bằng tải chỉ có ý nghĩa khi bạn có nhiều server, thậm chí chỉ với một server web hoặc server ứng dụng, việc triển khai reverse proxy vẫn có ý nghĩa. -------------------------------------------------------------------------------- /concepts/proxies/README_EN.md: -------------------------------------------------------------------------------- 1 | # What are Proxies in System Design? 2 | 3 | In this blog, we will learn about Proxy, an essential concept for a system design interview. Many of us have used tools that help us maintain our privacy or anonymity or remain safe from third-party users eavesdropping in our connection. Do you know how it works and how it is useful? Let’s find out! 4 | 5 | ## What are Proxies? 6 | 7 | A proxy is a server that acts as an intermediary between a client and another server. When these clients send requests to websites on the Internet, the proxy server intercepts these requests, then communicates with the servers on behalf of these clients, like a gobetween allowing us to perform something either before or after the request gets through to the original destination. 8 | 9 | ![](./assets/what-are-proxies.png) 10 | 11 | ## How does a proxy server work? 12 | 13 | A proxy acts on behalf of a client or group of clients. When a client issues a request to communicate with the server, it goes to the proxy instead of going directly to the server, which then forwards the request to the server. In other words, the client makes a request meant to go to the server but first goes to the proxy to communicate with the server on the client’s behalf. 14 | 15 | ![](./assets/how-proxy-work.png) 16 | 17 | ## Where is the Proxy server used? 18 | 19 | Proxy servers are used not only to hide the identity of the client from the server, but instead, it has many other usages: 20 | - Proxy servers are used to manage requests and responses. 21 | - It is used to filter, log, and transform requests by adding and removing headers. 22 | - If several clients access a particular resource, the proxy server can cache it and respond to all clients without sending the request to the server multiple times. 23 | - It is also used as a load balancer between servers. 24 | 25 | ## What is a Forward Proxy? 26 | 27 | Forward proxy, often called a proxy, is a server that sits between a client and a server. Here, instead of sending requests directly to the servers, requests are sent to a forward proxy, which then sends the requests to the server. 28 | 29 | Forward proxies are used as a middleman instead of directly interacting with the servers for many reasons such as to avoid browsing restrictions, to access blocked contents, or to protect their identity online. 30 | 31 | ![](./assets/forward-proxy.png) 32 | 33 | ## What is a Reverse Proxy? 34 | 35 | A Reverse Proxy is a proxy server that sits between one or more servers. Reverse proxies are the exact opposite of forwarding proxies in terms of their interaction pattern. A forward proxy acts on behalf of clients, whereas a reverse proxy acts on behalf of severs. 36 | 37 | ![](./assets/reverse-proxy.png) 38 | 39 | In this case, when a client sends a request to the server, the request actually goes to the Reverse Proxy without the client knowing about it. The client thinks it is directly interacting with the server, and for the client, there are no other servers here, and it thinks that the one it is interacting with is the server it wanted to send a request to. Let us take an example: 40 | 41 | > “Suppose, if we type https://www.enjoyalgorithm.com in our browser, our browser makes a DNS query to get the IP address of https://www.enjoyalgorithm.com. If https://www.enjoyalgorithm.com used a reverse proxy and configured it correctly, the DNS query will return the reverse proxy's IP address.” 42 | 43 | ## What are the use cases of a reverse proxy? 44 | 45 | Now, a reverse proxy is handy when we design a complex system, and it can be used for many purposes, such as: 46 | 47 | ![](./assets/use-case.png) 48 | 49 | - **Security**: When we use a reverse proxy, a website’s origin server IP address is abstracted from the attackers. So to exploit any vulnerabilities, malicious clients can not access them directly. Many reverse proxy servers include features that help protect backend servers against distributed denial-of-service (DDoS) attacks, such as rejecting traffic from specific IP addresses of the client (blacklisting) or limiting the number of requests accepted from each client. 50 | - **Load Balancing**: A website with millions of users visiting every day may find it hard to handle such huge traffic with a single server. Instead, we can use more than one server and use reverse proxy as a load balancing solution to distribute the traffic among servers and prevent any server from getting overloaded. 51 | - **Caching**: A reverse proxy can also be used to cache requests, resulting in faster performance. 52 | 53 | ## Disadvantages of Reverse Proxies 54 | 55 | Reverse proxies are not always useful, and it has their own drawbacks: 56 | - Adding reverse proxies to the architecture increases the complexity of our system. 57 | - A single reverse proxy can act as a single point of failure, and adding multiple reverse proxies increases complexity even more. 58 | - When we use unencrypted connections to a proxy server, the server can modify the responses we receive, good or bad, in both ways. 59 | - Even after using the encrypted connections or network, our data or information can be leaked using the technique of** TLS and SSL** encrypted connections. 60 | 61 | ## Reverse Proxy vs. Load Balancer 62 | 63 | Reverse proxy servers and load balancers are components in a client-server system design. In the interaction between clients and servers, both act as intermediaries, performing efficiency-enhancing functions. 64 | 65 | A load balancer distributes incoming client requests among a group of servers, returning the response to the appropriate client from the selected server in each case. When a site needs multiple servers, load balancers are most commonly deployed because the volume of requests is too much to handle efficiently for a single server. The load balancer's job is to distribute the requests in a way that makes the best use of the capacity of each server, prevents overload on any server, and results in the client’s quickest possible response. 66 | 67 | ![](./assets/proxy-vs-load-balancer.png) 68 | 69 | A reverse proxy accepts a request from a client or set of clients, forwards it to a server, and returns the client’s response from the server. Whereas deploying a load balancer only makes sense when you have multiple servers, even with just one web server or application server, deploying a reverse proxy often makes sense. 70 | -------------------------------------------------------------------------------- /concepts/proxies/assets/forward-proxy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/proxies/assets/forward-proxy.png -------------------------------------------------------------------------------- /concepts/proxies/assets/how-proxy-work.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/proxies/assets/how-proxy-work.png -------------------------------------------------------------------------------- /concepts/proxies/assets/proxy-vs-load-balancer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/proxies/assets/proxy-vs-load-balancer.png -------------------------------------------------------------------------------- /concepts/proxies/assets/reverse-proxy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/proxies/assets/reverse-proxy.png -------------------------------------------------------------------------------- /concepts/proxies/assets/use-case.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/proxies/assets/use-case.png -------------------------------------------------------------------------------- /concepts/proxies/assets/what-are-proxies.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/concepts/proxies/assets/what-are-proxies.png -------------------------------------------------------------------------------- /concepts/proxies/src/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /concepts/proxies/src/app.js: -------------------------------------------------------------------------------- 1 | const express = require("express"); 2 | const morgan = require("morgan"); 3 | const { createProxyMiddleware } = require("http-proxy-middleware"); 4 | require("dotenv").config(); 5 | 6 | // Create Express Server 7 | const app = express(); 8 | 9 | // Configuration 10 | const PORT = 3000; 11 | const HOST = "localhost"; 12 | const { API_BASE_URL } = process.env; 13 | const { API_KEY_VALUE } = process.env; 14 | const API_SERVICE_URL = `${API_BASE_URL}?q=London&appid=${API_KEY_VALUE}`; 15 | 16 | // Logging the requests 17 | app.use(morgan("dev")); 18 | 19 | // Proxy Logic : Proxy endpoints 20 | app.use( 21 | "/weather", 22 | createProxyMiddleware({ 23 | target: API_SERVICE_URL, 24 | changeOrigin: true, 25 | pathRewrite: { 26 | "^/weather": "", 27 | }, 28 | }) 29 | ); 30 | 31 | // Starting our Proxy server 32 | app.listen(PORT, HOST, () => { 33 | console.log(`Starting Proxy at ${HOST}:${PORT}`); 34 | }); -------------------------------------------------------------------------------- /concepts/proxies/src/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "src", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "start": "node app.js", 8 | "test": "echo \"Error: no test specified\" && exit 1" 9 | }, 10 | "keywords": [], 11 | "author": "", 12 | "license": "ISC", 13 | "dependencies": { 14 | "dotenv": "^16.0.1", 15 | "express": "^4.18.1", 16 | "http-proxy-middleware": "^2.0.6", 17 | "morgan": "^1.10.0" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /concepts/throughput/README.md: -------------------------------------------------------------------------------- 1 | # Thông lượng: Khái niệm Thiết kế Hệ thống 2 | 3 | [Version English](./README_EN.md) 4 | 5 | ![](./assets/throughput.svg) 6 | 7 | Chắc hẳn bạn đã thấy nước chảy ra từ đường ống như thế nào rồi đúng không! Lưu lượng của nước có thể khác nhau, nghĩa là đôi khi lưu lượng có thể ít hơn và đôi khi lưu lượng lớn, nhưng có một giới hạn trên đối với lưu lượng tối đa có thể đi ra từ một đường ống và đó là công suất của nó. Thông lượng là một khái niệm cơ bản trong Khoa học Máy tính và mạng truyền thông, tương tự như lưu lượng nước trong đường ống. Trong bài viết này, chúng ta sẽ nói về thông lượng và tầm quan trọng của nó trong việc thiết kế bất kỳ hệ thống máy tính nào. 8 | 9 | ## Ý nghĩa thông lượng trong Thiết kế Hệ thống 10 | 11 | Thông lượng được định nghĩa là tổng số mục được xử lý trên một đơn vị thời gian, hay có thể nói thông lượng là tốc độ sản xuất một thứ gì đó. Nó thường được biểu thị bằng số lượng bit được truyền mỗi giây hoặc số lượng hoạt động HTTP mỗi ngày. Thông lượng của hệ thống thường thu được bằng cách cộng tất cả các mục và chia tổng cho khoảng mẫu. Đây là một cách tiêu chuẩn để có được thông lượng, nhưng nó bị bỏ qua các biến thể tốc độ xử lý. Hãy lấy một ví dụ để hiểu rõ hơn về cách đạt được thông lượng. 12 | 13 | Giả sử một dây chuyền lắp ráp đang sản xuất ô tô. Nếu nhà máy có thể sản xuất khoảng 100 xe ô tô mỗi ngày. Như vậy thông lượng của tuyến là **~ 100 xe/ngày**. 14 | 15 | ## Quan niệm sai với độ trễ 16 | 17 | Độ trễ được định nghĩa là khoảng thời gian từ khi đưa ra yêu cầu đến khi bắt đầu thấy kết quả. Nó được đo bằng đơn vị thời gian. Độ trễ luôn bị hiểu nhầm với thông lượng và người ta cho rằng **Hệ thống thông lượng cao nên có độ trễ thấp**. Tuy nhiên, điều này có thể không phải lúc nào cũng đúng. Hãy xem xét việc xử lý dữ liệu liên quan đến các đĩa, có xu hướng có thông lượng lớn nhưng không cung cấp độ trễ thấp. 18 | 19 | Tương tự, trong các kết nối được nối mạng, độ trễ tăng theo thông lượng. Với sự gia tăng thông lượng, ngày càng nhiều gói tin sẽ có trên đường truyền và góp phần làm tăng độ trễ. Cũng có thể có các hệ thống có **Thông lượng thấp và độ trễ cũng thấp**. Do đó, sự kết hợp giữa Độ trễ và Thông lượng được lựa chọn tốt nhất bằng cách xem xét hệ thống và các yêu cầu nghiệp vụ. 20 | 21 | ### Các yếu tố ảnh hưởng đến thông lượng 22 | 23 | Thông lượng của hệ thống phụ thuộc vào các yếu tố khác nhau. Nó phụ thuộc vào các giới hạn tương tự cơ bản, khả năng xử lý của hệ thống, khả năng truy cập của dịch vụ và các thành phần phần cứng khác nhau. Nó cũng bị ảnh hưởng bởi lưu lượng mạng, các thay đổi về nhiễu và lỗi truyền dẫn. Thông lượng cũng phụ thuộc vào chi phí giao thức vì những chi phí này ảnh hưởng đến tốc độ truyền dữ liệu và hạn chế hệ thống đạt được thông lượng mong muốn tối đa. 24 | 25 | ### Hạn chế tương tự 26 | 27 | Phương tiện vật lý tương tự có ảnh hưởng rõ rệt đến thông lượng tối đa có thể đạt được của hệ thống. Trong giao tiếp được nối mạng, các giới hạn tương tự của phương tiện ảnh hưởng đến thông lượng bằng cách tuân theo giới hạn trên về lượng thông tin có thể chia sẻ. 28 | 29 | ### Giới hạn phần cứng 30 | 31 | Có một giới hạn trên cho mọi hệ thống máy tính và tiến trình. Điều này giới hạn thông lượng của hệ thống vì các hệ thống tính toán chỉ có một số khả năng xử lý hữu hạn. Khi một truy vấn lớn và phức tạp đòi hỏi phải tính toán nhiều, nó sẽ gây ra ảnh hưởng lớn đến tốc độ xử lý và thông lượng của hệ thống. 32 | 33 | ### Khả năng tiếp cận 34 | 35 | Khả năng tiếp cận dịch vụ cũng ảnh hưởng đến thông lượng của hệ thống. Khi nhiều người dùng chia sẻ đồng thời một hệ thống giao tiếp, điều đó có thể liên quan đến việc chia sẻ tài nguyên và ảnh hưởng đến thông lượng của hệ thống. Hơn nữa, khả năng tiếp cận với nhiều khách hàng cũng làm tăng lưu lượng truy cập trong mạng, đây cũng là một yếu tố quan trọng làm giảm thông lượng. 36 | 37 | ## Kết luận 38 | 39 | Thông lượng là một khái niệm rất liên quan đến thiết kế của mọi hệ thống. Nó là thước đo lượng dữ liệu được truyền qua một kênh. Các kiến ​​trúc sư luôn tập trung vào việc tăng thông lượng càng nhiều càng tốt để tăng công suất và hiệu suất của hệ thống. Trong bài viết này, chúng tôi đã cố gắng đề cập đến tất cả các khía cạnh khái niệm của Thông lượng. -------------------------------------------------------------------------------- /concepts/throughput/README_EN.md: -------------------------------------------------------------------------------- 1 | # Throughput: System Design Concept 2 | 3 | You must have seen how the water comes out of a pipe, right! The flow of water may vary,i.e., sometimes the flow might be less and sometimes the flow is large, but there is an upper bound to the maximum flow that could come out of a pipe, and that is its capacity. Throughput is a fundamental concept in Computer Science and communication networks, analogous to water flow in a pipe. In this blog, we’ll be talking about Throughput and its importance in designing any Computer System. Let’s dive in, and let’s get started! 4 | 5 | ## Throughput meaning in System Design 6 | 7 | Throughput is defined as the total number of items processed per unit of time, or we can say Throughput is the rate at which something is produced. It is generally represented as the number of bits transmitted per second or the number of HTTP operations per day. The system’s Throughput is generally obtained by summing up all the items and dividing the sum by the sample interval. It is a standard way of obtaining the Throughput, but it suffers from ignoring the processing speed variations. Let’s take an example to get a clear understanding of how to obtain Throughput :) Suppose an assembly line is manufacturing cars. Let’s consider the factory can able to produce around 100 cars per day. So the Throughput of the line is **Throughput ~ 100 cars/day**. 8 | 9 | ## Misconceptions with Latency 10 | 11 | Latency is defined as the time interval between making a request and beginning to see a result. It is measured in the unit of time. Latency is always misunderstood with Throughput, and it is taken for granted that **High throughput systems should have low latency**. However, this may not always be true. Consider the data processing in association with disks, which tend to have large Throughput but fail to provide low latency. 12 | 13 | Similarly, in networked connections, the latency increases with Throughput. With the increase in Throughput, more and more packets will be there on a wire and contribute to increased latency. It is also possible to have systems with **Low Throughput and Low Latency also**. Hence the combination of Latency and Throughput is best chosen by considering the system and business requirements. 14 | 15 | ### Factors Affecting Throughput 16 | 17 | The Throughput of the system depends on various factors. It depends on underlying analog limitations, the system’s processing power, accessibility of the service, and various hardware components. It also gets affected by the network’s traffic, interference changes, and transmission errors. Throughput also depends upon the protocol overheads as these overhead affects the data transfer rate and limits the system from achieving the maximum desirable Throughput. 18 | 19 | ### Analog limitations 20 | 21 | Analog physical medium has a profound influence on the maximum attainable Throughput of the system. In networked communication, the medium’s analog limitations affect the Throughput by sticking to an upper bound limit on the amount of shareable information. 22 | 23 | ### Hardware limitations 24 | 25 | There is an upper bound to every computing and processing system. This limits the Throughput of the system as computational systems have some finite processing power only. When a large and complicated query requires massive computations, it causes a sound effect on the processing speed and, hence, the system’s Throughput. 26 | 27 | ### Accessibility 28 | 29 | Accessibility to the service also affects the Throughput of the system. When multiple users share a single communication system simultaneously, it may involve sharing the resources and affecting the system’s Throughput. Moreover, accessibility to many customers also increases the traffic in the network, which is also an important factor in decreasing the Throughput. 30 | 31 | ## Conclusion 32 | 33 | Throughput is a very concept related associated with the design of every system. It is a measure of the amount of data transmitted through a channel. Architects always focus on increasing Throughput as much as possible to increase the system’s capacity and performance. In this blog, we tried to cover all the conceptual aspects of Throughput. -------------------------------------------------------------------------------- /concepts/throughput/assets/throughput.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /examples/README.md: -------------------------------------------------------------------------------- 1 | # Thiết -------------------------------------------------------------------------------- /examples/REAMDE_EN.md: -------------------------------------------------------------------------------- 1 | # System Design in Real World 2 | 3 | || System Design | 4 | |-|-| 5 | | ![](./dropbox/assets/logo.png) | [Dropbox](./dropbox/README_EN.md) | 6 | | ![](./facebook/assets/logo.png) | [Facebook](./facebook/README_EN.md) | 7 | | ![](./instagram/assets/logo.png) | [Instagram](./instagram/README_EN.md) | 8 | | ![](./messenger/assets/logo.jpg) | [Messenger](./messenger/README_EN.md) | 9 | | ![](./rate-limiter/assets/logo.png) | [Rate Limiter](./rate-limiter/README_EN.md) | 10 | | ![](./tinyurl/assets/logo.png) | [TinyURL](./tinyurl/README_EN.md) | 11 | | ![](./twitter/assets/logo.png) | [Twitter](./twitter/README_EN.md) | 12 | | ![](./typeahead-suggestion/assets/logo.png) | [Typeahead Suggestion](./typeahead-suggestion/README_EN.md) | 13 | | ![](./uber/assets/logo.jpeg) | [Uber](./uber/README_EN.md) | 14 | | ![](./web-crawler/assets/logo.jpg) | [Web Crawler](./web-crawler/README_EN.md) | 15 | | ![](./yelp/assets/logo.jpg) | [Yelp](./yelp/README_EN.md) | 16 | | ![](./youtube/assets/logo.png) | [Youtube](./youtube/README_EN.md) | 17 | -------------------------------------------------------------------------------- /examples/assets/What-Is-System-Design.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/assets/What-Is-System-Design.jpg -------------------------------------------------------------------------------- /examples/assets/dropbox-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/assets/dropbox-logo.png -------------------------------------------------------------------------------- /examples/assets/facebook-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/assets/facebook-logo.png -------------------------------------------------------------------------------- /examples/assets/instagram-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/assets/instagram-logo.png -------------------------------------------------------------------------------- /examples/assets/messsenger-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/assets/messsenger-logo.png -------------------------------------------------------------------------------- /examples/assets/rate-limiter-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/assets/rate-limiter-logo.png -------------------------------------------------------------------------------- /examples/assets/system-in-realworld.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/assets/system-in-realworld.jpg -------------------------------------------------------------------------------- /examples/assets/tinyurl-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/assets/tinyurl-logo.png -------------------------------------------------------------------------------- /examples/assets/twitter-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/assets/twitter-logo.png -------------------------------------------------------------------------------- /examples/assets/typeahead-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/assets/typeahead-logo.png -------------------------------------------------------------------------------- /examples/assets/uber-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/assets/uber-logo.png -------------------------------------------------------------------------------- /examples/assets/web-crawler-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/assets/web-crawler-logo.png -------------------------------------------------------------------------------- /examples/assets/yelp-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/assets/yelp-logo.png -------------------------------------------------------------------------------- /examples/assets/youtube-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/assets/youtube-logo.png -------------------------------------------------------------------------------- /examples/dropbox/assets/component-design.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/dropbox/assets/component-design.png -------------------------------------------------------------------------------- /examples/dropbox/assets/high-level-design.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/dropbox/assets/high-level-design.png -------------------------------------------------------------------------------- /examples/dropbox/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/dropbox/assets/logo.png -------------------------------------------------------------------------------- /examples/dropbox/assets/message-queue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/dropbox/assets/message-queue.png -------------------------------------------------------------------------------- /examples/dropbox/assets/storage.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/dropbox/assets/storage.png -------------------------------------------------------------------------------- /examples/facebook/assets/database.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/facebook/assets/database.png -------------------------------------------------------------------------------- /examples/facebook/assets/high-level-design.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/facebook/assets/high-level-design.png -------------------------------------------------------------------------------- /examples/facebook/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/facebook/assets/logo.png -------------------------------------------------------------------------------- /examples/instagram/README.md: -------------------------------------------------------------------------------- 1 | # Thiết Kế Instagram 2 | 3 | *Thiết kế hệ thống chia sẻ hình ảnh tương tự Instagram, nơi người dùng có thể tải ảnh của họ lên và chia sẻ với người khác.* 4 | 5 | ## Instagram là gì? 6 | 7 | Instagram là trang mạng xã hội cho phép người dùng tải và chia sẻ hình ảnh hay video với những người khác. Người dùng Instagram có thể chọn cách chia sẻ nội dung của họ là công khai hay riêng tư. Các nội dung công khai có thể được xem bởi bất kỳ ai, còn nội dung riêng tư thì chỉ có những người dùng được chỉ định mới có thể truy cập được. Instagram còn cho phép người dùng chia sẻ trên nhiều nền tảng khác như Facebook, Twitter, Flickr hay Tumblr. 8 | 9 | Trong bài viết này, chúng ta sẽ chỉ thiết kế một phiên bản đơn giản của Instagram, để người dùng có thể chia sẻ anh và theo dõi các người dùng khác. Trang "News Feed" sẽ bao gồm các ảnh mà người dùng đó đang theo dõi. 10 | 11 | ## Yêu cầu và Mục tiêu 12 | 13 | Ta sẽ tập trung vào tập yêu cầu chính khi thiết kế Instagram: 14 | 15 | ### Yêu cầu bắt buộc 16 | 17 | 1. Người dùng có thể tải lên/tải xuống/xem hình ảnh. 18 | 2. Người dùng có thể tìm kiếm dựa trên tiêu đề của ảnh/video. 19 | 3. Người dùng có thể theo dõi người khác. 20 | 4. Hệ thống nên có chức năng hiển thị các ảnh nổi bật của những người mà người dùng theo dõi trên News Feed. 21 | 22 | ### Yêu cầu không bắt buộc 23 | 24 | 1. Hệ thống nên có tính khả dụng cao 25 | 2. Độ trễ chấp nhận được trong hệ thống là 200ms cho trang News Feed. 26 | 3. Có thể hy sinh tính nhất quán cho tính khả dụng, nếu người dùng không thể xem ảnh trong một khoảng khắc nào đó, thì đó không phải vấn đề quá lớn. 27 | 4. Hệ thống nên có độ tin cậy cao, để ảnh hay video không bao giờ bị mất. 28 | 29 | **Không trong phạm vi:** Thêm tag cho ảnh, tìm kiếm bằng tag, bình luận, tag người dùng,... 30 | 31 | ### Một vài thiết kế cần xem xét 32 | 33 | Hệ thống sẽ thiên về việc đọc dữ liệu, nên chúng ta sẽ tập trung vào xây dựng hệ thống cho truy xuất hình ảnh nhanh chóng. 34 | 1. Người dùng có thể đăng lên số lượng ảnh tuỳ thích. Thế nên việc quản lý bộ lưu trữ một cách hiệu quả là nhân tố quan trọng khi thiết kế hệ thống này. 35 | 2. Độ trễ thấp khi người dùng xem ảnh. 36 | 3. Dữ liệu nên được đảm bảo 100%. Nếu người dùng đăng ảnh hệ thống sẽ đảm bảo nó không bao giờ bị mất. 37 | 38 | ### Các tính toán cơ bản 39 | 40 | - Giả sử tả có 500 triệu người dùng, trong đó có 1 triệu người dùng mỗi ngày. 41 | - 2 triệu ảnh mỗi ngày, 23 ảnh mới mỗi giây. 42 | - Dung lượng trung bình mỗi ảnh không lớn hơn 200KB. 43 | - Tổng dung lượng mỗi ngày là: 2M * 200KB => 400GB 44 | - Dung lượng trong 10 năm: 400GB * 365 * 10 ~= 1425TB 45 | 46 | ### Thiết kế cấp cao 47 | 48 | Ở mức độ này, ta có 2 trường hợp là một là tải ảnh lên hai là xem/tìm ảnh. Dịch vụ của chúng ta cung cấp một server dạng storage cho lưu trữ ảnh và một server cơ sở dữ liệu cho thông tin metadata của ảnh. 49 | 50 | ![](./assets/high-level.png) 51 | 52 | ### Cơ sở dữ liệu 53 | 54 | > Thiết kế lược đồ cơ sở dữ liệu là bước sớm nhất giúp hiểu được luồng hoạt động của dữ liệu với các thành phần khác nhau và là hướng dẫn cho phân vùng dữ liệu về sau. 55 | 56 | Ta cần lưu trữ dữ liệu người dùng, ảnh mà họ đăng lên và các người mà họ theo dõi. Bảng `Photo` sẽ lưu trữ tất cả dữ liệu liên quan đến ảnh, và ta cần đánh chỉ mục trên `PhotoID`, `CreationDate` vì ta cần lấy các bức ảnh gần đây nhất. 57 | 58 | ![](./assets/database.png) 59 | 60 | Cách tiếp cận thông thường để lưu trữ các lược đồ dữ liệu ở trên là sử dụng một RDBMS như MySQL vì ta cần thực hiện JOIN. Song các cơ sở dữ liệu quan hệ (SQL) cũng đi kèm nhiều thử thách khi ta mở rộng chúng. 61 | 62 | Về phía hình ảnh ta sẽ lưu chúng bằng các dịch vụ lưu trữ file phân tán như HDFS hay S3. 63 | 64 | Ta cũng có thể lưu trữ các lược đồ dữ liệu trên trong các cơ sở dữ liệu NoSQL dạng key-value. Ví dụ như với bảng `Photo` thì **key** có thể là `PhotoID` và **value** là một đối tượng bao gồm: `PhotoLocation`, `UserLocation`, `CreationTimestamp`,... 65 | 66 | Trong trường hợp ta cần lưu trữ mối quan hệ giữa người dùng và ảnh, để biết ảnh nào được đăng bởi ai. Đồng thời ta cũng cần lưu trữ danh sách người dùng được theo dõi. Với cả hai bảng này ta có thể sử dụng cơ sở dữ liệu NoSQL hướng column như Cassandra. Ví dụ như với bảng `UserPhoto`, **key** có thể là `UserID` và **value** là danh sách các `PhotoIDs` mà người dùng sở hữu, được lưu ở các cột khác. Ta sẽ có một lược đồ tương tự với bảng `UserFollow`. 67 | 68 | ### Ước lượng kích cỡ dữ liệu 69 | 70 | Ta sẽ đi đến các tính toán xem cần bao nhiều dữ liệu cho mỗi bảng và tổng dung lượng mà ta cần cho 10 năm. 71 | 72 | - **User**: giả sr kiểu `int` và `datetime` đều là 4 bytes, mỗi hàng trong bảng User sẽ cần 68 bytes: 73 | 74 | > UserID (4 bytes) + Name (20 bytes) + Email (32 bytes) + DateOfBirth (4 bytes) + CreationDate (4 bytes) + LastLogin (4 bytes) = 68 bytes 75 | 76 | Nếu ta có 500 triệu người dùng, ta sẽ cần 32GB cho tổng dung lượng. 77 | 78 | > 500M * 68 ~= 32GB 79 | 80 | - **Photo**: Mỗi hàng trong bảng Photo sẽ là 284 bytes: 81 | 82 | > PhotoID (4 bytes) + UserID (4 bytes) + PhotoPath (256 bytes) + PhotoLatitude (4 bytes) + PhotLongitude(4 bytes) + UserLatitude (4 bytes) + UserLongitude (4 bytes) + CreationDate (4 bytes) = 284 bytes 83 | 84 | Nếu có 2 triệu người dùng đăng ảnh mỗi ngày, ta sẽ cần 0.5GB mỗi ngày: 85 | 86 | > 2M * 284 bytes ~= 0.5GB per day 87 | 88 | Như vậy trong 10 năm sẽ là 1.88TB 89 | 90 | - **UserFollow**: Mỗi hàng trong bảng UserFollow sẽ là 8 bytes. Nếu ta có 500 triệu người dùng và trung bình một người có 500 người theo dõi. Ta sẽ cần 1.82TB cho bảng UserFollow: 91 | 92 | > 500 million users * 500 followers * 8 bytes ~= 1.82TB 93 | 94 | Tổng dung lượng yêu cầu ở cả 3 bảng là: 95 | 96 | ``` 97 | 32GB + 1.88TB + 1.82TB ~= 3.7TB 98 | ``` 99 | 100 | ### Thiết kế thành phần 101 | 102 | Quá trình tải ảnh lên (ghi dữ liệu) có thể sẽ chậm do các thành phần ổ cứng, ngược lại việc xem ảnh (đọc dữ liệu) lại nhanh hơn, đặc biệt là khi dùng bộ đệm. 103 | 104 | Việc tải ảnh lên của người dùng có thể sẽ tiêu thụ hết tất cả các kết nối khả dung, mà đây lại là một tiến trình chậm. Nên có thể dẫn đến việc các tiến trình đọc dữ liệu sẽ không thể thực hiện khi mà hệ thống quá bận với các yêu cầu ghi dữ liệu. Có một điều cần phải nhớ khi thiết kế hệ thống là có một số lượng giới hạn các kết nối được phép đến server. Giả sử ta thiết lập là 500, thì trong cùng thời điểm chỉ có tối đa 500 kết nối được phép đến server. Nếu 500 kết nối này đều là yêu cầu ghi thì ta không thể thực hiện bất kỳ thao tác đọc dữ liệu nào cho đến khi một kết nối ghi hoàn tất. 105 | 106 | Để giải quyết bài toán nghẽn cổ chai này, ta cần tách hệ thống của chúng ta thành hai dịch vụ: một bên chỉ cho đọc dữ liệu và bên còn lại cho ghi dữ liệu để đảm bảo rằng quá trình đăng ảnh sẽ không làm sập hệ thống. 107 | 108 | Với việc tách ra như vậy, ta có thể mở rộng dịch vụ xem ảnh và tải ảnh lên một cách độc lập và tối ưu hơn. 109 | 110 | ![](./assets/design.png) 111 | 112 | ### Độ tin cậy và dự phòng 113 | 114 | -------------------------------------------------------------------------------- /examples/instagram/assets/database.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/instagram/assets/database.png -------------------------------------------------------------------------------- /examples/instagram/assets/design.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/instagram/assets/design.png -------------------------------------------------------------------------------- /examples/instagram/assets/high-level.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/instagram/assets/high-level.png -------------------------------------------------------------------------------- /examples/instagram/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/instagram/assets/logo.png -------------------------------------------------------------------------------- /examples/instagram/assets/redundancy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/instagram/assets/redundancy.png -------------------------------------------------------------------------------- /examples/messenger/assets/high-level-design.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/messenger/assets/high-level-design.png -------------------------------------------------------------------------------- /examples/messenger/assets/logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/messenger/assets/logo.jpg -------------------------------------------------------------------------------- /examples/messenger/assets/manage-user.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/messenger/assets/manage-user.png -------------------------------------------------------------------------------- /examples/messenger/assets/workflow-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/messenger/assets/workflow-1.png -------------------------------------------------------------------------------- /examples/messenger/assets/workflow-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/messenger/assets/workflow-2.png -------------------------------------------------------------------------------- /examples/messenger/assets/workflow-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/messenger/assets/workflow-3.png -------------------------------------------------------------------------------- /examples/messenger/assets/workflow-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/messenger/assets/workflow-4.png -------------------------------------------------------------------------------- /examples/messenger/assets/workflow-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/messenger/assets/workflow-5.png -------------------------------------------------------------------------------- /examples/messenger/assets/workflow-6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/messenger/assets/workflow-6.png -------------------------------------------------------------------------------- /examples/messenger/assets/workflow-7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/messenger/assets/workflow-7.png -------------------------------------------------------------------------------- /examples/messenger/assets/workflow-8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/messenger/assets/workflow-8.png -------------------------------------------------------------------------------- /examples/rate-limiter/assets/atomicity.svg: -------------------------------------------------------------------------------- 1 |
Request 1
1) Read Count = 2
2) 
3) Update Count = 3

[Not supported by viewer]
Request 2
2) Read Count = 2
3) Update Count = 3


[Not supported by viewer]
Time
Time
-------------------------------------------------------------------------------- /examples/rate-limiter/assets/high-level.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/rate-limiter/assets/high-level.png -------------------------------------------------------------------------------- /examples/rate-limiter/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/rate-limiter/assets/logo.png -------------------------------------------------------------------------------- /examples/tinyurl/README.md: -------------------------------------------------------------------------------- 1 | # Thiết Kế Dịch Vụ Rút Gọn URL - TinyURL 2 | 3 | ![](./assets/design-a-url-shortening-service-like-tiny-url-cover.jpg) 4 | 5 | ## Hiểu vấn đề 6 | 7 | Thiết kế một dịch vụ rút gọn URL như trang [TinyURL](https://tinyurl.com/app). Đích đến là thiết kế một dịch vụ có khả năng mở rộng cao có thể cho phép nhiều người dùng tạo ra nhiều URL ngắn hơn từ chuỗi URL rất dài. 8 | 9 | ### TinyURL là gì? 10 | 11 | TinyURL là dịch vụ web rút gọn URL, nó tạo ra các URL với tên bí danh ngắn hơn thay thế cho URL rất dài. Bấy cứ khi nào người dùng đến với URL ngắn, nó sẽ tự động điều hướng sang các URL gốc. 12 | 13 | Trước khi đi đến giải pháp, chúng ta nên thảo luận về phạm vi và yêu cầu hệ thống về các tính năng cần có cho hệ thống. 14 | 15 | ## Yêu cầu hệ thống 16 | 17 | ### Các tính năng yêu cầu 18 | 19 | - Người dùng có thể tạo ra URL ngắn hơn từ các URL gốc. 20 | - Link ngắn tự động điều hướng đến link gốc. 21 | - Người dùng nên có tuỳ chỉnh để tạo một link ngắn theo ý của họ. 22 | 23 | ### Mục tiêu đạt được 24 | 25 | - Nếu hệ thống sập, điều đó có nghĩa là tất cả link ngắn hơn sẽ không hoạt động. Do đó, hệ thống của chúng ta phải có tính khả dụng cao. 26 | - Điều hướng phải là thời gian thực với độ trễ thấp. 27 | - Không được để tạo ra các link ngắn hơn nằm ngoài dự đoán. 28 | 29 | ### Mục tiêu mở rộng 30 | 31 | - Dịch vụ nên là REST API. 32 | - Thống kê: Bao nhiêu URL được truy cập? 33 | - Người dùng có thể chỉ định thời hạn của từng URL. 34 | 35 | ## Phân tích hệ thống 36 | 37 | Bây giờ ta sẽ xem qua các ước lượng cơ bản về hệ thống. Điều quan trọng cần nhớ là hệ thống của chúng ta sẽ thiên về **đọc dữ liệu**, các yêu cầu đọc có thể gấp hàng ngàn lần so với yêu cầu ghi. Do đó, ta giả sử tỉ lệ đọc/ghi sẽ là 100/1. 38 | 39 | #### Các thành phần chính 40 | 41 | Các thành phần chính trong ứng dụng rút gọn URL: 42 | 43 | 1. **Clients** - Trình duyệt Web/Ứng dụng di động. Giao tiếp với server thông qua giao thức HTTP. 44 | 2. **Load Balancer** - Để phân phối tải trên nhiều server. 45 | 3. **Web Servers** - Nhiều server sẽ được triển khai để mở rộng theo chiều ngang. 46 | 4. **Database** - Nó sẽ lưu các URL dài ánh xạ đến các URL ngắn. 47 | 48 | #### Ước lượng độ mở rộng 49 | 50 | - **Lưu lượng truy cập**: ta có thể giả sử ta có 500 triệu URL được tạo mỗi tháng, với tỉ lệ 100/1, ta có thể ước lượng là 50 tỉ điều hướng xuyên suốt thời điểm đó. -------------------------------------------------------------------------------- /examples/tinyurl/assets/base62-encoding.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/tinyurl/assets/base62-encoding.png -------------------------------------------------------------------------------- /examples/tinyurl/assets/cache.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/tinyurl/assets/cache.png -------------------------------------------------------------------------------- /examples/tinyurl/assets/databases-schema.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/tinyurl/assets/databases-schema.png -------------------------------------------------------------------------------- /examples/tinyurl/assets/design-a-url-shortening-service-like-tiny-url-cover.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/tinyurl/assets/design-a-url-shortening-service-like-tiny-url-cover.jpg -------------------------------------------------------------------------------- /examples/tinyurl/assets/example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/tinyurl/assets/example.png -------------------------------------------------------------------------------- /examples/tinyurl/assets/keys-offline.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/tinyurl/assets/keys-offline.png -------------------------------------------------------------------------------- /examples/tinyurl/assets/load-balancer.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/tinyurl/assets/load-balancer.png -------------------------------------------------------------------------------- /examples/tinyurl/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/tinyurl/assets/logo.png -------------------------------------------------------------------------------- /examples/tinyurl/assets/purging.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/tinyurl/assets/purging.png -------------------------------------------------------------------------------- /examples/tinyurl/assets/skeleton.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/tinyurl/assets/skeleton.png -------------------------------------------------------------------------------- /examples/tinyurl/assets/workflow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/tinyurl/assets/workflow.png -------------------------------------------------------------------------------- /examples/tinyurl/assets/workflow1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/tinyurl/assets/workflow1.png -------------------------------------------------------------------------------- /examples/tinyurl/assets/workflow2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/tinyurl/assets/workflow2.png -------------------------------------------------------------------------------- /examples/tinyurl/assets/workflow3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/tinyurl/assets/workflow3.png -------------------------------------------------------------------------------- /examples/tinyurl/assets/workflow4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/tinyurl/assets/workflow4.png -------------------------------------------------------------------------------- /examples/tinyurl/assets/workflow5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/tinyurl/assets/workflow5.png -------------------------------------------------------------------------------- /examples/tinyurl/assets/workflow6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/tinyurl/assets/workflow6.png -------------------------------------------------------------------------------- /examples/tinyurl/assets/workflow7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/tinyurl/assets/workflow7.png -------------------------------------------------------------------------------- /examples/tinyurl/assets/workflow8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/tinyurl/assets/workflow8.png -------------------------------------------------------------------------------- /examples/tinyurl/assets/workflow9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/tinyurl/assets/workflow9.png -------------------------------------------------------------------------------- /examples/twitter/assets/cache.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/twitter/assets/cache.png -------------------------------------------------------------------------------- /examples/twitter/assets/high-level-design.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/twitter/assets/high-level-design.png -------------------------------------------------------------------------------- /examples/twitter/assets/logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/twitter/assets/logo.jpg -------------------------------------------------------------------------------- /examples/twitter/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/twitter/assets/logo.png -------------------------------------------------------------------------------- /examples/twitter/assets/period.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/twitter/assets/period.png -------------------------------------------------------------------------------- /examples/typeahead-suggestion/assets/algorithm-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/typeahead-suggestion/assets/algorithm-1.png -------------------------------------------------------------------------------- /examples/typeahead-suggestion/assets/algorithm-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/typeahead-suggestion/assets/algorithm-2.png -------------------------------------------------------------------------------- /examples/typeahead-suggestion/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/typeahead-suggestion/assets/logo.png -------------------------------------------------------------------------------- /examples/typeahead-suggestion/assets/permanent.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/typeahead-suggestion/assets/permanent.png -------------------------------------------------------------------------------- /examples/uber/assets/design.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/uber/assets/design.png -------------------------------------------------------------------------------- /examples/uber/assets/logo.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/uber/assets/logo.jpeg -------------------------------------------------------------------------------- /examples/web-crawler/assets/detail-component-design.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/web-crawler/assets/detail-component-design.png -------------------------------------------------------------------------------- /examples/web-crawler/assets/high-level-design.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/web-crawler/assets/high-level-design.png -------------------------------------------------------------------------------- /examples/web-crawler/assets/logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/web-crawler/assets/logo.jpg -------------------------------------------------------------------------------- /examples/yelp/assets/design.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/yelp/assets/design.png -------------------------------------------------------------------------------- /examples/yelp/assets/grids.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/yelp/assets/grids.png -------------------------------------------------------------------------------- /examples/yelp/assets/logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/yelp/assets/logo.jpg -------------------------------------------------------------------------------- /examples/yelp/assets/quadtree.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/yelp/assets/quadtree.png -------------------------------------------------------------------------------- /examples/youtube/assets/detail-component.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/youtube/assets/detail-component.png -------------------------------------------------------------------------------- /examples/youtube/assets/high-level-design.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/youtube/assets/high-level-design.png -------------------------------------------------------------------------------- /examples/youtube/assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/youtube/assets/logo.png -------------------------------------------------------------------------------- /examples/youtube/assets/logo.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Ren0503/system-design/e6590ffab270b876cd25844f2edafc4e543b4ea6/examples/youtube/assets/logo.webp --------------------------------------------------------------------------------