System Design Interview: Designing a Real-Time Live Polling System
3 views
"Design a live polling system" is a compact system design interview question. Think of a webinar or a conference talk where a host launches a question, tens of thousands of viewers vote within thirty seconds, and everyone watches the bar chart update live. It is small enough to finish in 45 minutes, yet it touches write spikes, fan-out, and consistency.
1. Clarify requirements
Functional: hosts create a poll with options, open and close it; viewers vote once per poll; everyone sees near-real-time results. Non-functional: a single poll might take 100k votes in under a minute, result updates should appear within about one second, and a final tally must be exact. Ask whether votes can be changed and whether results are hidden until the poll closes, because both change the design.
2. Rough numbers
If 100k viewers vote within 20 seconds, that is roughly 5k writes per second for one hot key, with bursts higher. Reads are fan-out: pushing a result update to 100k connections once a second is 100k messages per second, which is the real cost.
3. High-level design
- Poll service: stores poll metadata (id, options, state, timestamps) in a relational database.
- Vote API: validates the poll is open and the user has not voted, then records the vote.
- Dedup store: a set keyed by poll_id containing user_ids, for example in Redis with SADD, which returns whether the member was new. Persist votes durably as well, e.g. appending to a log or a votes table with a unique (poll_id, user_id) constraint.
- Counters: increment per-option counters in Redis. For a very hot poll, shard each counter into N sub-keys and sum them when reading, so one key does not become a bottleneck.
- Results broadcaster: every 500 ms to 1 s, read the aggregated counts and publish one snapshot to a pub/sub channel. WebSocket gateway servers subscribe and push the snapshot to connected viewers.
4. Why batch the broadcast?
Pushing every single vote to every viewer is O(votes x viewers). Snapshotting on a timer caps fan-out at viewers per tick, no matter how many votes arrive. This is the key insight interviewers look for.
5. Correctness and the final tally
Live counts in Redis can be slightly off after a failure. When the poll closes, compute the authoritative result from the durable vote records and publish it as final. Mention idempotency keys on the vote request so client retries do not double count.
6. Scaling and failure modes
- WebSocket gateways scale horizontally; use sticky connections and let clients reconnect and fetch the latest snapshot.
- Rate-limit votes per user and per IP to blunt bots.
- If Redis is unavailable, queue votes durably and show "results updating" instead of wrong numbers.
7. Trade-offs to discuss
Exact live counts versus cheaper approximate ones, push (WebSocket) versus polling every few seconds for smaller events, and whether to show results before closing at all, which affects voter behavior.
Practice saying this structure aloud: requirements, numbers, design, the batching insight, then failure modes. If you want support while the interviewer pushes on follow-ups, Linkjob AI (https://linkjob.ai) offers real-time help during job interviews and technical interviews, including system design rounds.