← All problems
Dashboard
Courses
Problems
Badges
Theme
Sign inStart free
Problem 026 · Databases and storage

Design a Polls and Voting App

Easy 30 min

Design a polls app used by creators and TV shows. Anyone signed in can create a poll with up to 10 options; signed-in users vote once per poll and see results update every few seconds. Most days are quiet, but when a TV show puts a poll on screen, a million viewers vote within five minutes and keep refreshing the results. Votes must be counted exactly: no user may vote twice, and no accepted vote may be lost.

Functional requirements

  • Create a poll with a question, 2 to 10 options and an optional closing time
  • Signed-in users vote once per poll and can see which option they chose
  • Show live vote counts and percentages, refreshed every few seconds
  • Close a poll automatically at its closing time

Non-functional requirements

  • Exactly one counted vote per user per poll, even with retries and double taps
  • Voting and result reads respond in under 200 ms at p95
  • Displayed counts may lag by a few seconds but final results are exact

Constraints and scale

  • 1 million votes in 5 minutes on a TV poll: about 3,500 votes per second
  • Peak of 5,000 requests per second including result refreshes
  • 100,000 polls created per day, most with fewer than 1,000 votes

You will practise

  • Enforce uniqueness with a database constraint rather than application checks
  • Serve hot aggregates from cached counters instead of counting rows on every read
  • Separate the exact record of votes from the approximate live display
Show 2 hints
  1. Two requests from the same user arrive 10 ms apart: what stops both from being counted?
  2. Counting a million rows on every refresh is expensive. What could you increment instead?

Ready to build?

Open the canvas, place your components and explain your decisions. Your draft saves automatically.

Sign in to start

Failure scenarios

  • The counter cache restarts mid-pollDuring a TV poll with 400,000 votes so far, the cache node holding the counters restarts and comes back empty.

Run them from the workspace once your design is in place.