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
Proxies
What is a Proxy Server?
Uses of Proxies
VPN vs. Proxy Server
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
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
REST vs RPC
api design
rest
rpc
http
+1
An online store is being split into services. To create an order, the order service must now ask the catalog service for a product's price, over the network.
Every call between services needs a shape. Should the API name things, like "product 42"? Or should it name actions, like "get product 42"?
That is the difference between REST and RPC. This lesson explains both styles, what each one costs, why the data format is not the real difference, and where each style is usually used.
Two Ways to Design a Call
In REST, the API names things, called resources. For example, GET /products/42 asks for one product. The URL names the product, and the HTTP method, GET, says what to do with it.
In RPC, which stands for Remote Procedure Call, the API names actions. For example, GetProduct(42) calls a function that runs on another machine. RPC is procedure-oriented: the client calls what looks like a normal function.
REST
REST treats a system as a collection of resources. Each resource has its own URL, and the standard HTTP methods act on it:
GET /products list the products
POST /products create a new product
GET /products/42 read product 42
PUT /products/42 replace product 42
DELETE /products/42 delete product 42
The methods have agreed meanings. GET is safe, which means it only reads data. GET, PUT, and DELETE are also idempotent, which means repeating the same request has the same effect as sending it once. So a client can safely retry them after a timeout. POST is not idempotent, so a retry may create a second product.
What REST Gives You
- A uniform interface. Every resource uses the same few methods. Any developer with any HTTP client can call the API.
- Statelessness. Each request carries everything the server needs, so any server can answer any request. The Stateful vs Stateless Architecture lesson explains why this helps scaling.
- Caching by existing infrastructure. Browsers, CDNs, and proxies know that a
GETresponse can often be stored and reused. They can cache it without understanding your application. The Caching lesson covers these layers. - Easy debugging. Responses are usually readable JSON text. You can test any endpoint with a browser or a command-line tool like curl.
What REST Costs You
- Over-fetching and under-fetching. Each endpoint returns a fixed shape. Over-fetching means the client downloads fields it does not use. Under-fetching means one screen needs data from several resources, so the client makes several round trips.
- Awkward actions. "Send this invoice for approval" is an action, not a thing. Forcing it into a resource can produce strange URLs, like
POST /invoices/42/approval-requests. - No enforced contract. REST is a set of conventions. Tools like OpenAPI can describe an API, but nothing forces the client and server to agree. A breaking change may be found only when a client fails.
RPC and gRPC
With RPC, the client calls a function. A framework packs the arguments, sends them over the network, runs the function on the server, and returns the result.
In modern systems, RPC often means gRPC, an open source RPC framework. Three features define it.
1. A written contract. Every method, argument, and return type is described in a .proto file:
service Catalog {
rpc GetProduct (GetProductRequest) returns (Product);
}
message GetProductRequest {
int64 id = 1;
}
message Product {
int64 id = 1;
string name = 2;
int64 price_cents = 3;
}
2. Code generation. Tools generate the client code and the server code from this file. If a team renames a field, code that still uses the old name no longer compiles. The mistake appears when the code is built, not when users are affected.
3. A compact, fast wire format. Messages are encoded as Protocol Buffers, a compact binary format. They travel over HTTP/2, which can carry many calls on one connection at the same time. gRPC also supports streaming, where one call carries a sequence of messages, in either direction.
What gRPC Gives You
- Speed. Binary messages are usually smaller than JSON, and faster to read and write. Reusing connections avoids repeated setup work. This matters most when one user request causes many internal calls.
- Safety. The generated contract prevents many mistakes between the client and the server.
- Streaming. A server can send a stream of results over a single call.
- Natural actions. Calls like
ApproveInvoicefit naturally, because they are already functions.
What gRPC Costs You
- Browsers cannot call it directly. gRPC needs features of HTTP/2 that browsers do not expose. A browser needs a translation layer, like gRPC-Web, or a REST API in front.
- Not readable. Binary messages cannot be read by eye, so debugging needs special tools.
- No HTTP caching. Every gRPC call is sent as an HTTP
POST. So CDNs and proxies cannot cache the responses. - Tighter coupling. Both sides are built from the same contract. Changes need coordination between the teams.
The Difference Is Not the Data Format
A common shortcut says that REST is "the JSON one", and gRPC is "the binary one". That shortcut is wrong.
A REST API can return JSON, XML, HTML, or an image. Content negotiation is the HTTP feature that lets a client ask for the format it prefers. And RPC is not always binary. For example, JSON-RPC sends plain JSON text.
Most REST APIs do use JSON, and gRPC does use Protocol Buffers. But that is a common choice, not the real difference. The real difference is what the API names, and what is enforced. REST names resources and relies on conventions. gRPC names procedures and enforces a contract through generated code.
The caching difference follows from this. A REST GET can be answered by a cache on the way to the server. A gRPC call always reaches the server.
Where Each Style Is Usually Used
The two styles are not really competitors. Most large systems use both, in different places.
REST is used at the edge. The callers there are browsers, mobile apps, and outside developers. You do not control those clients, so the universal and cacheable option is the better fit. An API gateway usually receives this traffic.
gRPC is used inside the system. Between your own services, you control both sides. One user request may cause many internal calls, so speed matters. The enforced contract also prevents mistakes between teams.
One more style is worth knowing. GraphQL is a query language where the client lists exactly the fields it wants. It was created to fix over-fetching and under-fetching. Its costs are that normal HTTP caching works less well, and the server must be protected from very expensive queries.
REST vs. gRPC
| REST | gRPC | |
|---|---|---|
| The API names | Resources (things) | Procedures (actions) |
| Transport | Any version of HTTP | HTTP/2 |
| Data format | Any format, usually JSON | Protocol Buffers (binary) |
| Contract | Conventions, optionally described with OpenAPI | Enforced by generated code |
| HTTP caching | Works | Not available |
| Streaming | Limited | Built in, in both directions |
| Browser support | Built in | Needs a translation layer |
| Usual place | The public edge | Calls between internal services |
Choosing Between Them
- A public API, outside developers, or browsers: use REST. You do not control the callers, so universal support and caching matter most.
- Many calls between internal services: use gRPC. You control both sides, and speed and the contract matter.
- Streaming between services: use gRPC, because streaming is built in.
- A mobile screen that needs data from many resources: consider GraphQL, or one endpoint designed for that screen.
- Both needs in one system: use both. REST at the edge and gRPC inside is the usual design, not a compromise.
Using This in an Interview
The expected design is REST at the edge and gRPC inside. What earns credit is the reason. For example: "Services call each other with gRPC, because one request causes eight internal calls. Binary messages over shared HTTP/2 connections reduce that latency. The public API uses REST, because browsers and partners cannot call gRPC directly."
Two follow-up questions are common:
- "Why not use gRPC everywhere?" Browsers need a translation layer to call it, and responses cannot use HTTP caching.
- "Isn't REST just JSON?" No. REST can return XML or other formats. The real difference is resources versus procedures.
Key Takeaways
- REST names resources and uses HTTP methods to act on them. It relies on conventions, not an enforced contract.
- REST gives universal clients, stateless requests, caching by existing infrastructure, and easy debugging.
- RPC is procedure-oriented: the client calls a remote function. gRPC encodes messages in Protocol Buffers, a compact binary format, and sends them over HTTP/2.
- gRPC gives speed, a contract enforced by generated code, and built-in streaming. But browsers cannot call it directly, and it cannot use HTTP caching.
- The data format is not the real difference. The difference is naming resources versus naming procedures.
- Use REST for the public edge, and gRPC for calls between internal services. Most real systems use both.
REST and gRPC answer the same question in different ways: what does a call between two systems look like? The next lesson, Synchronous vs Asynchronous Communication, looks at a different question: whether the caller should wait for the answer.
Practice Questions
Try each question first, then open the answer.
1. A company is building a public API for outside developers, who will call it from browsers, mobile apps, and scripts. Should it use REST or gRPC?
<details> <summary>Show answer</summary>REST. The company does not control the callers, and REST works with any HTTP client, including browsers. GET responses can also be cached by browsers and CDNs. gRPC would need a translation layer for browsers, and developers would need special tools to read the messages.
2. One user request causes 8 internal calls. With example numbers, each call spends 3 ms on JSON and connection setup, but only 0.5 ms with gRPC. How much time does gRPC save for each user request?
<details> <summary>Show answer</summary>About 20 ms. Each call saves 3 - 0.5 = 2.5 ms. With 8 calls, the saving is 8 x 2.5 = 20 ms for every user request. The saving grows with the number of internal calls, which is why gRPC is popular between services.
</details>3. A REST API has the endpoint POST /invoices/42/approval-requests. Why does it look strange, and what would the RPC version look like?
"Approve this invoice" is an action, not a thing. REST works best with resources, so an action must be turned into a strange resource, like "approval requests". In RPC, the action is simply a function, like ApproveInvoice(invoice_id: 42). Many REST APIs accept a few action-style endpoints for cases like this.
4. A team renames the price field to price_cents in a REST JSON response. An older mobile client still reads price, and it fails in production. How would a gRPC contract help?
The mistake would appear at build time. With gRPC, both the client code and the server code are generated from the same .proto file. After the rename, code that still uses the old field name does not compile. So the team finds the problem before the release, not after users are affected.
5. A product page, GET /products/42, is requested 1,000,000 times per day. A CDN answers 90 percent of these requests from its cache. How many requests reach the servers, and what would change if the page data came through gRPC instead?
100,000 requests reach the servers with REST. The CDN answers 90 percent, so the other 10 percent, or 100,000 requests, reach the servers. Every gRPC call is sent as a POST, so the CDN cannot cache it. All 1,000,000 requests would reach the servers, which is 10 times the load.
Discussion
On This Page