Module Review: Real-Time Systems
[!IMPORTANT] In this module review, you will reinforce:
- Key Architectural Trade-offs: Reviewing latency, state management, and consistency.
- Real-Time Components: Understanding when to use WebSockets, Redis, and Pub/Sub.
- High Concurrency Techniques: Handling thundering herds, overselling, and C10M.
1. Key Concepts Summary
In this module, we explored how to build systems that react instantly to user actions.
- Latency is the Enemy: For “Real-Time”, we often trade Strong Consistency for Availability and Low Latency (AP systems).
- Stateful vs Stateless: WebSockets introduce stateful connections, making scaling harder (Need Sticky Sessions or Pub/Sub Backplanes).
- Concurrency: Handling millions of concurrent writes (Likes, Sales) requires moving locks out of the Database and into Memory (Redis).
2. Quick Reference Cheat Sheet
| Problem | Solution | Trade-off |
|---|---|---|
| Counting at Scale | Sharded Counters (Redis) | Harder to get “Exact” count instantly. |
| Real-Time Feed | WebSockets (2-way) or SSE (1-way) | Stateful servers require intricate load balancing. |
| Leaderboard | Redis Sorted Sets (Skiplists) | RAM usage grows with user count. |
| Flash Sale | Redis Atomic Counters (Lua) | If Redis crashes without AOF, stock count is lost. |
| Chat Fanout | Gateway Aggregation + Pub/Sub | Complexity in managing subscriptions. |
| Thundering Herd | Jitter (Random Backoff) | Slightly slower recovery time. |
| Overselling | Lua Scripting (Atomic Check-and-Set) | Complex to debug Lua scripts. |
| Hot Partition | Virtual Buckets / Consistent Hashing | Resharding is complex. |
| Group Messaging | Pub-Sub + Message Sequencers | High delivery latency for huge groups. |
| C10M Problem | Kernel Tuning / Ephemeral Ports | Requires deep OS knowledge. |
| Approximate Counting | HyperLogLog (Probabilistic) | ~0.81% error rate. |
3. Flashcards
Test your knowledge by clicking the cards to flip them.
Wait! How do we scale WebSockets?
(Click to reveal)
Why Redis ZSET for Leaderboards?
(Click to reveal)
Pessimistic vs Optimistic Locking?
(Click to reveal)
Long Polling vs SSE?
(Click to reveal)
How to handle "Approximate" Counts?
(Click to reveal)
What is a "Thundering Herd"?
(Click to reveal)
What is the "Funnel Architecture"?
(Click to reveal)
Why use Lua Scripts in Redis?
(Click to reveal)
What is the C10M Problem?
(Click to reveal)
What is a CRDT?
(Click to reveal)
Why is Redis Single-Threaded?
(Click to reveal)
Skiplist vs B-Tree for Leaderboards?
(Click to reveal)
What are Sticky Sessions?
(Click to reveal)
Why Gateway Aggregation?
(Click to reveal)
4. Final Assessment
If you can explain how to prevent overselling 100 iPhones to 1 Million users without crashing the DB, you are ready for the interview!
5. Next Steps
You’ve mastered Real-Time Systems and high concurrency! Next, we dive into uniquely constrained architectures that require domain-specific data structures.