You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
The best way to internalise system design principles is to apply them. This lesson walks through four real-world system designs: a URL shortener, a chat system, a news feed, and a notification service. Each follows the framework: requirements, estimation, high-level design, component breakdown, and trade-offs.
Functional:
Non-Functional:
graph LR
Client["Client"] --> LB["Load Balancer"]
LB --> App["App Servers"]
App --> Cache["Cache (Redis)"]
App --> DB["Database (NoSQL)"]
App --> ID["ID Generator"]
Use Base62 encoding (a-z, A-Z, 0-9) with a 7-character key:
With a 7-character code, base-62 (using a–z, A–Z and 0–9) gives 62⁷ ≈ 3.5 trillion possible URLs — enough for years. The numeric ID is simply encoded into that base: for example, 1234567 becomes "5BAN".
ID Generation options:
| Decision | Trade-off |
|---|---|
| NoSQL over SQL | Better horizontal scaling, but no native joins |
| Cache-heavy | Fast reads, but cache invalidation complexity |
| Base62 over hash | Shorter URLs, but needs unique ID generation |
| Eventual consistency | Higher availability, but stale reads possible |
Functional:
Non-Functional:
graph TD
CA["Client A"] ==>|"WebSocket"| CS["Chat Server (stateful WebSocket connection)"]
CB["Client B"] ==>|"WebSocket"| CS
CS --> MQ["Message Queue (Kafka)"]
CS --> PR["Presence Service (Redis)"]
CS --> MS["Media Storage (S3)"]
MQ --> MDB["Message Database (Cassandra)"]
graph TD
S1["1. Client A sends message via WebSocket"] --> S2["2. Chat server receives message"]
S2 --> S3["3. Message published to Kafka"]
S3 --> S4["4. Message persisted to Cassandra"]
S4 --> S5["5. If Client B online: push via WebSocket"]
S4 --> S6["6. If Client B offline: store for later delivery"]
S5 --> S7["7. Delivery confirmation sent back to Client A"]
| Component | Choice | Reasoning |
|---|---|---|
| Connection | WebSocket | Bidirectional, low latency |
| Message store | Cassandra | Write-heavy, partitioned by chat_id |
| Message queue | Kafka | Ordered delivery, replay capability |
| Presence | Redis | Fast reads/writes, TTL for timeout |
| Media | S3 + CDN | Scalable blob storage |
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.