Designing Large-Scale System Examples
1. Designing URL Shortener System
| Component | Detail |
|---|---|
| ID generation | Base62 of counter (Snowflake) or hash + collision check |
| Storage | K/V (DynamoDB / Redis-persistent); short_code → long_url |
| Read path | 302 redirect; cache hot codes |
| Analytics | Click events → Kafka → DW |
| Scale | ~100K reads/sec; CDN-cacheable redirects |
| Custom alias | Reserve namespace |
Example: short code lookup
String longUrl = cache.getOrLoad(code, () ->
db.findLongUrl(code).orElseThrow(NotFound::new));
return Response.status(302).location(URI.create(longUrl)).build();
2. Designing Social Media Feed System
| Approach | Detail |
|---|---|
| Fan-out on write | Push post to followers' feeds; fast read |
| Fan-out on read | Aggregate at read; better for celebs |
| Hybrid | Push for normal, pull for celebrities |
| Storage | Per-user feed in Redis/Cassandra |
| Ranking | ML model on candidate set |
| Pagination | Cursor by score / time |
3. Designing Video Streaming Platform
| Component | Detail |
|---|---|
| Upload | Multipart to S3 |
| Transcode | HLS/DASH ladder via MediaConvert |
| Storage | Object store + CDN |
| Delivery | HLS over CDN; adaptive bitrate |
| Metadata | DB; search via ES |
| DRM | Widevine / FairPlay / PlayReady |
| Recommendation | Collaborative + content-based ML |
4. Designing Ride-Sharing System
| Component | Detail |
|---|---|
| Driver location | Stream to Tile38/Redis (H3 cells) |
| Matching | Geo query nearest available; ETA + price |
| Trip state machine | requested → matched → en-route → arrived → in-trip → completed |
| Pricing | Surge based on supply/demand per cell |
| Payment | Hold → capture on completion |
| Map / routing | OSRM / vendor |
5. Designing E-commerce Platform
| Bounded Context | Detail |
|---|---|
| Catalog | Products, search (ES/Vespa) |
| Cart | Per-user; Redis + DB persistence |
| Inventory | Reservations; eventually consistent |
| Order | Saga across cart/inventory/payment |
| Payment | Stripe / Adyen integration |
| Fulfillment | Warehouse / shipping events |
| Recommendation | Online + offline scoring |
6. Designing Chat Application
| Component | Detail |
|---|---|
| Connection | WebSocket gateway, sticky LB |
| Backplane | Redis / NATS for cross-node fan-out |
| Storage | Cassandra/DynamoDB partitioned by chat_id |
| Receipts | sent / delivered / read |
| Push | FCM/APNs when offline |
| E2E | Optional Signal protocol |
| Search | Per-user index in ES |
7. Designing Search Engine
| Component | Detail |
|---|---|
| Crawler | Distributed; respect robots.txt |
| Indexer | Inverted index; Map-Reduce / Spark |
| Storage | Sharded; per-term posting lists |
| Query | Tokenize → fan-out shards → merge top-K |
| Ranking | BM25 + LTR + signals (PageRank, freshness) |
| Hybrid | + vector search for semantic |
8. Designing Rate Limiter Service
| Element | Detail |
|---|---|
| API | check(key, cost) → allow/deny + reset |
| Algorithm | Token bucket via Redis Lua (atomic) |
| Storage | Redis cluster, sharded by key |
| Local cache | Pre-allocate slice for low-latency |
| Multi-tier limits | per-second / minute / day |
| Failure mode | Fail-open with sample logging |
9. Designing Distributed Cache System
| Component | Detail |
|---|---|
| Sharding | Consistent hashing |
| Replication | Primary + replicas per shard |
| Eviction | LRU / LFU / TTL |
| Client | Smart client routes by hash |
| Hot key | Local cache + jitter |
| Examples | Memcached, Redis Cluster, Hazelcast |
10. Designing Newsfeed Ranking System
| Stage | Detail |
|---|---|
| Candidate gen | Friends, follows, recommended sources |
| Filter | Already seen, blocked, policy |
| Scoring | ML model predicts engagement |
| Re-ranking | Diversity, freshness, business rules |
| Serving | Pre-computed + on-demand |
11. Designing Notification Platform
| Component | Detail |
|---|---|
| Ingest API | Notification request |
| Preference + targeting | Resolve channels per user |
| Templating | Localized renders |
| Channel adapters | Email/SMS/push/in-app |
| Queue per channel | Rate-limited workers |
| Tracking | Webhooks → status DB |
| Analytics | Delivery, open, click rates |
12. Designing Ticketing System
| Component | Detail |
|---|---|
| Inventory | Per-event seat map |
| Hold | Reserve seat for N min via Redis lock |
| Queue | Virtual waiting room for high-demand drops |
| Checkout | Idempotent; payment integration |
| Anti-bot | CAPTCHA, device fingerprint, rate limit |
| Resale / transfer | Marketplace flow |
| Scale spike | Pre-scale + queue + CDN-cached static |