Part 4 of 7 · 2 min read
Prompts 11-20
Streams of events and people.
| # | Prompt | Level | Ask and estimate | Core idea |
|---|---|---|---|---|
| 11 | Design a comment system for a news site. | M | Comments a day, depth, moderation | Tree or flat with parent id, pagination, a cache for popular pages. |
| 12 | Design a leaderboard for a mobile game. | M | Players, updates a second, top N | Sorted set per board, shard by board, periodic snapshots. |
| 13 | Design live comments for a video stream. | H | Viewers, comments a second | Fan-out through pub/sub (page 1), sampling when too fast, one channel per stream. |
| 14 | Design a group chat with read receipts. | H | Groups, size, messages a second | Per-conversation ordering, message ids, receipts as small events. |
| 15 | Design a notification system for push, email and SMS. | M | Messages a day, channels, priorities | Queue per channel, templates, user preferences, retries, dedupe. |
| 16 | Design a polling and voting service for a TV show. | H | Votes a second at the peak, fraud | Count in sharded counters, one vote per user check, eventual totals. |
| 17 | Design a trending topics service. | M | Events a second, window | Stream processing with a sliding window and a top-K structure. |
| 18 | Design an online presence service (green dot). | M | Users, heartbeat rate | Heartbeats into a store with expiry, fan-out limited to friends who watch. |
| 19 | Design a live sports score service. | M | Matches, viewers | Push through WebSocket, CDN for non-live pages, a single source of truth. |
| 20 | Design a shared shopping list for families. | E | Users, lists | Small documents with versions, push on change, last writer wins or merge. |
What a good answer adds.
- For 13, 14, 16: do the peak arithmetic. A show with 5 million viewers and 2 per cent voting within 1 minute is 100,000 votes in 60 seconds, about 1,700 a second, which one sharded counter set absorbs easily. If 30 per cent vote in 10 seconds, it is 150,000 a second, and the design must buffer.
- For 12: say how a rank for any player (not just the top) is found, for instance a sorted set that gives rank by score.
- For 17: say why a count-min sketch (a small table that estimates counts) or a sharded counter is chosen when exact counts are too costly.
Check yourself: 1. In prompt 16, what changes if the vote window shrinks from 1 minute to 10 seconds? 2. Why limit the fan-out for presence? 3. What does a sorted set give a leaderboard?