← Questions

Design a voting system

0
AmazonAppleOO designLast asked May 2026

An object-oriented design interview question asked in Apple's technical phone screen and at Amazon, last asked May 2026. It tests object-oriented design.

Design the object model for a polling or voting system. A poll has a question and options, a set of eligible voters, and an open and close time. Each voter casts one vote, can change it until the poll closes, and the results are tallied. Focus on classes, the rules that keep one vote per voter, and how results are counted.

Requirements

  • Functional: create a poll with options, an eligible voter list (or "anyone signed in"), and open and close times; cast a vote for one option; change the vote while the poll is open; close the poll at its end time or manually; show results (counts and percentages per option), live or only after closing as the poll's creator chooses.
  • One voter, one counted vote; a changed vote replaces the earlier one.
  • Non-functional: votes cast at the same moment are all counted; results are reproducible from the stored ballots; the voting method can be extended later.

Clarifying questions

  • Single choice only, or also multiple choice and ranked choice?
  • Are votes anonymous? Can anyone see who voted for what?
  • Who can create polls and see results before closing?
  • How are voters identified and eligibility checked?
  • Is an audit trail of vote changes required?

What a strong answer covers

  • Core classes: Poll (question, options, eligibility, schedule, status, result visibility), Option, Voter, Ballot (voter, poll, choice, timestamps), VotingRule (single choice, multiple choice, ranked), Tally or ResultCalculator, and a PollService that validates and records ballots.
  • One ballot per voter per poll, keyed by (poll_id, voter_id), so changing a vote is an update, not a second vote.
  • Poll states (draft, open, closed) and rejecting votes outside the open window.
  • Tallying as a strategy per voting rule, recomputable from ballots, plus running counters updated on cast and change for fast live results.
  • Anonymity: separating who voted from what they voted when required.
  • Tests: a vote change, a vote after close, an ineligible voter, ties.

Follow-ups

  • Add ranked-choice voting with instant-runoff counting.
  • Polls with millions of voters: how do live counts stay correct and fast?
  • Prevent one person from voting with several accounts.

Where it's asked

  • Apple · Technical phone screen · Last asked May 2026
  • Amazon

What it tests

object-oriented design

Your canvas
Draw your answer hereBoxes, arrows and notes, saved for you to come back to.Sign in to start drawing