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:
Write QPS = 100M / 86,400 ≈ 1,160 writes/sec
Read QPS = 1B / 86,400 ≈ 11,600 reads/sec
Storage per URL ≈ 500 bytes (short URL + long URL + metadata)
Daily storage = 100M × 500 = 50 GB/day
5-year storage = 50 × 365 × 5 ≈ 91 TB
┌──────────┐ ┌──────────────┐ ┌───────────────┐
│ Client │────▶│ Load Balancer│────▶│ App Servers │
└──────────┘ └──────────────┘ └──────┬────────┘
│
┌─────────┼─────────┐
│ │ │
▼ ▼ ▼
┌────────┐┌────────┐┌────────┐
│ Cache ││Database││ ID │
│(Redis) ││(NoSQL) ││Generator│
└────────┘└────────┘└────────┘
Use Base62 encoding (a-z, A-Z, 0-9) with a 7-character key:
62^7 = 3.5 trillion possible URLs (sufficient for years)
ID → Base62 conversion:
1234567 → "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:
┌──────────┐ WebSocket ┌──────────────┐
│ Client A │═════════════════▶│ Chat Server │
└──────────┘ │ (stateful │
│ WebSocket │
┌──────────┐ WebSocket │ connection)│
│ Client B │═════════════════▶│ │
└──────────┘ └──────┬───────┘
│
┌──────────┼──────────┐
│ │ │
▼ ▼ ▼
┌──────────┐┌────────┐┌──────────┐
│ Message ││Presence││ Media │
│ Queue ││Service ││ Storage │
│ (Kafka) ││(Redis) ││ (S3) │
└──────┬───┘└────────┘└──────────┘
│
▼
┌──────────┐
│ Message │
│ Database │
│(Cassandra)│
└──────────┘
1. Client A sends message via WebSocket
2. Chat server receives message
3. Message published to Kafka
4. Message persisted to Cassandra
5. If Client B is online → push via WebSocket
6. If Client B is offline → store for later delivery
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 |
Functional:
Non-Functional:
Fan-out on Write (Push): Fan-out on Read (Pull):
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.