Urgent.News

What's breaking now, across hundreds of outlets.

Tech

Amazon Interview Question: Count the Votes. Now Let Everyone Change Their Mind.

One voter, two browser tabs, and the follow ups that turn a simple counter into a system design problem. Maya votes for A, changes her mind, and votes for B. Her connection drops, so her phone sends the second request again. If your system now counts four votes from three people, adding more servers is going to make the wrong answer arrive faster. This is why I like this question. You can…

The Amazon interview question "Count the Votes" involves designing a system for a live poll with millions of concurrent voters. People can change their choices, and results should refresh every second. The goal is to understand the product quickly while designing an architecture that accurately tracks individual choices.

Consider a scenario with three voters: Maya votes for A, Leo for A, and Nia for B. Maya then changes her mind to B, making the final results A = 1 and B = 2. The key rule is that each eligible account contributes at most one current choice per poll. To maintain this rule, store the current choice under the pair of poll ID and voter ID, along with a version number.

When a voter changes their mind, update the record by subtracting from the previous option and adding to the new one as one indivisible operation. Use a transactional datastore to enforce that the old version is used in the transaction, preventing stale states from causing issues. If multiple requests attempt to change the same voter's choice, the transaction that commits first updates the record, while the other request fails due to the version condition.

Handle dropped connections by assigning a stable request ID to each intended change, scoped to the poll and authenticated voter. Persist the outcome in the same transaction as the vote mutation. Include the original request parameters or a fingerprint of them in the record to reject reusing the same ID for different content.

For large-scale traffic, such as three million accounts submitting one change over 300 seconds, split the counters into buckets using a hash of poll ID and voter ID. Assign each voter to a stable bucket, ensuring their current choice and changes always use the same bucket during the poll. This approach helps avoid contention points and enables efficient aggregation of bucket totals.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

Report a problem with this story

More in Tech

Play random sound variations in Godot 4

The same footstep, hit or coin sound playing over and over starts to sound mechanical. You recorded several takes. Here is how to make Godot 4 pick between them.

  • AudioStreamRandomizer resource allows multiple sound variations in Godot 4
  • Playback modes include random with no repeats, random, or sequential
  • Cue Banks for Godot 4 tool simplifies creating and managing sound banks

Working with Canadian benefit payment dates in JavaScript

If you build a budgeting app or a reminder bot for people in Canada, someone will ask: "When does my CPP come in?" It looks like a date-math problem. Mostly it isn't.

  • Canadian CPP payments dates listed on canada.ca
  • Daybook Times stores published list, not computes dates
  • CDB payment date calculated as third Thursday of month

Approved, but Locked Outside My Own House 🐝🔑

Sorry for my absence 😅 I was busy finishing something: a WordPress plugin for BeeLadybug, written in PHP. Just a small first piece, but mine. 🐞 Here's how it went.

  • WordPress plugin BeeLadybug approved by WordPress.org
  • Antonio Prosperi's account blocked after plugin submission
  • BeeLadybug inspects WordPress sites for layout issues

More from Tuesday, 1 December 2026 →