Notes of the book System Desgin Interview - An Insider's Guide
Add Readme and fix formatting
Gaurav Kumar8bb95d0402bc
diff --git a/01. Scaling/Readme.md b/01. Scaling/Readme.mdnew file mode 100644index 0000000..77a65ad--- /dev/null+++ b/01. Scaling/Readme.md@@ -0,0 +1,239 @@+# Chapter 1: Scale from Zero to Millions of Users++## Introduction+Scaling a system to support millions of users is a complex, iterative journey requiring refinement and optimization. This chapter outlines how to begin with a single server setup and scale the architecture step by step to handle millions of users.++---++## Section 1: Single Server Setup+Initially, all components (web app, database, cache) run on a single server.++<div style="margin-left:3rem">+ <img src="./images/single-server.png" width="400" />+</div>++### Request Flow+1. Users access the application via domain names (e.g., `api.mysite.com`), resolved to IP addresses using DNS.+2. IP address of the web-server is returned to the browser or mobile app.+3. HTTP requests are sent to the web server, which returns HTML or JSON responses.++### Traffic Sources+1. **Web Applications:** Use server-side languages (e.g., Python, Java) for business logic and client-side languages (e.g., JavaScript, HTML) for presentation.+2. **Mobile Applications:** Communicate with the web server using HTTP and JSON for lightweight data exchange.++---++## Section 2: Database Separation+As the user base grows, the database is moved to a dedicated server to allow independent scaling of web and database tiers.++<div style="margin-left:3rem">+ <img src="./images/database.png" width="400" />+</div>++### Database Choices++1. **Relational Databases (SQL):** Structured data stored in tables. Examples: MySQL, PostgreSQL.+2. **Non-Relational Databases (NoSQL):** Suitable for unstructured data or low-latency requirements. Categories include:+ - Key-Value Stores+ - Graph Databases+ - Column Stores+ - Document Stores++- Non-relational databases might be the right choice if:+ - application requires super-low latency.+ - data is unstructured, or there is no relational data.+ - only need to serialize and deserialize data (JSON, XML, YAML, etc.).+ - need to store a massive amount of data.++---++## Section 3: Vertical vs Horizontal Scaling+### Vertical Scaling+- Adds more resources (CPU, RAM) to existing servers.+- Limited by hardware constraints and lacks redundancy.++### Horizontal Scaling+- Adds more servers to the pool, making it more suitable for large-scale systems.+- A load balancer is used to handle the request routing between the servers.+---++## Section 4: Load Balancer++<div style="margin-left:3rem">+ <img src="./images/load-balancer.png" width="400" />+</div>++A **load balancer** distributes traffic among multiple servers. Benefits include:+1. Redundancy: If a server goes offline, traffic is rerouted.+ - If server 1 goes offline, all the traffic will be routed to server 2.+2. Scalability: Easily add servers to handle traffic spikes.+ - If the website traffic grows rapidly, subsequent servers can be added to handle the additional traffic.++---++## Section 5: Database Replication++<div style="margin-left:3rem">+ <img src="./images/database-replication.png" width="400" />+</div>++### Master-Slave Model+- **Master Database:** Handles write operations.+ - All the data-modifying commands like insert, delete, or update must be sent to the master database.+- **Slave Databases:** Handle read operations, improving performance and reliability.+ - Since the ratio of reads to writes is higher is most applications; thus, the number of slave+databases in a system is usually larger than the number of master databases.++### Benefits+1. Improved performance through parallel read operations.+2. High availability and data reliability through redundancy.+++### Failure Handling+- If only one slave database is available and it goes offline, read operations will be directed+to the master database temporarily.+- In case multiple slave databases are available, read operations are+redirected to other healthy slave databases and a new server will replace the old one.+- If the master database goes offline, a slave database will be promoted to be the new+master.+- In production system the chosen slave database might not be up to date, hence data needs to be updated by running data+recovery scripts (methods like multi-masters and circular replication could help).++---++## Section 6: Caching+A **cache** stores frequently accessed data in memory to reduce database load. The cache tier is a temporary data store layer, much faster than the database.++<div style="margin-left:3rem">+ <img src="./images/cache.png" width="500" />+</div>++### Caching considerations+1. **Use case**: Consider using cache when data is read frequently but modified infrequently.+2. **Expiration Policies:** Once cached data is expired, it is removed from the cache. When there is no expiration policy, cached+data will be stored in the memory permanently.+3. **Consistency:** This means keeping the data store and the cache in sync. Inconsistency+can happen because data-modifying operations on the data store and cache are not in a single transaction.+4. **Mitigating failures**: A single cache server represents a potential single point of failure, multiple+cache servers across different data centers are recommended to avoid SPOF.+5. **Eviction Policies:**: Once the cache is full, items need to be evicted to free up memory. LRU is the most popular cache eviction policy.++---++## Section 7: Content Delivery Network (CDN)+A **CDN** improves load times by caching static content (images, CSS, JavaScript) on geographically distributed servers.++<div style="margin-left:3rem">+ <img src="./images/cdn.png" width="400" />+</div>++### Workflow+1. User requests content from the nearest CDN server.+2. If unavailable, content is fetched from the origin server and cached.+++### CDN considerations+1. **Cost:** CDNs are run by third-party providers which charge for data transfers in and out of the CDN.+2. **Cache Expiry:** The cache expiry time should neither be too long nor too short.+3. **CDN fallback:** If there is a temporary CDN outage, clients should be able to detect the problem+and request resources from the origin.+4. **Invalidating files:** If files are updated the cache should be invalidated to point to the updated files.++---++## Section 8: Stateless Web Tier+By moving session data to a shared datastore, web servers become stateless. This allows:+1. Easier horizontal scaling.+2. Auto-scaling based on traffic.++<div style="margin-left:3rem">+ <img src="./images/stateless.png" width="400" />+</div>++---++## Section 9: Multi-Data Center Setup+Deploying across multiple data centers improves availability and reduces latency. Strategies include:++<div style="margin-left:3rem">+ <img src="./images/data-center.png" width="400" />+</div>++1. **GeoDNS Routing:** Direct users to the nearest data center.+2. **Data Replication:** Synchronize data across centers to prevent inconsistencies.++### Key considerations+- **Traffic redirection:** Effective tools are needed to direct traffic to the correct data center.+- **Data synchronization:** A common strategy is to replicate data across multiple data centers.+- **Test and deployment:** Automated deployment tools are vital to keep services consistent through all the data centers.++---++## Section 10: Message Queue+A **message queue** is a durable component, stored in memory, that supports asynchronous+communication. It serves as a buffer and distributes asynchronous requests.++<div style="margin-left:3rem">+ <img src="./images//message-queue.png" width="500" />+</div>++- Input services, called producers/publishers, create messages, and publish them to a message queue.+- Other services called consumers/subscribers, connect to the queue, and perform actions defined by the messages.++---++## Section 11: Logging, Metrics, and Automation++<div style="margin-left:3rem">+ <img src="./images/logging.png" width="400" />+</div>++### Importance+1. **Logging:** Tracks errors and system health.+2. **Metrics:** Provides insights into performance and user activity.+3. **Automation:** Streamlines testing, deployment, and scaling.++---++## Section 12: Database Scaling+### Vertical Scaling+- Adds hardware resources but has physical and cost limitations.+- Has multiple drawbacks:+ - Greater risk of single point of failures.+ - Overall cost of vertical scaling is high++### Horizontal Scaling (Sharding)++<div style="margin-left:3rem">+ <img src="./images/horizontal-scaling.png" width="400" />+</div>++- Divides data across multiple shards using keys (e.g., `user_id`).+ - Sharding separates large databases into smaller, more easily managed parts called shards.+ - Each shard shares the same schema, though the actual data on each shard is unique to the shard.+- Sharding key is critical when implementing a sharding strategy. When choosing a sharding key it is important to choose a key that can evenly distribute data.++#### Challenges+1. **Resharding data:** Resharding data is needed when:+ - Single shard could no longer hold more data due to rapid growth.+ - Certain shards might experience shard exhaustion faster than others due to uneven data distribution.+ - Consistent Hashing is used to overcome these problems++2. **Celebrity problem:** Excessive access to a specific shard could cause server overload.+ - To solve this problem, we may need to allocate a shard for each celebrity.++3. **Join and de-normalization:** Once a database has been sharded across multiple servers, it is hard to perform join operations across database shards.+ - A common workaround is to de-normalize the database so that queries can be performed in a single table.++---++## Conclusion+### Key Takeaways+1. Keep the web tier stateless.+2. Build redundancy at every tier.+3. Use caching and CDNs to optimize performance.+4. Scale the data tier with sharding.+5. Decouple components for flexibility.++This chapter provides a solid foundation for building scalable systems that can handle millions of users.+diff --git a/01. Scaling/images/cache.png b/01. Scaling/images/cache.pngnew file mode 100644index 0000000..467e09eBinary files /dev/null and b/01. Scaling/images/cache.png differdiff --git a/01. Scaling/images/cdn.png b/01. Scaling/images/cdn.pngnew file mode 100644index 0000000..44b6ae5Binary files /dev/null and b/01. Scaling/images/cdn.png differdiff --git a/01. Scaling/images/data-center.png b/01. Scaling/images/data-center.pngnew file mode 100644index 0000000..e0e0987Binary files /dev/null and b/01. Scaling/images/data-center.png differdiff --git a/01. Scaling/images/database-replication.png b/01. Scaling/images/database-replication.pngnew file mode 100644index 0000000..996c558Binary files /dev/null and b/01. Scaling/images/database-replication.png differdiff --git a/01. Scaling/images/database.png b/01. Scaling/images/database.pngnew file mode 100644index 0000000..263d838Binary files /dev/null and b/01. Scaling/images/database.png differdiff --git a/01. Scaling/images/horizontal-scaling.png b/01. Scaling/images/horizontal-scaling.pngnew file mode 100644index 0000000..0d299ceBinary files /dev/null and b/01. Scaling/images/horizontal-scaling.png differdiff --git a/01. Scaling/images/load-balancer.png b/01. Scaling/images/load-balancer.pngnew file mode 100644index 0000000..7d0f43bBinary files /dev/null and b/01. Scaling/images/load-balancer.png differdiff --git a/01. Scaling/images/logging.png b/01. Scaling/images/logging.pngnew file mode 100644index 0000000..2ef0da5Binary files /dev/null and b/01. Scaling/images/logging.png differdiff --git a/01. Scaling/images/message-queue.png b/01. Scaling/images/message-queue.pngnew file mode 100644index 0000000..7948298Binary files /dev/null and b/01. Scaling/images/message-queue.png differdiff --git a/01. Scaling/images/single-server.png b/01. Scaling/images/single-server.pngnew file mode 100644index 0000000..e6d0bf6Binary files /dev/null and b/01. Scaling/images/single-server.png differdiff --git a/01. Scaling/images/statefull.png b/01. Scaling/images/statefull.pngnew file mode 100644index 0000000..09ee35fBinary files /dev/null and b/01. Scaling/images/statefull.png differdiff --git a/01. Scaling/images/stateless.png b/01. Scaling/images/stateless.pngnew file mode 100644index 0000000..89476aeBinary files /dev/null and b/01. Scaling/images/stateless.png differdiff --git a/02. Back Of the Envelope Estimation/Readme.md b/02. Back Of the Envelope Estimation/Readme.mdnew file mode 100644index 0000000..a166409--- /dev/null+++ b/02. Back Of the Envelope Estimation/Readme.md@@ -0,0 +1,98 @@+# Chapter 2: Back-of-the-Envelope Estimation++## Introduction+Back-of-the-envelope estimation is a crucial skill in system design interviews. It involves making quick, rough calculations to assess system capacity or performance. According to Jeff Dean, Google Senior Fellow, these estimates help evaluate whether designs meet requirements through thought experiments and common performance benchmarks.++This chapter covers key concepts, methodologies, and examples to build proficiency in scalability and estimation.++---++## Section 1: Key Concepts++### Power of Two+Understanding data volume in terms of powers of two is fundamental:++<img src="./images/power-of-two.png" alt="power-of-two" width="500" />++This knowledge helps in performing accurate storage and bandwidth calculations.++---++### Latency Numbers Every Programmer Should Know+Latency numbers represent the time taken for various operations in computing systems. These provide insights into relative performance:++| Operation | Latency (2020) |+|--------------------------|----------------|+| L1 Cache Access | 0.5 ns |+| L2 Cache Access | 7 ns |+| Main Memory Access | 100 ns |+| SSD Random Read | 150 µs |+| HDD Random Seek | 10 ms |+| Round-Trip in Data Center| 500 µs |+| Inter-Region Data Center | 150 ms |++**Key Insights:**+- Memory is fast, disk is slow.+- Avoid disk seeks whenever possible.+- Compress data before transmitting over the internet to save bandwidth.+++---++### Availability Numbers+High availability (HA) ensures minimal downtime. Availability is expressed in **nines**:+- **99% (Two Nines):** ~3.65 days/year of downtime+- **99.9% (Three Nines):** ~8.8 hours/year of downtime+- **99.99% (Four Nines):** ~52 minutes/year of downtime+- **99.999% (Five Nines):** ~5.3 minutes/year of downtime+- **99.9999% (Six Nines):** ~31.56 seconds/year of downtime+++Cloud providers like Amazon, Google, and Microsoft aim for SLAs (Service Level Agreements) of **99.9% or higher**.++---++## Section 2: Example Estimation - Twitter QPS and Storage Requirements++### Assumptions+- **300 million monthly active users (MAU).**+- **50% daily active users (DAU).**+- **Average tweets/user/day:** 2.+- **10% of tweets contain media.**+- **Data retention:** 5 years.++### Estimations+1. **Query Per Second (QPS):**+ - DAU = \( 300M x 50\% = 150M \)+ - Tweets QPS = \( 150M x 2 tweets / 24 hour / 3600 seconds = ~3500 )+ - Peak QPS = \( 2 x 3500 = ~7000 \)++2. **Media Storage:**+ - **Tweet Size Components:**+ - `tweet_id`: 64 bytes+ - `text`: 140 bytes+ - `media`: 1 MB+ - **Daily Media Storage:** \( 150M x 2 x 10\% x 1MB = 30TB per day \)+ - **5-Year Storage:** \( 30TB x 365 x 5 = ~55PB \)++---++## Section 3: Tips for Effective Estimation++### 1. Rounding and Approximation+Precision is not critical; focus on the process. Simplify complex calculations using round numbers. For example:+- \( 99987 / 9.1 \) can be approximated as \( 100,000 / 10 = 10,000 \).++### 2. Write Down Assumptions+Document assumptions clearly for future reference.++### 3. Label Units+Avoid ambiguity by labeling units (e.g., `5 MB` instead of `5`).++### 4. Common Estimation Scenarios+- **QPS (Queries Per Second):** Measure traffic intensity.+- **Peak QPS:** Account for traffic spikes.+- **Storage Requirements:** Estimate total data needs.+- **Cache Requirements:** Evaluate memory requirements for caching.+- **Number of Servers:** Calculate hardware needs based on workload.+diff --git a/02. Back Of the Envelope Estimation/images/power-of-two.png b/02. Back Of the Envelope Estimation/images/power-of-two.pngnew file mode 100644index 0000000..b9866a4Binary files /dev/null and b/02. Back Of the Envelope Estimation/images/power-of-two.png differdiff --git a/03. System Design Framework/Readme.md b/03. System Design Framework/Readme.mdnew file mode 100644index 0000000..b8267a5--- /dev/null+++ b/03. System Design Framework/Readme.md@@ -0,0 +1,115 @@+# Chapter 3: A Framework for System Design Interviews++## Introduction+System design interviews are a key part of the hiring process, simulating real-life problem-solving scenarios. These interviews evaluate not just technical skills but also collaboration, communication, and the ability to handle ambiguous requirements.++This chapter introduces a **4-step framework** for navigating system design interviews effectively.++---++## Step 1: Understand the Problem and Establish Design Scope++### Key Objectives+- Clarify requirements and assumptions.+- Avoid jumping into solutions prematurely.+- Showcase critical thinking by asking good questions.++### Approach+- **Ask Clarifying Questions:**+ - What are the most important features?+ - What scale does the system need to handle?+ - Are we building for web, mobile, or both?+ - Are there existing technologies or constraints?++- **Document Assumptions:** Write assumptions on a whiteboard or paper for reference.++### Example+**Problem:** Design a news feed system.+**Questions:**+- Is it a mobile app, web app, or both?+- How many friends can a user have?+- Should the feed include images and videos?+- Is the feed sorted by reverse chronological order?++---++## Step 2: Propose High-Level Design and Get Buy-In++### Key Objectives+- Develop a high-level architecture.+- Collaborate with the interviewer to refine the design.++### Approach+- **Draft a Blueprint:**+ - Use box diagrams for key components (e.g., clients, APIs, databases, caches, CDNs).+ - Treat the interviewer as a teammate to refine the design.++- **Perform Back-of-the-Envelope Calculations:**+ - Ensure the design can handle the scale constraints.++- **Walk Through Use Cases:** Identify edge cases and validate design assumptions.++### Example+For a news feed system, divide the design into:+1. **Feed Publishing Flow:** Writing posts into databases and populating friends' feeds.+2. **Feed Retrieval Flow:** Aggregating and displaying friends' posts in reverse chronological order.++---++## Step 3: Design Deep Dive++### Key Objectives+- Dive into critical components.+- Showcase depth of understanding and adaptability.++### Approach+- **Prioritize Key Components:** Focus on areas most relevant to the problem.+- **Discuss Bottlenecks:** Identify potential performance issues and propose solutions.+- **Balance Detail:** Avoid over-engineering or unnecessary deep dives.++### Example Topics+- **URL Shortener:** Focus on hash function design.+- **Chat System:** Explore latency reduction and online/offline status handling.+- **News Feed System:** Examine feed publishing and retrieval processes.++---++## Step 4: Wrap-Up++### Key Objectives+- Highlight areas for improvement.+- Recap the design and discuss follow-ups.++### Approach+- **Identify Bottlenecks:** Discuss potential limitations and scaling strategies.+- **Summarize Design:** Recap major design decisions and trade-offs.+- **Propose Enhancements:**+ - How to scale from 1 million to 10 million users.+ - Error handling for server failures or network issues.++---++## Best Practices++### Dos+- **Ask Questions:** Clarify ambiguities before diving into solutions.+- **Communicate:** Share your thought process with the interviewer.+- **Iterate with the Interviewer:** Treat them as a collaborator.+- **Show Flexibility:** Suggest alternative approaches and refine your design.+- **Focus on Critical Components:** Prioritize key parts of the system.++### Don’ts+- **Avoid Premature Solutions:** Don’t design before understanding the requirements.+- **Don’t Go Silent:** Communicate regularly during the process.+- **Avoid Over-Engineering:** Focus on practical, scalable solutions.++---++## Time Management++### Suggested Time Allocation (for 45-Minute Interviews):+1. **Understand Problem and Scope:** 3–10 minutes+2. **High-Level Design and Buy-In:** 10–15 minutes+3. **Deep Dive:** 10–25 minutes+4. **Wrap-Up:** 3–5 minutes+diff --git a/rate-limiter/Readme.md b/04. Rate Limiter/Readme.mdsimilarity index 77%rename from rate-limiter/Readme.mdrename to 04. Rate Limiter/Readme.mdindex 3d81dd6..4cd7c28 100644--- a/rate-limiter/Readme.md+++ b/04. Rate Limiter/Readme.md@@ -26,11 +26,14 @@ This chapter explores the design and implementation of a rate limiter—a system## Step 2: High-Level Design### Placement Options+<div style="margin-left:2rem">+ <img src="./images/rate_limiter_architecture.png" alt="Rate Limiting Middleware Architecture" width="550">+</div>+1. **Client-Side Implementation:** Unreliable due to potential misuse.2. **Server-Side Implementation:** Preferred for control and reliability.3. **Middleware (API Gateway):** A flexible option for integrated rate limiting.- <img src="./images/rate_limiter_architecture.png" style="margin-left: 40px; margin-top: 20px; margin-bottom: 20px;" alt="Rate Limiting Middleware Architecture" width="500">### Guidelines for Placement- Evaluate current tech stack and choose efficient options.@@ -40,65 +43,80 @@ This chapter explores the design and implementation of a rate limiter—a system## Step 3: Rate Limiting Algorithms### 1. Token Bucket+<div style="margin-left:2rem">+ <img src="./images/token-bucket.png" alt="Token Bucket Algorithm" width="550">+</div>+- **Description:** Tokens are added to a bucket at a fixed rate; each request consumes a token.- **Parameters:** Bucket size and refill rate.- **Pros:** Easy to implement, memory-efficient, supports traffic bursts.- **Cons:** Requires careful parameter tuning.- <img src="./images/token-bucket.png" style="margin-left: 40px; margin-top: 20px; margin-bottom: 20px;" alt="Token Bucket Algorithm" width="500">### 2. Leaking Bucket+<div style="margin-left:2rem">+ <img src="./images/leaking-bucket.png" alt="Leaking Bucket Algorithm" width="550">+</div>+- **Description:** Processes requests at a fixed rate using a FIFO queue.- **Pros:** Memory-efficient, stable outflow rate.- **Cons:** Traffic bursts may delay recent requests.- <img src="./images/leaking-bucket.png" style="margin-left: 40px; margin-top: 20px; margin-bottom: 20px;" alt="Leaking Bucket Algorithm" width="500">Example: https://github.com/uber-go/ratelimit### 3. Fixed Window Counter+<div style="margin-left:2rem">+ <img src="./images/fixed-window-counter.png" alt="Fixed Window Counter" width="550">+</div>+- **Description:** Divides time into fixed intervals and uses counters to limit requests.- **Pros:** Simple, efficient for specific use cases.- **Cons:** Traffic spikes at window edges can exceed limits.- <img src="./images/fixed-window-counter.png" style="margin-left: 40px; margin-top: 20px; margin-bottom: 20px;" alt="Fixed Window Counter" width="500">--- Sudden burst of traffic at the edges of time windowscould cause more requests than allowed quota to go through.- <img src="./images/fixed-window-issue.png" style="margin-left: 40px; margin-top: 20px; margin-bottom: 20px;" alt="Fixed Window Issue" width="500">+ <img src="./images/fixed-window-issue.png" alt="Fixed Window Issue" width="550">### 4. Sliding Window Log+<div style="margin-left:2rem">+ <img src="./images/sliding-window-log.png" alt="Sliding Window Log" width="550">+</div>+- **Description:** Tracks timestamps to allow a rolling time window.- **Pros:** Accurate rate limiting.- **Cons:** High memory consumption.- <img src="./images/sliding-window-log.png" style="margin-left: 40px; margin-top: 20px; margin-bottom: 20px;" alt="Sliding Window Log" width="500">### 5. Sliding Window Counter+<div style="margin-left:2rem">+ <img src="./images/sliding-window-counter.png" alt="Fixed Window Counter" width="550">+</div>+- **Description:** Combines fixed window and sliding log methods for smoothing spikes.- **Pros:** Memory-efficient, handles traffic bursts.- **Cons:** Approximation may not be perfectly strict.- <img src="./images/sliding-window-counter.png" style="margin-left: 40px; margin-top: 20px; margin-bottom: 20px;" alt="Fixed Window Counter" width="500">## High-Level Architecture+<div style="margin-left:2rem">+ <img src="./images/architecture.png" style="margin-left: 40px; margin-top: 40px; margin-bottom: 20px;" alt="Architecture" width="550">+</div>+- **Data Storage:** Use in-memory caching (e.g., Redis) for fast counter operations.- **Steps:**1. Client sends request to middleware.2. Middleware checks counters in Redis.3. Request is processed or rejected based on limits.- <img src="./images/architecture.png" style="margin-left: 40px; margin-top: 40px; margin-bottom: 20px;" alt="Architecture" width="500">-## Advanced Considerations### Distributed Environmentsdiff --git a/rate-limiter/images/architecture.png b/04. Rate Limiter/images/architecture.pngsimilarity index 100%rename from rate-limiter/images/architecture.pngrename to 04. Rate Limiter/images/architecture.pngdiff --git a/rate-limiter/images/fixed-window-counter.png b/04. Rate Limiter/images/fixed-window-counter.pngsimilarity index 100%rename from rate-limiter/images/fixed-window-counter.pngrename to 04. Rate Limiter/images/fixed-window-counter.pngdiff --git a/rate-limiter/images/fixed-window-issue.png b/04. Rate Limiter/images/fixed-window-issue.pngsimilarity index 100%rename from rate-limiter/images/fixed-window-issue.pngrename to 04. Rate Limiter/images/fixed-window-issue.pngdiff --git a/rate-limiter/images/leaking-bucket.png b/04. Rate Limiter/images/leaking-bucket.pngsimilarity index 100%rename from rate-limiter/images/leaking-bucket.pngrename to 04. Rate Limiter/images/leaking-bucket.pngdiff --git a/rate-limiter/images/rate_limiter_architecture.png b/04. Rate Limiter/images/rate_limiter_architecture.pngsimilarity index 100%rename from rate-limiter/images/rate_limiter_architecture.pngrename to 04. Rate Limiter/images/rate_limiter_architecture.pngdiff --git a/rate-limiter/images/sliding-window-counter.png b/04. Rate Limiter/images/sliding-window-counter.pngsimilarity index 100%rename from rate-limiter/images/sliding-window-counter.pngrename to 04. Rate Limiter/images/sliding-window-counter.pngdiff --git a/rate-limiter/images/sliding-window-log.png b/04. Rate Limiter/images/sliding-window-log.pngsimilarity index 100%rename from rate-limiter/images/sliding-window-log.pngrename to 04. Rate Limiter/images/sliding-window-log.pngdiff --git a/rate-limiter/images/token-bucket.png b/04. Rate Limiter/images/token-bucket.pngsimilarity index 100%rename from rate-limiter/images/token-bucket.pngrename to 04. Rate Limiter/images/token-bucket.pngdiff --git a/consistent-hashing/Readme.md b/05. Consistent Hashing/Readme.mdsimilarity index 73%rename from consistent-hashing/Readme.mdrename to 05. Consistent Hashing/Readme.mdindex 0f55e84..1e3322c 100644--- a/consistent-hashing/Readme.md+++ b/05. Consistent Hashing/Readme.md@@ -9,11 +9,11 @@ In traditional hashing methods, such as `serverIndex = hash(key) % N`, data redi- Removing a server causes most keys to be reassigned, leading to cache misses.- Adding a server results in unnecessary key redistributions.- <img src="./images/server-hashing.png" style="margin-left: 40px; margin-top: 20px; margin-bottom: 20px;" alt="Server hashing" width="400">+ <img src="./images/server-hashing.png" alt="Server hashing" width="450">- This approach works well when the size of the server pool is fixed. However, problems arise when new servers are added, or existing servers are removed.- <img src="./images/server-hashing-miss.png" style="margin-left: 40px; margin-top: 20px; margin-bottom: 20px;" alt="Server hashing" width="400">+ <img src="./images/server-hashing-miss.png" alt="Server hashing Miss" width="450">### Key IssueRedistribution of most keys when server count changes causes inefficiency and overload.@@ -25,33 +25,33 @@ Consistent hashing ensures that only a fraction of keys are remapped when server### Key Concepts1. **Hash Space and Ring:** The hash space forms a continuous ring, with hash values distributed from `0` to `2^160-1` (e.g., using hash function like SHA-1). By connecting both ends we get a ring.<p align="center">- <img src="./images/hash-ring.png" style="margin-left: 40px; margin-top: 20px; margin-bottom: 20px;" alt="Server hashing" width="400">+ <img src="./images/hash-ring.png" alt="Hash Ring" width="450"></p>- Using the same hash function f, we map servers based on server IP or name onto the ring.<p align="center">- <img src="./images/server-ring.png" style="margin-left: 40px; margin-top: 20px; margin-bottom: 20px;" alt="Server hashing" width="400">+ <img src="./images/server-ring.png" alt="Server Ring" width="450"></p>1. **Server Lookup**- A key's server is determined by traversing clockwise on the ring until a server is found.<p align="center">- <img src="./images/server-lookup.png" style="margin-left: 40px; margin-top: 20px; margin-bottom: 20px;" alt="Server hashing" width="400">+ <img src="./images/server-lookup.png" alt="Server Lookup" width="450"></p>2. **Adding and Removing Servers**- Adding a server redistributes only nearby keys. Only a fraction of keys are redistributed to the new server.<p align="center">- <img src="./images/adding-server.png" style="margin-left: 40px; margin-top: 20px; margin-bottom: 20px;" alt="Server hashing" width="400">+ <img src="./images/adding-server.png" alt="Adding Server" width="450"></p>- Removing a server affects only the keys in its range. Only keys from the removed server are reassigned to the next server clockwise.<p align="center">- <img src="./images/removing-server.png" style="margin-left: 40px; margin-top: 20px; margin-bottom: 20px;" alt="Server hashing" width="400">+ <img src="./images/removing-server.png" alt="Removing Server" width="450"></p>## Challenges and Solutions@@ -64,7 +64,7 @@ Consistent hashing ensures that only a fraction of keys are remapped when server- Virtual nodes improve key distribution and balance load. As the number of virtual nodes increases, the distribution of keys becomes more balanced. This is because the standard deviation gets smaller with more virtual nodes, leading to balanced data distribution.<p align="center">- <img src="./images/virtual-nodes.png" style="margin-top: 20px; margin-bottom: 20px;" alt="Server hashing" width="400">+ <img src="./images/virtual-nodes.png" alt="Virtual Nodes" width="450"></p>## Affected Keys@@ -75,14 +75,14 @@ When servers are added or removed:located between s3 and s4 need to be redistributed to s4.<p align="center">- <img src="./images/server-addition.png" style="margin-top: 20px; margin-bottom: 20px;" alt="Server hashing" width="400">+ <img src="./images/server-addition.png" alt="Server Addition" width="450"></p>- **Removed Server:** Affected keys are those between the removed server and its predecessor. In the following example when a server (s1) is removed, the affected range starts from s1(removed node) and moves anticlockwise around the ring until a server is found (s0). Thus, keys located between s0 and s1 must be redistributed to s2.<p align="center">- <img src="./images/server-removed.png" style="margin-top: 20px; margin-bottom: 20px;" alt="Server hashing" width="400">+ <img src="./images/server-removed.png" alt="Server Removed" width="450"></p>## Benefits of Consistent Hashingdiff --git a/consistent-hashing/images/adding-server.png b/05. Consistent Hashing/images/adding-server.pngsimilarity index 100%rename from consistent-hashing/images/adding-server.pngrename to 05. Consistent Hashing/images/adding-server.pngdiff --git a/consistent-hashing/images/hash-ring.png b/05. Consistent Hashing/images/hash-ring.pngsimilarity index 100%rename from consistent-hashing/images/hash-ring.pngrename to 05. Consistent Hashing/images/hash-ring.pngdiff --git a/consistent-hashing/images/removing-server.png b/05. Consistent Hashing/images/removing-server.pngsimilarity index 100%rename from consistent-hashing/images/removing-server.pngrename to 05. Consistent Hashing/images/removing-server.pngdiff --git a/consistent-hashing/images/server-addition.png b/05. Consistent Hashing/images/server-addition.pngsimilarity index 100%rename from consistent-hashing/images/server-addition.pngrename to 05. Consistent Hashing/images/server-addition.pngdiff --git a/consistent-hashing/images/server-hashing-miss.png b/05. Consistent Hashing/images/server-hashing-miss.pngsimilarity index 100%rename from consistent-hashing/images/server-hashing-miss.pngrename to 05. Consistent Hashing/images/server-hashing-miss.pngdiff --git a/consistent-hashing/images/server-hashing.png b/05. Consistent Hashing/images/server-hashing.pngsimilarity index 100%rename from consistent-hashing/images/server-hashing.pngrename to 05. Consistent Hashing/images/server-hashing.pngdiff --git a/consistent-hashing/images/server-lookup.png b/05. Consistent Hashing/images/server-lookup.pngsimilarity index 100%rename from consistent-hashing/images/server-lookup.pngrename to 05. Consistent Hashing/images/server-lookup.pngdiff --git a/consistent-hashing/images/server-removed.png b/05. Consistent Hashing/images/server-removed.pngsimilarity index 100%rename from consistent-hashing/images/server-removed.pngrename to 05. Consistent Hashing/images/server-removed.pngdiff --git a/consistent-hashing/images/server-ring.png b/05. Consistent Hashing/images/server-ring.pngsimilarity index 100%rename from consistent-hashing/images/server-ring.pngrename to 05. Consistent Hashing/images/server-ring.pngdiff --git a/consistent-hashing/images/virtual-nodes.png b/05. Consistent Hashing/images/virtual-nodes.pngsimilarity index 100%rename from consistent-hashing/images/virtual-nodes.pngrename to 05. Consistent Hashing/images/virtual-nodes.pngdiff --git a/key-value-store/Readme.md b/06. Key-Value Store/Readme.mdsimilarity index 86%rename from key-value-store/Readme.mdrename to 06. Key-Value Store/Readme.mdindex 7c55b37..149c07f 100644--- a/key-value-store/Readme.md+++ b/06. Key-Value Store/Readme.md@@ -36,7 +36,7 @@ A **distributed key-value store** partitions data across multiple servers and mu**Trade-off:** According to CAP theorem only two of the three guarantees can be achieved.<p align="center">- <img src="./images/cap.png" alt="CAP" width="350">+ <img src="./images/cap.png" alt="CAP" width="400"></p>#### System Types:@@ -50,7 +50,7 @@ A **distributed key-value store** partitions data across multiple servers and muany data written to nodes n1 or n2 cannot be propagated to n3. Conversely, if data is written to n3 but not yet propagated to n1 and n2, nodes n1 and n2 will have stale data.<p align="center">- <img src="./images/server-down.png" alt="Server down" width="350">+ <img src="./images/server-down.png" alt="Server down" width="400"></p>- If we choose CP system, we must block all write operations to n1 and n2 to avoid data inconsistency.- If we choose AP system, the system keeps accepting reads, even though it might return stale data.@@ -104,8 +104,8 @@ vector locks are used to solve inconsistency problems.- Use **vector clocks** to track data versions and resolve conflicts.- Versioning means treating each data modification as a new immutable version of data.<div>- <img src="./images/consistent-server.png" style="margin-left: 40px; margin-top: 20px; margin-bottom: 20px;" alt="Consisten hashing" width="300">- <img src="./images/inconsistent-server.png" style="margin-left: 40px; margin-top: 20px; margin-bottom: 20px;" alt="Inconsistent server" height="175">+ <img src="./images/consistent-server.png" alt="Consisten hashing" width="400">+ <img src="./images/inconsistent-server.png" alt="Inconsistent server" height="230"></div>- Server 1 changes the name , and server 2 also changes the name. These two changes are performed simultaneously. Now, we have conflicting values, called versions v1 and v2.@@ -129,7 +129,7 @@ vector locks are used to solve inconsistency problems.4. **Conflict Resolution:** When conflicts are detected (sibling versions), the system relies on application-specific logic or client intervention to reconcile the data.<p align="center">- <img src="./images/vector-clock.png" style="margin-left: 40px; margin-top: 20px; margin-bottom: 20px;" alt="Server hashing" width="300">+ <img src="./images/vector-clock.png" alt="Server hashing" width="500"></p>- **Challenges:**@@ -142,24 +142,30 @@ vector locks are used to solve inconsistency problems.#### a. Failure DetectionIt is insufficient to believe that a server is down because another server says so.Usually, it requires at least two independent sources of information to mark a server down.- **Gossip Protocol:**+ <div style="margin-left:3rem">+ <img src="./images/gossip-protocol.png" alt="Gossip protocol" width="600">+ </div>+- Each node maintains member IDs and heartbeat counters.- Each node periodically increments its heartbeat counter.- Each node periodically sends heartbeats to a set of random nodes.- If the heartbeat has not increased for more than predefined periods, the member isconsidered as offline- <img src="./images/gossip-protocol.png" alt="Gossip protocol" width="600">+#### b. Temporary Failures- **Sloppy Quorum:** Use healthy nodes to maintain operations temporarily.+ <p align="center">+ <img src="./images/sloppy-quorum.png" alt="Sloppy Quorum" width="400">+ </p>+- After detecting failures, the system needs to deploy certain mechanisms to ensure availability- Instead of enforcing the quorum requirement, the system chooses the first W healthy servers for writes and first Rhealthy servers for reads on the hash ring.- Offline servers are ignored. If a server is unavailable, another server will process requests temporarily- <p align="center">- <img src="./images/sloppy-quorum.png" alt="Sloppy Quorum" width="400">- </p>+- **Hinted Handoff:** Offline servers catch up with changes upon recovery.- When the down server is up, changes will be pushed back to achieve data consistency@@ -176,19 +182,19 @@ It is insufficient to believe that a server is down because another server says2. **Building a Merkle Tree:**- **Step 1:** Divide the key space into buckets.- <img src="./images/key-bucket.png" style="margin-left: 40px; margin-top: 20px; margin-bottom: 20px;" alt="Key Bucket" width="300">+ <img src="./images/key-bucket.png" alt="Key Bucket" width="500">- **Step 2:** Hash each key in a bucket using uniform hashing.- <img src="./images/hash-key-bucket.png" style="margin-left: 40px; margin-top: 20px; margin-bottom: 20px;" alt="Hash Key Bucket" width="400">+ <img src="./images/hash-key-bucket.png" alt="Hash Key Bucket" width="500">- **Step 3:** Create a single hash for each bucket.- <img src="./images/hash-bucket.png" style="margin-left: 40px; margin-top: 20px; margin-bottom: 20px;" alt="Hash Bucket" width="350">+ <img src="./images/hash-bucket.png" alt="Hash Bucket" width="500">- **Step 4:** Combine hashes of buckets to compute higher-level hashes, culminating in the root hash.- <img src="./images/merkel-tree.png" style="margin-left: 40px; margin-top: 20px; margin-bottom: 20px;" alt="Merkel Tree" width="400">+ <img src="./images/merkel-tree.png" alt="Merkel Tree" width="500">@@ -212,23 +218,37 @@ It is insufficient to believe that a server is down because another server says## Write and Read Paths### 1. Write Path (Based on Cassandra architecture)++<div style="margin-left:3rem">+ <img src="./images/write-path.png" alt="Hash Bucket" width="500">+</div>+- Persist the write in a **commit log**.- Save data to a **memory cache**.- Flush data to **SSTable** (Sorted String Table) on disk when cache is full.- <img src="./images/write-path.png" style="margin-left: 40px; margin-top: 20px; margin-bottom: 20px;" alt="Hash Bucket" width="400">+### 2. Read Path+<div style="margin-left:3rem">+ <img src="./images/read-path.png" alt="Hash Bucket" width="500">+ <img src="./images/read-path-without-cache.png" alt="Hash Bucket" width="500">+</div>+- Check **memory cache** for the data.- If absent, use a **Bloom Filter** to locate the data in SSTables.- Retrieve and return the data.- <img src="./images/read-path.png" style="margin-left: 40px; margin-top: 20px; margin-bottom: 20px;" alt="Hash Bucket" width="400">- <img src="./images/read-path-without-cache.png" style="margin-left: 40px; margin-top: 20px; margin-bottom: 20px;" alt="Hash Bucket" width="400">---## Final Architecture++<p align="center">+<img src="./images/final-architecture.png" alt="Hash Bucket" width="500">+</p>++- Clients communicate with the key-value store through simple APIs: get(key) and put(key,value).- A coordinator is a node that acts as a proxy between the client and the key-value store.@@ -236,6 +256,5 @@ value).- The system is completely decentralized so adding and moving nodes can be automatic.- Data is replicated at multiple nodes.- There is no single point of failure as every node has the same set of responsibilities.- <p align="center">- <img src="./images/final-architecture.png" style="margin-left: 40px; margin-top: 20px; margin-bottom: 20px;" alt="Hash Bucket" width="500">- </p>++diff --git a/key-value-store/images/cap.png b/06. Key-Value Store/images/cap.pngsimilarity index 100%rename from key-value-store/images/cap.pngrename to 06. Key-Value Store/images/cap.pngdiff --git a/key-value-store/images/consistent-server.png b/06. Key-Value Store/images/consistent-server.pngsimilarity index 100%rename from key-value-store/images/consistent-server.pngrename to 06. Key-Value Store/images/consistent-server.pngdiff --git a/key-value-store/images/data-replication.png b/06. Key-Value Store/images/data-replication.pngsimilarity index 100%rename from key-value-store/images/data-replication.pngrename to 06. Key-Value Store/images/data-replication.pngdiff --git a/key-value-store/images/final-architecture.png b/06. Key-Value Store/images/final-architecture.pngsimilarity index 100%rename from key-value-store/images/final-architecture.pngrename to 06. Key-Value Store/images/final-architecture.pngdiff --git a/key-value-store/images/gossip-protocol.png b/06. Key-Value Store/images/gossip-protocol.pngsimilarity index 100%rename from key-value-store/images/gossip-protocol.pngrename to 06. Key-Value Store/images/gossip-protocol.pngdiff --git a/key-value-store/images/hash-bucket.png b/06. Key-Value Store/images/hash-bucket.pngsimilarity index 100%rename from key-value-store/images/hash-bucket.pngrename to 06. Key-Value Store/images/hash-bucket.pngdiff --git a/key-value-store/images/hash-key-bucket.png b/06. Key-Value Store/images/hash-key-bucket.pngsimilarity index 100%rename from key-value-store/images/hash-key-bucket.pngrename to 06. Key-Value Store/images/hash-key-bucket.pngdiff --git a/key-value-store/images/inconsistent-server.png b/06. Key-Value Store/images/inconsistent-server.pngsimilarity index 100%rename from key-value-store/images/inconsistent-server.pngrename to 06. Key-Value Store/images/inconsistent-server.pngdiff --git a/key-value-store/images/key-bucket.png b/06. Key-Value Store/images/key-bucket.pngsimilarity index 100%rename from key-value-store/images/key-bucket.pngrename to 06. Key-Value Store/images/key-bucket.pngdiff --git a/key-value-store/images/merkel-tree.png b/06. Key-Value Store/images/merkel-tree.pngsimilarity index 100%rename from key-value-store/images/merkel-tree.pngrename to 06. Key-Value Store/images/merkel-tree.pngdiff --git a/key-value-store/images/quorum-consensus.png b/06. Key-Value Store/images/quorum-consensus.pngsimilarity index 100%rename from key-value-store/images/quorum-consensus.pngrename to 06. Key-Value Store/images/quorum-consensus.pngdiff --git a/key-value-store/images/read-path-without-cache.png b/06. Key-Value Store/images/read-path-without-cache.pngsimilarity index 100%rename from key-value-store/images/read-path-without-cache.pngrename to 06. Key-Value Store/images/read-path-without-cache.pngdiff --git a/key-value-store/images/read-path.png b/06. Key-Value Store/images/read-path.pngsimilarity index 100%rename from key-value-store/images/read-path.pngrename to 06. Key-Value Store/images/read-path.pngdiff --git a/key-value-store/images/server-down.png b/06. Key-Value Store/images/server-down.pngsimilarity index 100%rename from key-value-store/images/server-down.pngrename to 06. Key-Value Store/images/server-down.pngdiff --git a/key-value-store/images/sloppy-quorum.png b/06. Key-Value Store/images/sloppy-quorum.pngsimilarity index 100%rename from key-value-store/images/sloppy-quorum.pngrename to 06. Key-Value Store/images/sloppy-quorum.pngdiff --git a/key-value-store/images/vector-clock.png b/06. Key-Value Store/images/vector-clock.pngsimilarity index 100%rename from key-value-store/images/vector-clock.pngrename to 06. Key-Value Store/images/vector-clock.pngdiff --git a/key-value-store/images/write-path.png b/06. Key-Value Store/images/write-path.pngsimilarity index 100%rename from key-value-store/images/write-path.pngrename to 06. Key-Value Store/images/write-path.pngdiff --git a/unique-id-generator/Readme.md b/07. Unique-Id Generator/Readme.mdsimilarity index 92%rename from unique-id-generator/Readme.mdrename to 07. Unique-Id Generator/Readme.mdindex be84141..2a8ef37 100644--- a/unique-id-generator/Readme.md+++ b/07. Unique-Id Generator/Readme.md@@ -22,7 +22,7 @@ This chapter addresses the challenge of designing a **unique ID generator** for- **Approach:** Use database `auto_increment` with step increments (e.g., `+k` for k servers).<p align="left">- <img src="./images/multi-master.png" alt="Multi Master" width="300">+ <img src="./images/multi-master.png" alt="Multi Master" width="400"></p>- **Drawbacks:**@@ -36,7 +36,7 @@ This chapter addresses the challenge of designing a **unique ID generator** for- UUIDs can be generated independently without coordination between servers<p align="left">- <img src="./images/uuid.png" alt="UUID generator" width="500">+ <img src="./images/uuid.png" alt="UUID generator" width="600"></p>- **Advantages:**@@ -63,6 +63,14 @@ This chapter addresses the challenge of designing a **unique ID generator** for### 4. Twitter Snowflake Approach- **Approach:**++ <div style="margin-left:3rem">+ <img src="./images/twitter-snowflake.png" alt="Snowflake approach" width="500">+ </div>+ <div style="margin-left:3rem">+ <img src="./images/snowflake-id-breakdown.png" alt="Snowflake ID breakdow" width="500">+ </div>+- Divide IDs into sections to ensure uniqueness and scalability.- **Sign Bit (1 bit):** Always `0`, potentially distinguishing signed and unsigned numbers.- **Timestamp (41 bits):** Milliseconds since a custom epoch (Twitter's default is `1288834974657`, equivalent to Nov 04, 2010, 01:42:54 UTC). Ensures IDs are time-ordered.@@ -70,12 +78,7 @@ This chapter addresses the challenge of designing a **unique ID generator** for- **Machine ID (5 bits):** Identifies up to `2^5 = 32` machines within each datacenter.- **Sequence Number (12 bits):** Tracks IDs generated on a machine within the same millisecond, supporting up to `2^12 = 4096` IDs per millisecond. The sequence resets to `0` every millisecond.- <p align="left">- <img src="./images/twitter-snowflake.png" alt="Snowflake approach" width="500">- </p>- <p align="left">- <img src="./images/snowflake-id-breakdown.png" alt="Snowflake ID breakdow" width="500">- </p>+- **Advantages:**- **Scalability:** Handles 10,000+ IDs per second across multiple servers.diff --git a/unique-id-generator/images/multi-master.png b/07. Unique-Id Generator/images/multi-master.pngsimilarity index 100%rename from unique-id-generator/images/multi-master.pngrename to 07. Unique-Id Generator/images/multi-master.pngdiff --git a/unique-id-generator/images/snowflake-id-breakdown.png b/07. Unique-Id Generator/images/snowflake-id-breakdown.pngsimilarity index 100%rename from unique-id-generator/images/snowflake-id-breakdown.pngrename to 07. Unique-Id Generator/images/snowflake-id-breakdown.pngdiff --git a/unique-id-generator/images/ticket-server.png b/07. Unique-Id Generator/images/ticket-server.pngsimilarity index 100%rename from unique-id-generator/images/ticket-server.pngrename to 07. Unique-Id Generator/images/ticket-server.pngdiff --git a/unique-id-generator/images/twitter-snowflake.png b/07. Unique-Id Generator/images/twitter-snowflake.pngsimilarity index 100%rename from unique-id-generator/images/twitter-snowflake.pngrename to 07. Unique-Id Generator/images/twitter-snowflake.pngdiff --git a/unique-id-generator/images/uuid.png b/07. Unique-Id Generator/images/uuid.pngsimilarity index 100%rename from unique-id-generator/images/uuid.pngrename to 07. Unique-Id Generator/images/uuid.pngdiff --git a/url-shortener/Readme.md b/08. URL Shortener/Readme.mdsimilarity index 93%rename from url-shortener/Readme.mdrename to 08. URL Shortener/Readme.mdindex 8aa4663..c39e66f 100644--- a/url-shortener/Readme.md+++ b/08. URL Shortener/Readme.md@@ -23,7 +23,7 @@ This chapter discusses the design of a URL shortening service like TinyURL. The- Endpoint: `GET api/v1/shortUrl`- Returns: `longURL` for redirection.- <img src="./images/url-redirection.png" alt="URL Redirection" width="500">+ <img src="./images/url-redirection.png" alt="URL Redirection" width="600">### URL Redirection- **301 Redirect:** A 301 redirect shows that the requested URL is “permanently” moved to the long URL. The browser caches the response, and@@ -31,12 +31,14 @@ subsequent requests for the same URL will not be sent to the URL shortening serv- **302 Redirect:** Temporary; useful for analytics like tracking clicks.### URL Shortening+<div style="margin-left:3rem">+ <img src="./images/url-shortening.png" alt="URL Shortening" width="400">+</div>+- Use a **hash function** to generate a short URL, mapping long URLs to unique shortened versions.- The hash function must satisfy the following requirements:- Each longURL must be hashed to one hashValue.- Each hashValue can be mapped back to the longURL.-- <img src="./images/url-shortening.png" alt="URL Shortening" width="300">---@@ -49,7 +51,7 @@ Store `<shortURL, longURL>` mappings in a relational database to optimize memory- `shortURL`,- `longURL`.- <img src="./images/table-schema.png" alt="Table Schema" width="200">+ <img src="./images/table-schema.png" alt="Table Schema" width="300">### Hash Function@@ -66,13 +68,13 @@ Convert ID `2009215674938` to Base 62:#### 2. Hash + Collision Resolution:- Use hash functions like CRC32, MD5, or SHA-1.- <img src="./images/hash-function.png" alt="Hash Function" width="400">+ <img src="./images/hash-function.png" alt="Hash Function" width="500">- One approach is to collect the first 7 characters of a hash value; however, this method can lead to hash collisions.- To resolve collisions,recursively append a new predefined string until no more collision but this can be expensive.- Resolve collisions with **Bloom Filters** for efficient lookup.- <img src="./images/url-lookup.png" alt="URL Lookup" width="400">+ <img src="./images/url-lookup.png" alt="URL Lookup" width="500">### Comparison@@ -93,6 +95,11 @@ Convert ID `2009215674938` to Base 62:---### URL Shortening Flow++<div style="margin-left:3rem">+ <img src="./images/url-shortening-flow.png" alt="URL Shortening" width="500">+</div>+1. Check if `longURL` exists in the database.2. If found, return the existing `shortURL`.3. Otherwise:@@ -100,19 +107,21 @@ Convert ID `2009215674938` to Base 62:- Convert the ID to `shortURL` using Base 62.- Store the `<id, shortURL, longURL>` mapping in the database.- <img src="./images/url-shortening-flow.png" alt="URL Shortening" width="500">---### URL Redirecting Flow+<div style="margin-left:3rem">+ <img src="./images/url-redirecting-flow.png" alt="URL Shortening" width="600">+</div>+1. User clicks a `shortURL`.2. Query `<shortURL, longURL>` mapping:- Check the **cache** first for faster access.- If not in the cache, query the database.3. Redirect the user to `longURL`.- <img src="./images/url-redirecting-flow.png" alt="URL Shortening" width="500">---diff --git a/url-shortener/images/hash-function.png b/08. URL Shortener/images/hash-function.pngsimilarity index 100%rename from url-shortener/images/hash-function.pngrename to 08. URL Shortener/images/hash-function.pngdiff --git a/url-shortener/images/table-schema.png b/08. URL Shortener/images/table-schema.pngsimilarity index 100%rename from url-shortener/images/table-schema.pngrename to 08. URL Shortener/images/table-schema.pngdiff --git a/url-shortener/images/url-lookup.png b/08. URL Shortener/images/url-lookup.pngsimilarity index 100%rename from url-shortener/images/url-lookup.pngrename to 08. URL Shortener/images/url-lookup.pngdiff --git a/url-shortener/images/url-redirecting-flow.png b/08. URL Shortener/images/url-redirecting-flow.pngsimilarity index 100%rename from url-shortener/images/url-redirecting-flow.pngrename to 08. URL Shortener/images/url-redirecting-flow.pngdiff --git a/url-shortener/images/url-redirection.png b/08. URL Shortener/images/url-redirection.pngsimilarity index 100%rename from url-shortener/images/url-redirection.pngrename to 08. URL Shortener/images/url-redirection.pngdiff --git a/url-shortener/images/url-shortening-flow.png b/08. URL Shortener/images/url-shortening-flow.pngsimilarity index 100%rename from url-shortener/images/url-shortening-flow.pngrename to 08. URL Shortener/images/url-shortening-flow.pngdiff --git a/url-shortener/images/url-shortening.png b/08. URL Shortener/images/url-shortening.pngsimilarity index 100%rename from url-shortener/images/url-shortening.pngrename to 08. URL Shortener/images/url-shortening.pngdiff --git a/web-crawler/Readme.md b/09. Web Crawler/Readme.mdsimilarity index 98%rename from web-crawler/Readme.mdrename to 09. Web Crawler/Readme.mdindex 1228eae..001551e 100644--- a/web-crawler/Readme.md+++ b/09. Web Crawler/Readme.md@@ -32,7 +32,9 @@ A good web crawler must address:## Step 2: High-Level Design### Components-<img src="./images/web-crawler-architecture.png" alt="Web Crawler Architecture" width="600">+<p align="center">+<img src="./images/web-crawler-architecture.png" alt="Web Crawler Architecture" width="700">+</p>1. **Seed URLs:** Starting points for the crawler.- Need to selective as a good starting point that a crawler can utilize to traverse as many links as possible.@@ -87,7 +89,7 @@ A good web crawler must address:- Use a mapping from hostnames to queues and worker (download) threads.- Each downloader thread has a separate FIFO queue and only downloads URLs from that queue.- <img src="./images/politeness.png" alt="Politeness" width="350">+ <img src="./images/politeness.png" alt="Politeness" width="500">- **Queue router:** Ensures that each queue (b1, b2, … bn) only contains URLs from the same host.- **Mapping table:** It maps each host to a queue.@@ -97,7 +99,7 @@ A good web crawler must address:- **Priority:**- Assign higher priority to important pages (e.g., by PageRank or update frequency).- <img src="./images/prioritizer.png" alt="Politeness" width="350">+ <img src="./images/prioritizer.png" alt="Politeness" width="500">- **Prioritizer:** It takes URLs as input and computes the priorities.- **Queue f1 to fn:** Each queue has an assigned priority. Queues with high priority are selected with higher probability.@@ -125,7 +127,7 @@ A good web crawler must address:- Add modules for new content types (e.g., PNG downloader, web monitor).- Example: Plug in a module to monitor web content for copyright violations.- <img src="./images/extensibility.png" alt="Politeness" width="500">+ <img src="./images/extensibility.png" alt="Politeness" width="600">---### Avoiding Problematic Contentdiff --git a/web-crawler/images/extensibility.png b/09. Web Crawler/images/extensibility.pngsimilarity index 100%rename from web-crawler/images/extensibility.pngrename to 09. Web Crawler/images/extensibility.pngdiff --git a/web-crawler/images/politeness.png b/09. Web Crawler/images/politeness.pngsimilarity index 100%rename from web-crawler/images/politeness.pngrename to 09. Web Crawler/images/politeness.pngdiff --git a/web-crawler/images/prioritizer.png b/09. Web Crawler/images/prioritizer.pngsimilarity index 100%rename from web-crawler/images/prioritizer.pngrename to 09. Web Crawler/images/prioritizer.pngdiff --git a/web-crawler/images/web-crawler-architecture.png b/09. Web Crawler/images/web-crawler-architecture.pngsimilarity index 100%rename from web-crawler/images/web-crawler-architecture.pngrename to 09. Web Crawler/images/web-crawler-architecture.pngdiff --git a/notification-system/Readme.md b/10. Notification System/Readme.mdsimilarity index 93%rename from notification-system/Readme.mdrename to 10. Notification System/Readme.mdindex fe6302c..cafa1db 100644--- a/notification-system/Readme.md+++ b/10. Notification System/Readme.md@@ -35,14 +35,22 @@ The chapter focuses on designing a scalable system capable of sending millions o- **Emails:** Commercial email services like SendGrid or Mailchimp.2. **Contact Info Gathering:**+ <div style="margin-left:3rem">+ <img src="./images/contact-info-gathering.png" alt="Contact Info Gathering" width="500">+ </div>+- Collect device tokens, phone numbers, or email addresses during app installation or signup.- Store contact info in the database:- **Device Tokens Table:** For push notifications.- **User Table:** For emails and phone numbers.- <img src="./images/contact-info-gathering.png" alt="Contact Info Gathering" width="500">3. **Notification Sending Flow:**++ <div style="margin-left:3rem">+ <img src="./images/high-level-design.png" alt="High Level Design" width="500">+ </div>+- **Trigger Services:**- Generate events to initiate notifications (e.g., billing reminders, shipping updates).- A service can be a micro-service, a cron job, or a distributed system that triggers notification sending events.@@ -52,7 +60,7 @@ The chapter focuses on designing a scalable system capable of sending millions o- Query the database or cache to fetch data needed to render a notification.- **Third-Party Services:** Deliver notifications to users.- <img src="./images/high-level-design.png" alt="High Level Design" width="500">+### Challenges in Initial Design- **Single Point of Failure (SPOF):** One notification server can crash the entire system.@@ -60,13 +68,18 @@ The chapter focuses on designing a scalable system capable of sending millions o- **Performance Bottlenecks:** High resource demands for sending notifications.### Improved Design++ <div style="margin-left:3rem">+ <img src="./images/improved-design.png" alt="Improved Design" width="500">+ </div>+- Move databases and caches out of the notification server.- Introduce **horizontal scaling** with multiple notification servers.- Use **message queues** to decouple system components.- Message queues serve as buffers when high volumes of notifications are to be sent out.- Add workers that pull notification events from message queues and send them to corresponding third party services.- <img src="./images/improved-design.png" alt="Improved Design" width="500">+---@@ -74,10 +87,13 @@ The chapter focuses on designing a scalable system capable of sending millions o### Reliability1. **Prevent Data Loss:**+ <div style="margin-left:3rem">+ <img src="./images/data-loss.png" alt="Data Loss" width="400">+ </div>+- Persist notification data in a database and implement a retry mechanism.- The Notification log database is included for data persistence.- <img src="./images/data-loss.png" alt="Data Loss" width="400">2. **Deduplication:**- Check event IDs to avoid sending duplicate notifications.@@ -86,6 +102,10 @@ If seen before discard it, otherwise send out the notification.### Additional Components+ <div style="margin-left:3rem">+ <img src="./images/events-tracking.png" alt="Events Tracking" width="400">+ </div>+1. **Notification Templates:** Preformatted templates for consistent and efficient notifications.2. **Notification Settings:**- Users can opt-in or opt-out for specific channels (push, SMS, or email).@@ -95,19 +115,22 @@ If seen before discard it, otherwise send out the notification.5. **Monitoring Queues:** Track queued notifications to scale workers dynamically.6. **Event Tracking:** Collect metrics like open rate, click rate, and engagement.- <img src="./images/events-tracking.png" alt="Events Tracking" width="350">### Security- Use **AppKey** and **AppSecret** to authenticate and secure APIs for push notifications.### Notification Flow++ <div style="margin-left:3rem">+ <img src="./images/updated-design.png" alt="Updated Design" width="500">+ </div>+1. Trigger services call APIs to send notifications.2. Notification servers validate requests and fetch metadata from caches or databases.3. Notification events are sent to message queues.4. Workers process events and interact with third-party services.5. Third-party services deliver notifications to users.- <img src="./images/updated-design.png" alt="Updated Design" width="500">---diff --git a/notification-system/images/contact-info-gathering.png b/10. Notification System/images/contact-info-gathering.pngsimilarity index 100%rename from notification-system/images/contact-info-gathering.pngrename to 10. Notification System/images/contact-info-gathering.pngdiff --git a/notification-system/images/data-loss.png b/10. Notification System/images/data-loss.pngsimilarity index 100%rename from notification-system/images/data-loss.pngrename to 10. Notification System/images/data-loss.pngdiff --git a/notification-system/images/events-tracking.png b/10. Notification System/images/events-tracking.pngsimilarity index 100%rename from notification-system/images/events-tracking.pngrename to 10. Notification System/images/events-tracking.pngdiff --git a/notification-system/images/high-level-design.png b/10. Notification System/images/high-level-design.pngsimilarity index 100%rename from notification-system/images/high-level-design.pngrename to 10. Notification System/images/high-level-design.pngdiff --git a/notification-system/images/improved-design.png b/10. Notification System/images/improved-design.pngsimilarity index 100%rename from notification-system/images/improved-design.pngrename to 10. Notification System/images/improved-design.pngdiff --git a/notification-system/images/updated-design.png b/10. Notification System/images/updated-design.pngsimilarity index 100%rename from notification-system/images/updated-design.pngrename to 10. Notification System/images/updated-design.pngdiff --git a/news-feed-system/Readme.md b/11. News Feed System/Readme.mdsimilarity index 93%rename from news-feed-system/Readme.mdrename to 11. News Feed System/Readme.mdindex 9ef7ec8..84e2ae8 100644--- a/news-feed-system/Readme.md+++ b/11. News Feed System/Readme.md@@ -42,6 +42,9 @@ The design includes two main flows:### Feed Publishing+ <div style="margin-left:3rem">+ <img src="./images/feed-publishing.png" alt="Feed Publishing" width="400">+ </div>1. **User Interaction:** The user publishes a post via the feed publishing API.2. **Load Balancer:** Distributes traffic to web servers.@@ -50,17 +53,20 @@ The design includes two main flows:5. **Fanout Service:** Propagates the post to friends’ news feeds in the cache.6. **Notification Service:** Sends notifications to friends.- <img src="./images/feed-publishing.png" alt="Feed Publishing" width="300">----### News Feed Building++ <div style="margin-left:3rem">+ <img src="./images/news-feed-building.png" alt="News Feed Building" width="400">+ </div>+1. **User Interaction:** The user requests their news feed via the retrieval API.2. **Load Balancer:** Distributes traffic to web servers.3. **Web Servers:** Forward requests to the news feed service.4. **News Feed Service:** Fetches post IDs from the news feed cache and retrieves complete post details from the database or cache.- <img src="./images/news-feed-building.png" alt="News Feed Building" width="300">+---## Step 3: Design Deep Dive@@ -79,7 +85,7 @@ The design includes two main flows:- **Cons:** Slower feed retrieval.- **Hybrid Approach:** Use a push model for most users and a pull model for high-connection users (e.g., celebrities).- <img src="./images/feed-publishing-deep-dive.png" alt="Feed Publishing Deep Dive" width="400">+ <img src="./images/feed-publishing-deep-dive.png" alt="Feed Publishing Deep Dive" width="500">The **fanout service** works as following:@@ -89,7 +95,7 @@ The design includes two main flows:4. **Fanout Workers:** Workers retrieve data from the message queue and update the news feed cache. The cache stores `<post_id, user_id>` mappings instead of full user and post objects to save memory.5. **Store in News Feed Cache:** Append new post IDs to the friends’ news feed cache. A configurable limit ensures that only recent posts are stored, as most users focus on the latest content, keeping cache memory consumption manageable.- <img src="./images/fanout-service.png" alt="Fanout Service" width="400">+ <img src="./images/fanout-service.png" alt="Fanout Service" width="500">## News Feed Retrieval Deep Dive@@ -101,7 +107,7 @@ The cache is divided into five layers:4. **Action Cache:** Tracks user actions (likes, replies, shares).5. **Counter Cache:** Maintains counts for likes, replies, followers, etc.- <img src="./images/cache-architecture.png" alt="Cache Architecture" width="400">+ <img src="./images/cache-architecture.png" alt="Cache Architecture" width="500">---## Key Optimizationsdiff --git a/news-feed-system/images/cache-architecture.png b/11. News Feed System/images/cache-architecture.pngsimilarity index 100%rename from news-feed-system/images/cache-architecture.pngrename to 11. News Feed System/images/cache-architecture.pngdiff --git a/news-feed-system/images/fanout-service.png b/11. News Feed System/images/fanout-service.pngsimilarity index 100%rename from news-feed-system/images/fanout-service.pngrename to 11. News Feed System/images/fanout-service.pngdiff --git a/news-feed-system/images/feed-publishing-deep-dive.png b/11. News Feed System/images/feed-publishing-deep-dive.pngsimilarity index 100%rename from news-feed-system/images/feed-publishing-deep-dive.pngrename to 11. News Feed System/images/feed-publishing-deep-dive.pngdiff --git a/news-feed-system/images/feed-publishing.png b/11. News Feed System/images/feed-publishing.pngsimilarity index 100%rename from news-feed-system/images/feed-publishing.pngrename to 11. News Feed System/images/feed-publishing.pngdiff --git a/news-feed-system/images/news-feed-building.png b/11. News Feed System/images/news-feed-building.pngsimilarity index 100%rename from news-feed-system/images/news-feed-building.pngrename to 11. News Feed System/images/news-feed-building.pngdiff --git a/chat-system/Readme.md b/12. Chat System/Readme.mdsimilarity index 88%rename from chat-system/Readme.mdrename to 12. Chat System/Readme.mdindex 7c0ee84..cf14843 100644--- a/chat-system/Readme.md+++ b/12. Chat System/Readme.md@@ -31,30 +31,38 @@ The system targets **50 million daily active users (DAU)** and stores chat histo### Communication Protocols1. **Sender Side:** HTTP for sending messages, leveraging persistent connections for efficiency.- <img src="./images/basic-design.png" alt="Basic Design" width="400">+ <div style="margin-left:2rem">+ <img src="./images/basic-design.png" alt="Basic Design" width="500">+ <div>2. **Receiver Side:**- **Polling:**- Client periodically asks the server if there are messages available.- Inefficient due to frequent, redundant requests.- <img src="./images/polling.png" alt="Polling" width="250">+ <img src="./images/polling.png" alt="Polling" width="400">- **Long Polling:**- Keeps the connection open until messages arrive.- Inefficient for inactive users.- <img src="./images/long-polling.png" alt="Long Polling" width="250">+ <img src="./images/long-polling.png" alt="Long Polling" width="400">- **WebSocket:**- A bi-directional, persistent connection for real-time communication, chosen for both sending and receiving messages.- Uses WebSockets (ws) protocol for sending and recieving messages.- <img src="./images/websocket.png" alt="Websocket" width="250" >+ <img src="./images/websocket.png" alt="Websocket" width="400" >---### Components++<div style="margin-left:5rem">+ <img src="./images/high-level-stateless-arch.png" alt="High Level Architecture" height="350">+ <img src="./images/high-level-statefull-arch.png" alt="High Level Architecture" height="350" width="550">+</div>+1. **Stateless Services:**- Handle signup, login, and user profile management.- Integrated with service discovery to recommend the best chat server.@@ -64,15 +72,17 @@ The system targets **50 million daily active users (DAU)** and stores chat histo3. **Third-Party Integration:**- Push notification services notify users about new messages.- Refer Notification System chapter for notifications implementation.- <p>- <img src="./images/high-level-stateless-arch.png" alt="High Level Architecture" height="250">- <img src="./images/high-level-statefull-arch.png" alt="High Level Architecture" height="250" width="350">- </p>+---### DesignThe client maintains a persistent WebSocket connection to a chat server for real-time messaging.++<div style="margin-left:3rem">+ <img src="./images/high-level-design.png" alt="High Level Design" width="450">+</div>+- Chat servers facilitate message sending/receiving.- Presence servers manage online/offline status.- API servers handle everything including user login, signup, change profile, etc.@@ -85,8 +95,6 @@ The client maintains a persistent WebSocket connection to a chat server for real- KV stores are adopted by other proven reliable chat applications. For example,both Facebook messenger and Discord.- <img src="./images/high-level-design.png" alt="High Level Design" width="350">-Following are the data models for one-to-one chat and group chat.- The primary key is message id, which helps to decide message sequence.@@ -95,66 +103,86 @@ Following are the data models for one-to-one chat and group chat.- A better approach is to use local sequence number generator. Local means IDs are only unique within a group.- The reason why local IDs work is that maintaining message sequence within one-on-one channel or a group channel is sufficient.- <img src="./images/one-to-one-chat.png" alt="One to one chat design" width="200">- <img src="./images/group-chat.png" alt="Group chat design" width="200">+ <img src="./images/one-to-one-chat.png" alt="One to one chat design" width="300">+ <img src="./images/group-chat.png" alt="Group chat design" width="300">## Step 3: Design Deep Dive### Service Discovery++<div style="margin-left:3rem">+ <img src="./images/zookeeper.png" alt="Zookeeper" width="400">+</div>+- The primary role of service discovery is to recommend the best chat server for a client basedon the criteria like geographical location, server capacity.- Uses **Apache Zookeeper** to allocate chat servers based on criteria like geographic location and server capacity.- Ensures efficient load distribution and minimizes latency.- <img src="./images/zookeeper.png" alt="Zookeeper" width="300">### Messaging Flows#### One-on-One Chat++1. User A sends a message to Chat Server 1.2. Chat Server 1 assigns a unique message ID and stores the message in a key-value store.3. If User B is online, the message is forwarded to Chat Server 2, maintaining a persistent WebSocket connection.4. If User B is offline, a push notification is sent.- <img src="./images/one-to-one-chat-flow.png" alt="One-to-One Chat Flow" width="300">#### Group Chat++<div style="margin-left:3rem">+ <img src="./images/group-chat-flow.png" alt="Group Chat Flow" width="400">+</div>+- Messages are copied to individual inboxes for each recipient in the group.- Simplifies synchronization but becomes expensive for larger groups.- On the recipient side, a recipient can receive messages from multiple users. Each recipienthas an inbox (message sync queue) which contains messages from different senders.- <img src="./images/group-chat-flow.png" alt="Group Chat Flow" width="300">----#### Message Synchronization+Many users have multiple devices. We need to synchronize the message across the devices.Each device maintains a variable called cur_max_message_id, which keeps track of the latestmessage ID on the device. Messages that satisfy the following two conditions are consideredas news messages:++<div style="margin-left:3rem">+ <img src="./images/message-synchronization.png" alt="Message Synchronization" width="400">+</div>+- The recipient ID is equal to the currently logged-in user ID.- Message ID in the key-value store is larger than cur_max_message_id- <img src="./images/message-synchronization.png" alt="Message Synchronization" width="350">----### Online Presence1. **Heartbeat Mechanism:**+ <div style="margin-left:3rem">+ <img src="./images/heartbeat-mechanism.png" alt="Heartbeat Mechanism" width="400">+ </div>+- Clients send periodic heartbeats to presence servers to indicate they are online.- If no heartbeat is received within a threshold (for eg x = 30), the user is marked offline.- <img src="./images/heartbeat-mechanism.png" alt="Heartbeat Mechanism" width="350">+2. **Fanout Model:**++ <div style="margin-left:3rem">+ <img src="./images/fanout-presence.png" alt="Fanout Presence" width="400">+ </div>+- Presence updates are pushed to friends using a publish-subscribe model in which each friend pair maintains a channel.- When User A’s online status changes, it publishes the event to three channels, channel A-B, A-C, and A-D.- Those three channels are subscribed by User B, C, and D, respectively which get the online status updates.- The above design is effective for a small user groups.- <img src="./images/fanout-presence.png" alt="Fanout Presence" width="400">---diff --git a/chat-system/images/basic-design.png b/12. Chat System/images/basic-design.pngsimilarity index 100%rename from chat-system/images/basic-design.pngrename to 12. Chat System/images/basic-design.pngdiff --git a/chat-system/images/fanout-presence.png b/12. Chat System/images/fanout-presence.pngsimilarity index 100%rename from chat-system/images/fanout-presence.pngrename to 12. Chat System/images/fanout-presence.pngdiff --git a/chat-system/images/group-chat-flow.png b/12. Chat System/images/group-chat-flow.pngsimilarity index 100%rename from chat-system/images/group-chat-flow.pngrename to 12. Chat System/images/group-chat-flow.pngdiff --git a/chat-system/images/group-chat.png b/12. Chat System/images/group-chat.pngsimilarity index 100%rename from chat-system/images/group-chat.pngrename to 12. Chat System/images/group-chat.pngdiff --git a/chat-system/images/heartbeat-mechanism.png b/12. Chat System/images/heartbeat-mechanism.pngsimilarity index 100%rename from chat-system/images/heartbeat-mechanism.pngrename to 12. Chat System/images/heartbeat-mechanism.pngdiff --git a/chat-system/images/high-level-design.png b/12. Chat System/images/high-level-design.pngsimilarity index 100%rename from chat-system/images/high-level-design.pngrename to 12. Chat System/images/high-level-design.pngdiff --git a/chat-system/images/high-level-statefull-arch.png b/12. Chat System/images/high-level-statefull-arch.pngsimilarity index 100%rename from chat-system/images/high-level-statefull-arch.pngrename to 12. Chat System/images/high-level-statefull-arch.pngdiff --git a/chat-system/images/high-level-stateless-arch.png b/12. Chat System/images/high-level-stateless-arch.pngsimilarity index 100%rename from chat-system/images/high-level-stateless-arch.pngrename to 12. Chat System/images/high-level-stateless-arch.pngdiff --git a/chat-system/images/long-polling.png b/12. Chat System/images/long-polling.pngsimilarity index 100%rename from chat-system/images/long-polling.pngrename to 12. Chat System/images/long-polling.pngdiff --git a/chat-system/images/message-synchronization.png b/12. Chat System/images/message-synchronization.pngsimilarity index 100%rename from chat-system/images/message-synchronization.pngrename to 12. Chat System/images/message-synchronization.pngdiff --git a/chat-system/images/one-to-one-chat-flow.png b/12. Chat System/images/one-to-one-chat-flow.pngsimilarity index 100%rename from chat-system/images/one-to-one-chat-flow.pngrename to 12. Chat System/images/one-to-one-chat-flow.pngdiff --git a/chat-system/images/one-to-one-chat.png b/12. Chat System/images/one-to-one-chat.pngsimilarity index 100%rename from chat-system/images/one-to-one-chat.pngrename to 12. Chat System/images/one-to-one-chat.pngdiff --git a/chat-system/images/online-presence.png b/12. Chat System/images/online-presence.pngsimilarity index 100%rename from chat-system/images/online-presence.pngrename to 12. Chat System/images/online-presence.pngdiff --git a/chat-system/images/polling.png b/12. Chat System/images/polling.pngsimilarity index 100%rename from chat-system/images/polling.pngrename to 12. Chat System/images/polling.pngdiff --git a/chat-system/images/websocket.png b/12. Chat System/images/websocket.pngsimilarity index 100%rename from chat-system/images/websocket.pngrename to 12. Chat System/images/websocket.pngdiff --git a/chat-system/images/zookeeper.png b/12. Chat System/images/zookeeper.pngsimilarity index 100%rename from chat-system/images/zookeeper.pngrename to 12. Chat System/images/zookeeper.pngdiff --git a/search-autocomplete/Readme.md b/13. Search Autocomplete/Readme.mdsimilarity index 90%rename from search-autocomplete/Readme.mdrename to 13. Search Autocomplete/Readme.mdindex 2cc83c6..7f067ef 100644--- a/search-autocomplete/Readme.md+++ b/13. Search Autocomplete/Readme.md@@ -34,21 +34,27 @@ At the high-level, the system is broken down into two services:---### Data Gathering Service+<div style="margin-left:3rem">+ <img src="./images/data-gathering.png" alt="Data Gathering" width="600">+</div>+- Aggregates query data from analytics logs and updates the frequency table.- Processes historical data weekly to build a **trie** (prefix tree).- <img src="./images/data-gathering.png" alt="Data Gathering" width="400">### Query Service+<div style="margin-left:3rem">+ <img src="./images/frequency-table.png" alt="Frequency Table" width="400">+ <img src="./images/basic-search-suggestions.png" alt="Search Suggestions" width="360">+</div>+- Uses the frequency table from data gathering service.- Processes user input and retrieves top-k suggestions from the frequency table using a Trie.- Optimized for fast lookups using caching and efficient data structures.- For example when a user types “tw” in the search box, the following top 5 searched queries are displayed.- <img src="./images/frequency-table.png" alt="Frequency Table" width="300">- <img src="./images/basic-search-suggestions.png" alt="Search Suggestions" width="273">---@@ -62,16 +68,19 @@ The **trie** is a tree-like data structure used to store and retrieve query stri2. **Frequency Information:** Stores the popularity of queries at each node.4. **Steps to get top k most searched queries**+ <div style="margin-left:3rem">+ <img src="./images/trie-structure.png" alt="Trie Structure" width="500">+ </div>+- Find the prefix- Traverse the subtree from prefix node to get all valid children- Sort the children and get top k- <img src="./images/trie-structure.png" alt="Trie Structure" width="400">3. **Optimizations:**- Cache top-k queries at each node to speed up retrieval and avoid traversing the whole trie.- <img src="./images/cached-trie.png" alt="Cached Trie" width="400">+ <img src="./images/cached-trie.png" alt="Cached Trie" width="600">- Limit prefix length to reduce search space as users rarely type a loong search query (say 50).@@ -81,11 +90,14 @@ The **trie** is a tree-like data structure used to store and retrieve query stri- The source of data is from Analytics Log/DB.2. **Update:** Rarely updated in real-time; weekly updates replace old data.3. **Delete:**+ <div style="margin-left:3rem">+ <img src="./images/delete-kv.png" alt="Delete KV" width="500">+ </div>+- Filters remove unwanted or harmful suggestions (e.g., hate speech).- Having a filter layer gives us the flexibility of removing results based on different filter rules.- Unwanted suggestions are removed physically from the database asynchronically.- <img src="./images/delete-kv.png" alt="Delete KV" width="300">---@@ -120,7 +132,9 @@ In the high-level design, whenever a user types a search query, data is updated#### Updated Design-<img src="./images/data-gathering-flow.png" alt="Updated Data Gathering Flow" width="500">+<div style="margin-left:3rem">+ <img src="./images/data-gathering-flow.png" alt="Updated Data Gathering Flow" width="600">+</div>1. **Analytics Logs:**- Stores raw query data as logs for weekly aggregation.@@ -140,7 +154,7 @@ In the high-level design, whenever a user types a search query, data is updated- Every prefix in the trie is mapped to a key in a hash table.- Data on each trie node is mapped to a value in a hash table.- <img src="./images/trie-db.png" alt="Trie DB" width="400">+ <img src="./images/trie-db.png" alt="Trie DB" width="600">---### Scalability@@ -148,9 +162,12 @@ In the high-level design, whenever a user types a search query, data is updated- Distribute trie nodes across servers based on prefix ranges (e.g., `a-m`, `n-z`).- Further shard within prefixes to balance uneven distributions (e.g., `aa-ag`, `ah-an`).2. **Load Balancing:**+ <div style="margin-left:3rem">+ <img src="./images/sharding.png" alt="Sharding" width="400">+ </div>+- Use a shard map manager to route requests to the appropriate server.- <img src="./images/sharding.png" alt="Sharding" width="300">---diff --git a/search-autocomplete/images/basic-search-suggestions.png b/13. Search Autocomplete/images/basic-search-suggestions.pngsimilarity index 100%rename from search-autocomplete/images/basic-search-suggestions.pngrename to 13. Search Autocomplete/images/basic-search-suggestions.pngdiff --git a/search-autocomplete/images/cached-trie.png b/13. Search Autocomplete/images/cached-trie.pngsimilarity index 100%rename from search-autocomplete/images/cached-trie.pngrename to 13. Search Autocomplete/images/cached-trie.pngdiff --git a/search-autocomplete/images/data-gathering-flow.png b/13. Search Autocomplete/images/data-gathering-flow.pngsimilarity index 100%rename from search-autocomplete/images/data-gathering-flow.pngrename to 13. Search Autocomplete/images/data-gathering-flow.pngdiff --git a/search-autocomplete/images/data-gathering.png b/13. Search Autocomplete/images/data-gathering.pngsimilarity index 100%rename from search-autocomplete/images/data-gathering.pngrename to 13. Search Autocomplete/images/data-gathering.pngdiff --git a/search-autocomplete/images/delete-kv.png b/13. Search Autocomplete/images/delete-kv.pngsimilarity index 100%rename from search-autocomplete/images/delete-kv.pngrename to 13. Search Autocomplete/images/delete-kv.pngdiff --git a/search-autocomplete/images/frequency-table.png b/13. Search Autocomplete/images/frequency-table.pngsimilarity index 100%rename from search-autocomplete/images/frequency-table.pngrename to 13. Search Autocomplete/images/frequency-table.pngdiff --git a/search-autocomplete/images/sharding.png b/13. Search Autocomplete/images/sharding.pngsimilarity index 100%rename from search-autocomplete/images/sharding.pngrename to 13. Search Autocomplete/images/sharding.pngdiff --git a/search-autocomplete/images/trie-db.png b/13. Search Autocomplete/images/trie-db.pngsimilarity index 100%rename from search-autocomplete/images/trie-db.pngrename to 13. Search Autocomplete/images/trie-db.pngdiff --git a/search-autocomplete/images/trie-structure.png b/13. Search Autocomplete/images/trie-structure.pngsimilarity index 100%rename from search-autocomplete/images/trie-structure.pngrename to 13. Search Autocomplete/images/trie-structure.pngdiff --git a/youtube/Readme.md b/14. Youtube/Readme.mdsimilarity index 88%rename from youtube/Readme.mdrename to 14. Youtube/Readme.mdindex 5ddd3c0..2ff3c6c 100644--- a/youtube/Readme.md+++ b/14. Youtube/Readme.md@@ -39,7 +39,9 @@ YouTube is a massive video streaming platform supporting video uploads, playback### Components- <img src="./images/high-level-design.png" alt="High Level Design" width="300">+<div style="margin-left:3rem">+ <img src="./images/high-level-design.png" alt="High Level Design" width="400">+</div>1. **Client:** Devices like smartphones, computers, and TVs.2. **CDN (Content Delivery Network):** Stores and streams videos.@@ -60,7 +62,9 @@ YouTube is a massive video streaming platform supporting video uploads, playback- **Video Upload (Steps):**- <img src="./images/video-uploading-flow.png" alt="Video Upload Flow" width="400">+ <div style="margin-left:3rem">+ <img src="./images/video-uploading-flow.png" alt="Video Upload Flow" width="500">+ </div>- [1] Videos are uploaded to blob storage.- [2] Transcoding servers convert videos to multiple formats.@@ -72,10 +76,11 @@ YouTube is a massive video streaming platform supporting video uploads, playback-- **Metadata Upload (Steps):**- <img src="./images/metadata-upload.png" alt="Metadata Upload" height="300">+ <div style="margin-left:3rem">+ <img src="./images/metadata-upload.png" alt="Metadata Upload" height="500">+ </div>- The client in parallel sends a request to update the video metadata- The request contains video metadata, including file name, size, format, etc.@@ -86,7 +91,7 @@ YouTube is a massive video streaming platform supporting video uploads, playback#### 2. Video Streaming Flow<div style="margin-left: 3em;">- <img src="./images/video-streaming-flow.png" alt="Video Streaming Flow" height="250">+ <img src="./images/video-streaming-flow.png" alt="Video Streaming Flow" height="400"></div>- Videos are streamed directly from the CDN using edge servers to minimize latency.@@ -109,11 +114,14 @@ YouTube is a massive video streaming platform supporting video uploads, playback- **Codecs:** Compression and Decompression algorithms (e.g., H.264, VP9).#### Directed Acyclic Graph (DAG) Model+<div style="margin-left: 3em;">+ <img src="./images/dag-video-transcoding.png" alt="DAG Video Transcoding" width="600">+</div>+- Transcoding a video is computationally expensive and time-consuming.- DAG Model defines tasks like encoding, thumbnail generation, and watermarking.- Allows high parallelism in video processing.- <img src="./images/dag-video-transcoding.png" alt="DAG Video Transcoding" width="400">- The original video is split into video, audio, and metadata.- Video encodings: Videos are converted to support different resolutions, codec, bitrates.@@ -124,36 +132,51 @@ YouTube is a massive video streaming platform supporting video uploads, playback### Video Transcoding Architecture- <img src="./images/video-transcoding-architecture.png" alt="Video Transcoding" width="500">+<div style="margin-left: 3em;">+<img src="./images/video-transcoding-architecture.png" alt="Video Transcoding" width="600">+</div>1. **Preprocessor:** Splits videos into smaller chunks (GOP alignment). It has 4 responsibilities.++ <div style="margin-left: 3em;">+ <img src="./images/dag-config.png" alt="DAG Config" width="500">+ </div>+- Video splitting: Video stream is split or further split into smaller Group of Pictures (GOP) alignment.- It split videos by GOP alignment for old clients.- It generates DAG based on configuration files client programmers write.- It stores GOPs and metadata in temporary storage in case the encoding fails, the system could use persisted data for retry operations.- <img src="./images/dag-config.png" alt="DAG Config" width="400">2. **DAG Scheduler:** Organizes tasks into sequential or parallel stages.+ <div style="margin-left: 3em;">+ <img src="./images/dag-scheduler.png" alt="DAG Scheduler" width="500">+ </div>+- It splits a DAG graph into stages of tasks and puts them in the task queue in the resource manager.- Stage 1: video, audio, and metadata.- The video file is further split into two tasks in stage 2: video encoding and thumbnail.- <img src="./images/dag-scheduler.png" alt="DAG Scheduler" width="300">3. **Resource Manager:** Responsible for managing the efficiency of resource allocation.Itcontains 3 queues and a task scheduler.+ <div style="margin-left: 3em;">+ <img src="./images/resource-manager.png" alt="Resource Manager" width="700">+ </div>+- Task queue: priority queue that contains tasks to be executed.- Worker queue: priority queue that contains worker utilization info.- Running queue: contains currently running tasks and workers running the tasks.- Task scheduler: picks the optimal task/worker, and instructs the chosen task worker to execute the job.- <img src="./images/resource-manager.png" alt="Resource Manager" width="400">4. **Task Workers:** Perform transcoding and other operations.+ <div style="margin-left: 3em;">+ <img src="./images/task-worker.png" alt="Task Worker" width="250">+ </div>+- Different task workers may run different tasks- <img src="./images/task-worker.png" alt="Task Worker" width="150">5. **Temporary Storage:** Stores intermediate data for retries.- The choice of storage system depends on factors like data type, data size, access frequency, data life span, etc.@@ -167,18 +190,18 @@ contains 3 queues and a task scheduler.### Speed Optimizations1. **Parallel Video Uploads:** Split videos into smaller chunks for faster, resumable uploads.- <img src="./images/video-split.png" alt="Video Split" width="400">+ <img src="./images/video-split.png" alt="Video Split" width="600">2. **Distributed Upload Centers:** Use CDNs as upload hubs close to users.3. **Parallel Processing:** Decouple modules using message queues for high parallelism.- <img src="./images/message-queue1.png" alt="Message Queue" width="400">- <img src="./images/message-queue2.png" alt="Message Queue" height="115" width="400">+ <img src="./images/message-queue1.png" alt="Message Queue" width="600">+ <img src="./images/message-queue2.png" alt="Message Queue" height="170" width="500">### Safety Optimizations1. **Pre-Signed URLs:** Restrict video uploads to authorized users.- <img src="./images/pres-signed-urls.png" alt="Pre Signed" width="300">+ <img src="./images/pres-signed-urls.png" alt="Pre Signed" width="500">2. **Protect Videos:**- **DRM Systems** (e.g., Apple FairPlay, Google Widevine).diff --git a/youtube/images/dag-config.png b/14. Youtube/images/dag-config.pngsimilarity index 100%rename from youtube/images/dag-config.pngrename to 14. Youtube/images/dag-config.pngdiff --git a/youtube/images/dag-scheduler.png b/14. Youtube/images/dag-scheduler.pngsimilarity index 100%rename from youtube/images/dag-scheduler.pngrename to 14. Youtube/images/dag-scheduler.pngdiff --git a/youtube/images/dag-video-transcoding.png b/14. Youtube/images/dag-video-transcoding.pngsimilarity index 100%rename from youtube/images/dag-video-transcoding.pngrename to 14. Youtube/images/dag-video-transcoding.pngdiff --git a/youtube/images/high-level-design.png b/14. Youtube/images/high-level-design.pngsimilarity index 100%rename from youtube/images/high-level-design.pngrename to 14. Youtube/images/high-level-design.pngdiff --git a/youtube/images/message-queue1.png b/14. Youtube/images/message-queue1.pngsimilarity index 100%rename from youtube/images/message-queue1.pngrename to 14. Youtube/images/message-queue1.pngdiff --git a/youtube/images/message-queue2.png b/14. Youtube/images/message-queue2.pngsimilarity index 100%rename from youtube/images/message-queue2.pngrename to 14. Youtube/images/message-queue2.pngdiff --git a/youtube/images/metadata-upload.png b/14. Youtube/images/metadata-upload.pngsimilarity index 100%rename from youtube/images/metadata-upload.pngrename to 14. Youtube/images/metadata-upload.pngdiff --git a/youtube/images/pres-signed-urls.png b/14. Youtube/images/pres-signed-urls.pngsimilarity index 100%rename from youtube/images/pres-signed-urls.pngrename to 14. Youtube/images/pres-signed-urls.pngdiff --git a/youtube/images/resource-manager.png b/14. Youtube/images/resource-manager.pngsimilarity index 100%rename from youtube/images/resource-manager.pngrename to 14. Youtube/images/resource-manager.pngdiff --git a/youtube/images/task-worker.png b/14. Youtube/images/task-worker.pngsimilarity index 100%rename from youtube/images/task-worker.pngrename to 14. Youtube/images/task-worker.pngdiff --git a/youtube/images/video-split.png b/14. Youtube/images/video-split.pngsimilarity index 100%rename from youtube/images/video-split.pngrename to 14. Youtube/images/video-split.pngdiff --git a/youtube/images/video-streaming-flow.png b/14. Youtube/images/video-streaming-flow.pngsimilarity index 100%rename from youtube/images/video-streaming-flow.pngrename to 14. Youtube/images/video-streaming-flow.pngdiff --git a/youtube/images/video-transcoding-architecture.png b/14. Youtube/images/video-transcoding-architecture.pngsimilarity index 100%rename from youtube/images/video-transcoding-architecture.pngrename to 14. Youtube/images/video-transcoding-architecture.pngdiff --git a/youtube/images/video-uploading-flow.png b/14. Youtube/images/video-uploading-flow.pngsimilarity index 100%rename from youtube/images/video-uploading-flow.pngrename to 14. Youtube/images/video-uploading-flow.pngdiff --git a/google-drive/Readme.md b/15. Google Drive/Readme.mdsimilarity index 97%rename from google-drive/Readme.mdrename to 15. Google Drive/Readme.mdindex 557da1e..49177aa 100644--- a/google-drive/Readme.md+++ b/15. Google Drive/Readme.md@@ -45,7 +45,7 @@ A basic setup includes:<div style="margin-left:3rem">- <img src="./images/namespaces.png" alt="Namespaces" width="300" />+ <img src="./images/namespaces.png" alt="Namespaces" width="400" /></div>- A web server and a directory called drive/ is set up as the root directory to store uploaded files.@@ -75,7 +75,7 @@ This design serves as a starting point but is inadequate for scaling.1. **Sharding:** Split storage across servers based on `user_id`.2. **Amazon S3:** Use S3 for scalable and redundant file storage with cross-region replication.- <img src="./images/replication.png" alt="Replication" width="400" />+ <img src="./images/replication.png" alt="Replication" width="600" />3. **Load Balancer:** Distribute traffic across multiple web servers.4. **Metadata Database Replication:** Ensure availability through database sharding and replication.@@ -86,7 +86,7 @@ For a large storage system like Google Drive, sync conflicts happen from time toWhen two users modify the same file or folder at the same time, a conflict happens.<div style="margin-left:5rem">-<img src="./images/sync-conflicts.png" alt="Sync Conflicts" width="500" />+<img src="./images/sync-conflicts.png" alt="Sync Conflicts" width="600" /></div>- In the example user 1 and user 2 tries to update the same file at the same time, but user 1’s file is processed by our system first.@@ -96,7 +96,7 @@ When two users modify the same file or folder at the same time, a conflict happe### Improved design<div style="margin-left:5rem">-<img src="./images/high-level-design.png" alt="High Level Design" width="400" />+<img src="./images/high-level-design.png" alt="High Level Design" width="500" /></div>1. **User Interaction:**: Users access the application via browser or mobile app.@@ -139,7 +139,7 @@ A highly simplified is shown below version as it only includes the most importan- **File Version Table:** Stores file revision history.<div style="margin-left:5rem">-<img src="./images/metadata-database.png" alt="Metadata Database " width="400" />+<img src="./images/metadata-database.png" alt="Metadata Database " width="500" /></div>---@@ -168,7 +168,7 @@ A highly simplified is shown below version as it only includes the most importan1. **Delta Sync:** Transfer only modified blocks instead of the entire file.<div style="margin-left:2rem">- <img src="./images/delta-sync.png" alt="Delta Sync" width="200" />+ <img src="./images/delta-sync.png" alt="Delta Sync" width="400" /></div>2. **Compression:** Blocks are compressed using compression algorithms depending on file types.@@ -196,7 +196,7 @@ downloads blocks to construct the file.<div style="margin-left:3rem">-<img src="./images/download-flow.png" alt="Upload Flow " width="500" />+<img src="./images/download-flow.png" alt="Upload Flow " width="600" /></div>diff --git a/google-drive/images/delta-sync.png b/15. Google Drive/images/delta-sync.pngsimilarity index 100%rename from google-drive/images/delta-sync.pngrename to 15. Google Drive/images/delta-sync.pngdiff --git a/google-drive/images/download-flow.png b/15. Google Drive/images/download-flow.pngsimilarity index 100%rename from google-drive/images/download-flow.pngrename to 15. Google Drive/images/download-flow.pngdiff --git a/google-drive/images/file-sync.png b/15. Google Drive/images/file-sync.pngsimilarity index 100%rename from google-drive/images/file-sync.pngrename to 15. Google Drive/images/file-sync.pngdiff --git a/google-drive/images/high-level-design.png b/15. Google Drive/images/high-level-design.pngsimilarity index 100%rename from google-drive/images/high-level-design.pngrename to 15. Google Drive/images/high-level-design.pngdiff --git a/google-drive/images/metadata-database.png b/15. Google Drive/images/metadata-database.pngsimilarity index 100%rename from google-drive/images/metadata-database.pngrename to 15. Google Drive/images/metadata-database.pngdiff --git a/google-drive/images/namespaces.png b/15. Google Drive/images/namespaces.pngsimilarity index 100%rename from google-drive/images/namespaces.pngrename to 15. Google Drive/images/namespaces.pngdiff --git a/google-drive/images/replication.png b/15. Google Drive/images/replication.pngsimilarity index 100%rename from google-drive/images/replication.pngrename to 15. Google Drive/images/replication.pngdiff --git a/google-drive/images/sync-conflicts.png b/15. Google Drive/images/sync-conflicts.pngsimilarity index 100%rename from google-drive/images/sync-conflicts.pngrename to 15. Google Drive/images/sync-conflicts.pngdiff --git a/google-drive/images/upload-flow.png b/15. Google Drive/images/upload-flow.pngsimilarity index 100%rename from google-drive/images/upload-flow.pngrename to 15. Google Drive/images/upload-flow.pngdiff --git a/Readme.md b/Readme.mdnew file mode 100644index 0000000..e344e60--- /dev/null+++ b/Readme.md@@ -0,0 +1,84 @@++# [System Design Interview - An Insider's Guide (Vol 1)](https://bytebytego.com/courses/system-design-interview)+These notes are based on the System Design Interview books - [Vol 1 2nd Ed](https://www.goodreads.com/book/show/54109255-system-design-interview-an-insider-s-guide)+++**Note:** These notes are a work in progress.+++ * [Chapter 1 - Scale From Zero To Millions Of Users](./1.%20Scaling/)+ * [Chapter 2 - Back-of-the-envelope Estimation](./2.%20Back%20Of%20the%20Envelope%20Estimation/)+ * [Chapter 3 - A Framework For System Design Interviews](./3.%20System%20Design%20Framework/)+ * [Chapter 4 - Design A Rate Limiter](./4.%20Rate%20Limiter/)+ * [Chapter 5 - Design Consistent Hashing](./5.%20Consistent%20Hashing/)+ * [Chapter 6 - Design A Key-Value Store](./6.%20Key-Value%20Store/)+ * [Chapter 7 - Design A Unique ID Generator In Distributed Systems](./7.%20Unique-Id%20Generator/)+ * [Chapter 8 - Design A URL Shortener](./8.%20URL%20Shortener/)+ * [Chapter 9 - Design A Web Crawler](./9.%20Web%20Crawler/)+ * [Chapter 10 - Design A Notification System](./10.%20Notification%20System/)+ * [Chapter 11 - Design A News Feed System](./11.%20News%20Feed%20System/)+ * [Chapter 12 - Design A Chat System](./12.%20Chat%20System/)+ * [Chapter 13 - Design A Search Autocomplete System](./13.%20Search%20Autocomplete/)+ * [Chapter 14 - Design YouTube](./14.%20Youtube/)+ * [Chapter 15 - Design Google Drive](./15.%20Google%20Drive/)++++# Additonal Resources++### Rate Limiting+- [Circuit Breaker Algorithm](https://martinfowler.com/bliki/CircuitBreaker.html)+- [Uber Rate Limiter](https://github.com/uber-go/ratelimit/blob/master/ratelimit.go)+++### Consistent Hashing+- [Consistent Hashing](https://tom-e-white.com/2007/11/consistent-hashing.html)+- [CS168: Introduction and Consistent Hashing:]( http://theory.stanford.edu/~tim/s16/l/l1.pdf)+- [Apache Cassandra](http://www.cs.cornell.edu/Projects/ladis2009/papers/Lakshman-ladis2009.PDF)+- [Scaling Discord](https://blog.discord.com/scaling-elixir-f9b8e1e7c29b)+- [Google Maglev](https://static.googleusercontent.com/media/research.google.com/en//pubs/archive/44824.pdf)+++### Key-Value Store+- [Amazon Dynamo](https://www.allthingsdistributed.com/files/amazon-dynamo-sosp2007.pdf)+- [Cassandra Architecture](https://docs.datastax.com/en/archived/cassandra/3.0/cassandra/architecture/archIntro.html)+- [Google BigTable Architecture](https://static.googleusercontent.com/media/research.google.com/en//archive/bigtable-osdi06.pdf)+- [Amazon Dynamo DB Internals](https://www.allthingsdistributed.com/2007/10/amazons_dynamo.html)+- [Design Patterns in Amazon Dynamo DB](https://www.youtube.com/watch?v=HaEPXoXVf2k)+- [Internals of Amazon Dynamo DB](https://www.youtube.com/watch?v=yvBR71D0nAQ)+++### Unique-ID Generator+- [Ticket Servers: Distributed Unique Primary Keys on the Cheap](https://code.flickr.net/2010/02/08/ticket-servers-distributed-unique-primary-keys-on-the-cheap)+- [Snowflake](https://blog.twitter.com/engineering/en_us/a/2010/announcing-snowflake.html)+++### Web Crawler+- [Web Crawling](http://infolab.stanford.edu/~olston/publications/crawling_survey.pdf)+- [Google Dynamic Rendering](https://developers.google.com/search/docs/guides/dynamic-rendering)++++### Chat Systems+- [How Discord stores billions of messages](https://discord.com/blog/how-discord-stores-billions-of-messages)+- [Flannel: An Application-Level Edge Cache to Make Slack Scale](https://slack.engineering/flannel-an-application-level-edge-cache-to-make-slack-scale/)+++### Search Autocomplete+- [How We Built Prefixy](https://medium.com/@prefixyteam/how-we-built-prefixy-a-scalable-prefix-search-service-for-powering-autocomplete-c20f98e2eff1)+- [Prefix Hash Tree](https://people.eecs.berkeley.edu/~sylvia/papers/pht.pdf)+++### Youtube+- [YouTube Architecture](http://highscalability.com/youtube-architecture)+- [YouTube scalability 2012](https://www.youtube.com/watch?v=w5WVu624fY8)+- [Transcoding Videos at Scale](https://www.egnyte.com/blog/2018/12/transcoding-how-we-serve-videos-at-scale/)+- [Facebook Video Broadcasting](https://engineering.fb.com/ios/under-the-hood-broadcasting-live-video-to-millions/)+- [Netflix Video Encoding at Scale](https://netflixtechblog.com/high-quality-video-encoding-at-scale-d159db052746)+- [Netflix Shot based encoding](https://netflixtechblog.com/optimized-shot-based-encodes-now-streaming-4b9464204830)+++### Google Drive+- [Differential Synchronization](https://neil.fraser.name/writing/sync/)+- [Differential Synchronization Video](https://www.youtube.com/watch?v=S2Hp_1jqpY8)+- [How We’ve Scaled Dropbox](https://www.youtube.com/watch?v=PE4gwstWhmc&feature=youtu.be)