📝 Problem Description
Design a system that shows likes updating in real-time on posts. When someone likes a post, all users viewing that post should see the count increment live. Handle high-engagement viral posts with millions of likes per minute.
👤 Use Cases
1.
User wants to likes a post so that like count increments for all viewers
2.
User wants to views a post so that sees live-updating like count
3.
Viral post wants to receives 1M likes/min so that system handles scale gracefully
✅ Functional Requirements
- •Like/unlike a post
- •Show like count in real-time
- •Show who liked (subset of friends)
- •Handle both real-time updates and current count
⚡ Non-Functional Requirements
- •Like action completes in < 100ms
- •Count updates within 1 second
- •Support posts with 100M+ likes
- •Handle 1M likes/sec on viral posts
⚠️ Constraints & Assumptions
- •Cannot push to all 2B users for every like
- •Viral posts need special handling
- •Count consistency not strict (eventual OK)
📊 Capacity Estimation
👥 Users
2B total users, 100M DAU
💾 Storage
100TB (likes data)
⚡ QPS
Likes: 100K/sec, Count reads: 1M/sec
📐 Assumptions
- • 100M DAU
- • Average 50 likes per user per day
- • 10M posts viewed at any moment
- • Viral posts: 1M viewers simultaneously
💡 Key Concepts
CRITICAL
Counter with Sharding
For viral posts, use multiple counter shards to avoid hot key.
HIGH
Batched Updates
Don't push every like individually; batch updates every 100ms.
HIGH
Post-based Channels
Only viewers of a post subscribe to its update channel.
MEDIUM
Approximate Counts
For very high counts, approximate is acceptable (1.2M vs 1,234,567).
💡 Interview Tips
- 💡Start with the sharded counter pattern
- 💡Discuss the hot post detection mechanism
- 💡Emphasize the real-time update requirements
- 💡Be prepared to discuss eventual consistency
- 💡Know the tradeoffs between accuracy and performance
- 💡Understand the WebSocket/SSE for live updates