Design a voting system
I was asked this
No reports yet. Sign in to say where you were asked it.
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),TallyorResultCalculator, and aPollServicethat 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
What it tests
Sign in to see the worked answer
The full answer, chapter by chapter, with what interviewers expect at each level. New accounts get 5 credits: each one unlocks a question for good.
What the labs asked this week
A weekly email of what OpenAI, Anthropic and the other top AI labs asked engineers, round by round.

