System Design
Learn System Design
Introduction to System Design
How to Learn System Design?
Key Characteristics of Distributed Systems
Scalability
Availability
Latency and Performance
Concurrency and Coordination
Monitoring and Observability
Resilience and Error Handling
Fault Tolerance vs. High Availability
Flashcards Review
Chapter Assessment
Network Essentials
HTTP vs. HTTPS
TCP vs. UDP
HTTP: 1.0 vs. 1.1 vs 2.0 vs. 3.0
URL vs. URI vs. URN
What Happens When You Type a URL into the Browser
Flashcards Review
Chapter Assessment
Long-Polling vs. WebSockets vs. Server-Sent Events
Introduction to Real-Time Communication
What is Long-Polling?
What is WebSocket?
What are Server-Sent Events?
Difference Between Long-Polling, WebSockets, and Server-Sent Events
Flashcards Review
Chapter Assessment
Domain Name System (DNS)
Introduction to DNS
DNS Resolution Process
DNS Load Balancing and High Availability
Flashcards Review
Chapter Assessment
Load Balancing
Introduction to Load Balancing
Load Balancing Algorithms
Uses of Load Balancing
Load Balancer Types
Stateless vs. Stateful Load Balancing
High Availability and Fault Tolerance
Scalability and Performance
Challenges of Load Balancers
Flashcards Review
Chapter Assessment
API Gateway
Introduction to API Gateway
Usage of API gateway
Advantages and disadvantages of using API gateway
Flashcards Review
Chapter Assessment
API Design
What Is an API?
What Are REST APIs?
Resources, Not Actions
HTTP Methods and Their Semantics
URL Design
Request and Response Shapes
Status Codes and Error Design
Pagination from the Consumer's View
Idempotency Keys
Versioning and Backward Compatibility
Concurrency and Conditional Requests
REST vs gRPC vs GraphQL
Flashcards Review
Chapter Assessment
Rate Limiting and Throttling
What Is Rate Limiting
Rate Limiting Algorithms
Distributed Rate Limiting
Rate Limiting in Practice
Flashcards Review
Chapter Assessment
Caching
Introduction to Caching
Why is Caching Important?
Types of Caching
Cache Replacement Policies
Cache Invalidation
Cache Read Strategies
Cache Coherence and Consistency Models
Caching Challenges
Cache Performance Metrics
Flashcards Review
Chapter Assessment
CDN
What is CDN?
Origin Server vs. Edge Server
CDN Architecture
Push CDN vs. Pull CDN
Flashcards Review
Chapter Assessment
Data Partitioning
Introduction to Data Partitioning
Partitioning Methods
Data Sharding Techniques
Benefits of Data Partitioning
Common Problems Associated with Data Partitioning
Flashcards Review
Chapter Assessment
Redundancy and Replication
What is Redundancy?
What is Replication?
Replication Methods
Data Backup vs. Disaster Recovery
Flashcards Review
Chapter Assessment
CAP & PACELC Theorems
Introduction to CAP Theorem
Components of CAP Theorem
Trade-offs in CAP Theorem
Examples of CAP Theorem in Practice
Beyond CAP Theorem
System Design Trade-offs in Interviews
Flashcards Review
Chapter Assessment
Databases (SQL vs. NoSQL)
Introduction to Databases
SQL Databases
NoSQL Databases
SQL vs. NoSQL
ACID vs BASE Properties
Real-World Examples and Case Studies
SQL Normalization and Denormalization
In-Memory Database vs. On-Disk Database
Data Replication vs. Data Mirroring
Database Federation
Flashcards Review
Chapter Assessment
Indexes
What are Indexes?
How a B-Tree Index Works
Types of Indexes
B-Tree vs. LSM Tree
Indexes in Distributed Systems
Flashcards Review
Chapter Assessment
Bloom Filters
Introduction to Bloom Filters
Benefits & Limitations of Bloom Filters
Variants and Extensions of Bloom Filters
Applications of Bloom Filters
Flashcards Review
Chapter Assessment
Quorum
Why Quorum?
What is Quorum?
Flashcards Review
Chapter Assessment
Leader and Follower
What is Leader and Follower Pattern?
Flashcards Review
Chapter Assessment
Heartbeat
What is Heartbeat?
Flashcards Review
Chapter Assessment
Checksum
What is Checksum?
Uses of Checksum
Flashcards Review
Chapter Assessment
Distributed Messaging System
Introduction to Messaging System
Introduction to Kafka
Messaging patterns
Popular Messaging Queue Systems
RabbitMQ vs. Kafka vs. ActiveMQ
Scalability and Performance
Flashcards Review
Chapter Assessment
Distributed File Systems
What is a Distributed File System?
Architecture of a Distributed File System
Key Components of a DFS
Flashcards Review
Chapter Assessment
Security
What is Security and Privacy?
What is Authentication?
What is Authorization?
Authentication vs. Authorization
OAuth vs. JWT for Authentication
What is Encryption?
What are DDoS Attacks?
Flashcards Review
Chapter Assessment
Misc Concepts
Batch Processing vs. Stream Processing
XML vs. JSON
Synchronous vs. Asynchronous Communication
Push vs. Pull Notification Systems
Microservices vs. Serverless Architecture
Message Queues vs. Service Bus
Stateful vs. Stateless Architecture
Event-Driven vs. Polling Architecture
Flashcards Review
Chapter Assessment
Quiz - System Design Fundamentals
Quiz
System Design Trade-offs
Importance of Discussing Trade-offs
Strong vs Eventual Consistency
Latency vs Throughput
ACID vs BASE Properties in Databases
Read-Through vs Write-Through Cache
Batch Processing vs Stream Processing
Load Balancer vs. API Gateway
API Gateway vs Direct Service Exposure
Proxy vs. Reverse Proxy
API Gateway vs. Reverse Proxy
SQL vs. NoSQL
Primary-Replica vs Peer-to-Peer Replication
Data Compression vs Data Deduplication
Server-Side Caching vs Client-Side Caching
REST vs RPC
Polling vs. Long-Polling vs. WebSockets vs. Webhooks
CDN Usage vs Direct Server Serving
Serverless Architecture vs Traditional Server-based
Stateful vs Stateless Architecture
Hybrid Cloud Storage vs All-Cloud Storage
Token Bucket vs Leaky Bucket
Read Heavy vs Write Heavy System
Quiz
How to Approach a System Design Interview
System Design Interviews - A step by step guide
Functional vs. Non-functional Requirements
What are Back-of-the-Envelope Estimations?
Things to Avoid During System Design Interview
System Design Master Template
System Design Master Template
Quiz
Designing a URL Shortening Service like TinyURL
Designing a URL Shortening Service like TinyURL
Quiz - Designing URL Shortner
Designing Pastebin
Designing Pastebin
Quiz - Designing Pastebin
Designing Instagram
Designing Instagram
Quiz - Designing Instagram
Designing Dropbox
Designing Dropbox
Quiz - Designing Dropbox
Designing Facebook Messenger
Designing Facebook Messenger
Quiz - Designing Facebook Messenger
Designing Twitter
Designing Twitter
Quiz - Designing Twitter
Designing Youtube or Netflix
Designing Youtube or Netflix
Quiz - Designing Youtube
Designing Typeahead Suggestion
Designing Typeahead Suggestion
Quiz - Designing Typeahead Suggestion
Designing an API Rate Limiter
Designing an API Rate Limiter
Quiz - Designing an API Rate Limiter
Designing Twitter Search
Designing Twitter Search
Quiz - Designing Twitter Search
Designing a Web Crawler
Designing a Web Crawler
Quiz - Designing a Web Crawler
Designing Facebook’s Newsfeed
Designing Facebook’s Newsfeed
Quiz - Designing Facebook’s Newsfeed
Designing Yelp or Nearby Friends
Designing Yelp or Nearby Friends
Quiz - Designing Yelp or Nearby Friends
Designing Uber backend
Designing Uber backend
Quiz - Designing Uber backend
Designing Ticketmaster
Designing Ticketmaster
Quiz - Designing Ticketmaster
Dynamo: How to design a key value store?
Dynamo: Introduction
High-Level Architecture
Data Partitioning
Replication
Vector Clocks and Conflicting Data
The Life of Dynamo’s put() & get() Operations
Anti-entropy Through Merkle Trees
Gossip Protocol
Dynamo Characteristics and Criticism
Summary: Dynamo
Quiz: Dynamo
Mock Interview: Dynamo
Designing YouTube Likes Counter (medium)
YouTube Likes Counter
Quiz
Cassandra: How to Design a Wide-column NoSQL Database?
Cassandra: Introduction
High-level Architecture
Replication
Cassandra Consistency Levels
Gossiper
Anatomy of Cassandra's Write Operation
Anatomy of Cassandra's Read Operation
Compaction
Tombstones
Summary: Cassandra
Quiz: Cassandra
Mock Interview: Cassandra
Kafka: How to Design a Distributed Messaging System?
Messaging Systems: Introduction
Kafka: Introduction
High-level Architecture
Kafka: Deep Dive
Consumer Groups
Kafka Workflow
Role of ZooKeeper
Controller Broker
Kafka Delivery Semantics
Kafka Characteristics
Summary: Kafka
Quiz: Kafka
Mock Interview: Kafka
Chubby: How to Design a Distributed Locking Service?
Chubby: Introduction
High-level Architecture
Design Rationale
How Chubby Works
File, Directories, and Handles
Locks, Sequencers, and Lock-delays
Sessions and Events
Master Election and Chubby Events
Caching
Database
Scaling Chubby
Summary: Chubby
Quiz: Chubby
Mock Interview: Chubby
HDFS: How to Design File Storage System?
Hadoop Distributed File System: Introduction
High-level Architecture
Deep Dive
Anatomy of a Read Operation
Anatomy of a Write Operation
Data Integrity & Caching
Fault Tolerance
HDFS High Availability (HA)
HDFS Characteristics
Summary: HDFS
Quiz: HDFS
Mock Interview: HDFS
GFS: How to Design a Distributed File System Storage?
Google File System: Introduction
High-level Architecture
Single Master and Large Chunk Size
Metadata
Master Operations
Anatomy of a Read Operation
Anatomy of a Write Operation
Anatomy of an Append Operation
GFS Consistency Model and Snapshotting
Fault Tolerance, High Availability, and Data Integrity
Garbage Collection
Criticism on GFS
Summary: GFS
Quiz: GFS
Mock Interview: GFS
BigTable: How to Design a Wide Column Storage System?
BigTable: Introduction
BigTable Data Model
System APIs
Partitioning and High-level Architecture
SSTable
GFS and Chubby
Bigtable Components
Working with Tablets
The Life of BigTable's Read & Write Operations
Fault Tolerance and Compaction
BigTable Refinements
BigTable Characteristics
Summary: BigTable
Quiz: BigTable
Mock Interview: BigTable
Designing Reddit (medium)
Design Reddit
Quiz
Designing Notification Service (medium)
Designing a Notification System
Quiz
Design Google Calendar (medium)
Design Google calendar (Medium)
Quiz
Design a Recommendation System (medium)
Design a Recommendation System for Netflix
Quiz
Designing Gmail (medium)
Design Gmail
Quiz
Designing Google News (medium)
Design Google News, a Global News Aggregator System (Medium)
Quiz
Designing Unique ID Generator (medium)
Design Unique ID Generator (Easy)
Quiz
Designing Code Judging System (medium)
Design Code Judging System like LeetCode (Medium)
Quiz
Designing Payment System (hard)
Design Payment System
Quiz
Designing Flash Sale System (hard)
Design a Flash Sale for an E-commerce Site (Hard)
Quiz
Designing Reminder Alert System (hard)
Design a Reminder Alert System
Quiz
System Design Patterns
Introduction: System Design Patterns
1. Bloom Filters
2. Consistent Hashing
3. Quorum
4. Leader and Follower
5. Write-ahead Log
6. Segmented Log
7. High-Water Mark
8. Lease
9. Heartbeat
10. Gossip Protocol
11. Phi Accrual Failure Detection
12. Split Brain
13. Fencing
14. Checksum
15. Vector Clocks
16. CAP Theorem
17. PACELC Theorem
18. Hinted Handoff
19. Read Repair
20. Merkle Trees
Quiz
What is a Proxy Server?
proxy server
reverse proxy
caching
load balancing
+2
An employee opens a news website on a laptop at work. The company network does not send the request straight to the website. It sends the request to a server that contacts the website for the laptop. So the news website sees the company's server, not the laptop.
The news website does something similar on its side. Its many servers stay hidden behind one public server, and that server passes each request to one of them.
So one simple page view passed through two middle servers. Each is a proxy, but they sit on opposite sides and do opposite jobs. This lesson explains both kinds, how they work, and when to use each one.
What a Proxy Is
A proxy is a piece of software or hardware that sits between a client and a server. It facilitates the traffic that flows between them. The client sends its request to the proxy. The proxy forwards the request to the server, receives the response, and passes it back.
Because all traffic passes through it, a proxy can do useful work while the traffic passes. It can hide who sent a request, store responses, block requests, or change them.
The most important question about a proxy is which side it works for.
- A proxy that sits with the clients and acts for them is a forward proxy.
- A proxy that sits with the servers and acts for them is a reverse proxy.
Forward Proxy
A forward proxy is a server that sits in front of one or more client machines. It acts as an intermediary between those clients and the internet. A forward proxy is also known as a proxy server, or simply a proxy.
Here is how a request flows through it.
- A client, like a laptop, requests a resource on the internet, like a web page or a file.
- The request goes to the forward proxy first.
- The forward proxy sends the request to the internet on behalf of the client.
- The website responds to the proxy.
- The proxy returns the response to the client.
A Forward Proxy Hides the Client
Because the proxy sends the request, the website sees the proxy's IP address, not the client's. A forward proxy can hide the identity of the client from the server by sending requests on the client's behalf.
For example, 500 employees may browse the web through one company proxy. Every website they visit sees the same single address, the proxy's.
How Clients Use a Forward Proxy
There are two common ways a client's traffic reaches a forward proxy.
- Configured proxy. The browser or operating system is set to send web requests to the proxy's address.
- Transparent proxy. The network itself sends web traffic through the proxy, so users do not need to change any settings. Many companies and schools work this way.
What a Forward Proxy Can Do
Forward proxies are typically used for four jobs.
- Cache data. The proxy stores copies of popular responses, so repeated requests are answered without going to the internet again.
- Filter requests. The proxy blocks requests to websites or content types that a company or school does not allow.
- Log requests. The proxy records which sites were visited, for security reviews or rules that an organization must follow.
- Transform requests. The proxy changes requests or responses, for example by adding or removing headers, encrypting or decrypting data, or compressing a resource.
Forward Proxies and HTTPS
HTTPS traffic is encrypted, so a normal forward proxy cannot read it. The browser asks the proxy to open a tunnel to the website, using an HTTP method called CONNECT. The proxy then passes the encrypted bytes through without reading them.
So for an HTTPS site, the proxy can see which website the client connects to, and how much data moves. It cannot see the pages, forms, or passwords.
Some companies do inspect HTTPS traffic. They install their own certificate on every company device, which lets the proxy decrypt and check the traffic. Without that certificate installed, the browser would show a warning.
A plain proxy also does not encrypt your traffic on its own. The VPN vs. Proxy Server lesson explains this difference.
Collapsed Forwarding
A proxy receives requests from many clients. That position lets it save work in a way that no single client could.
Suppose several clients request the same data at the same moment, and the data is not in the cache. If every request reached the server directly, the server would read the same data from disk many times.
A proxy can combine those identical requests into one request. The server reads the data from disk only once. The proxy then returns that single result to every client that asked. This technique is called collapsed forwarding. It is also called request coalescing.
Here is the effect in numbers. Suppose 200 users request the same new report at the same moment, and it is not cached yet. Without collapsed forwarding, the server reads the report 200 times. With collapsed forwarding, it reads the report once, and the proxy sends the result to all 200 users.
This matters most right after a cache entry expires. Without collapsed forwarding, every waiting request can reach the server at the same time. With it, only one request reaches the server, and the rest wait for its answer.
Reverse Proxy
A reverse proxy is a server that sits in front of one or more web servers. It acts as an intermediary between those web servers and the internet.
Here is how a request flows through it.
- A client requests a resource from a website.
- The request goes to the reverse proxy first.
- The reverse proxy forwards the request to one of the web servers behind it.
- The web server returns the response to the reverse proxy.
- The reverse proxy returns the response to the client.
A Reverse Proxy Hides the Server
A forward proxy hides the client's identity. A reverse proxy hides the server's identity. The client sees only the reverse proxy's address. It never learns which backend server produced the response, or how many backend servers exist.
Think about requesting a page from facebook.com. Facebook's reverse proxy receives the request. It gets the response from one of many backend servers and returns the response to the client. The client never learns which backend server actually built the page.
What a Reverse Proxy Can Do
Like a forward proxy, a reverse proxy can be used for caching. It can also be used for load balancing or routing requests to the appropriate servers.
- Caching. It stores responses, like images or popular pages, so backend servers do less work.
- Load balancing. It spreads requests across many backend servers, so no single server is overloaded.
- Routing. It sends each request to the right group of servers, often based on the path. For example,
/api/requests go to API servers, and/images/requests go to image servers.
Reverse proxies also often handle HTTPS encryption for the servers behind them, and they protect those servers from direct attacks. The Uses of Proxies lesson covers these jobs in more detail.
Common reverse proxy software includes Nginx, HAProxy, and Envoy. Many other parts of a system are reverse proxies too. A load balancer, a CDN edge server, and an API gateway all sit in front of servers and act for them.
Forward Proxy vs. Reverse Proxy
| Forward proxy | Reverse proxy | |
|---|---|---|
| Sits in front of | Client machines | Web servers |
| Acts on behalf of | The clients | The servers |
| Whose identity it hides | The client's, from the server | The server's, from the client |
| Who sets it up | The side making requests, like a company network | The side serving requests, like a website |
| Typical jobs | Caching, filtering, logging, transforming requests | Caching, load balancing, routing requests |
| Examples | Office and school web proxies | Nginx, load balancers, CDNs, API gateways |
The choice depends on what you want to protect.
- To protect the clients on your internal network, put them behind a forward proxy. It hides the clients that make the requests.
- To protect your servers, put them behind a reverse proxy. It hides the servers that answer the requests.
Key Takeaways
- A proxy is software or hardware that sits between a client and a server to facilitate the traffic between them.
- A forward proxy, also called a proxy server, sits in front of client machines. It hides the client's identity from the server by sending requests on the client's behalf.
- Forward proxies are used to cache data, filter requests, log requests, and transform requests. For HTTPS, a normal forward proxy sees only which site is visited, not the content.
- Collapsed forwarding combines identical requests for uncached data into one request, so the data is read from disk only once.
- A reverse proxy sits in front of web servers. It hides the server's identity from the client, and it is used for caching, load balancing, and routing requests.
- Use a forward proxy to protect clients, and a reverse proxy to protect servers.
A forward proxy acts for the clients, and a reverse proxy acts for the servers. The next lesson, Uses of Proxies, covers the main jobs that proxies do in real systems.
Practice Questions
Try each question first, then open the answer.
1. A company wants every employee's web traffic to be checked against a list of blocked sites and logged. Which kind of proxy fits, and where does it sit?
<details> <summary>Show answer</summary>A forward proxy, in front of the employees' devices. All web requests from the office go through it before they reach the internet. The proxy can then block requests to sites on the list, and log every request. Websites see the proxy's address instead of each employee's device.
</details>2. A website runs 20 backend servers. Users should reach it at one address and never learn the backend servers' addresses. Which kind of proxy fits?
<details> <summary>Show answer</summary>A reverse proxy. It sits in front of the 20 servers and receives every request at one public address. It forwards each request to one of the servers and returns the response. Users never see which server answered, and the proxy can also balance the load across the servers.
</details>3. 200 users request the same report at the same moment, and it is not in the cache. How many times is the report read from disk without collapsed forwarding, and how many times with it?
<details> <summary>Show answer</summary>200 times without it, and once with it. Without collapsed forwarding, each of the 200 requests reaches the server and reads the report separately. With collapsed forwarding, the proxy combines the identical requests into one. The server reads the report once, and the proxy returns that result to all 200 users.
</details>4. An employee visits https://bank.example.com through a normal company forward proxy. What can the proxy see, and what can it not see?
It can see the site's name and how much data moves, but not the pages or passwords. For HTTPS, the browser asks the proxy to open a tunnel with the CONNECT method, and the traffic inside stays encrypted. The proxy can read the content only if the company has installed its own certificate on the device to inspect HTTPS traffic.
5. Is a load balancer a forward proxy or a reverse proxy? Explain.
<details> <summary>Show answer</summary>A reverse proxy. A load balancer sits in front of a group of servers and acts for them. It receives each client request, forwards it to one of the servers, and returns the response. The client sees only the load balancer's address and never learns which server answered.
</details>Discussion
On This Page