
Building Live Polls Without REST APIs Using AWS Blocks
Building a real-time polling app is more than creating a form and counting votes. It requires secure authentication, duplicate vote prevention, live result updates, concurrency control, and automatic poll closure. In this article, I show how I built a multi-user polling application using AWS Blocks with AuthBasic, DistributedTable, Realtime, CronJob, and ApiNamespace—without writing REST APIs, while keeping the entire application running locally with npm run dev.
Series: Series: AWS User Group Madurai - Skill Sprint Challenge - DevTool Month - AWS Blocks (3 articles)
- 2Building Live Polls Without REST APIs Using AWS Blocks This article
Every conference, classroom, workshop, and online event eventually hits the same moment: "Let's take a quick vote."
The answer usually comes from a polling app.
Building one sounds straightforward. A question. A few options. A timer. A Vote button.
But behind that simple interface is a surprisingly tricky engineering problem.
How do you stop the same person from voting twice - without a race condition? How do dozens of connected browsers all see updated results the instant a vote lands? How do polls automatically close when the timer runs out, even if no one is watching? How does a user who reconnects mid-poll immediately see the current state? How do you make sure a late-arriving result doesn't overwrite a more recent one?
I wanted to build something that solved all of these problems without spending the week assembling authentication flows, WebSocket handlers, background workers, database schemas, and REST endpoints from scratch.
That's where AWS Blocks came in.
Instead of wiring infrastructure piece by piece, I composed five building blocks - auth, a distributed table, real-time pub/sub, a cron job, and a typed API surface - and focused almost entirely on the polling logic itself. The Live Voting Polls app is what came out of that experiment.
Why Polling Applications Are Harder Than They Look
A polling app isn't just another CRUD application. It's a small distributed system.
Every vote affects every connected user simultaneously. That means several problems have to be solved at once - and they all interact with each other.
Authentication. Duplicate vote prevention. Concurrent updates. Live result synchronization. Automatic poll expiry. Durable storage. Reconnect recovery.
Get any one of these wrong and you end up with inconsistent results: double-counted votes, stale counts frozen on screen, polls that never close, or users who reconnect to a blank page.
That's exactly what made a polling app the right subject for exploring AWS Blocks. Each of those hard problems maps cleanly onto a building block - and composing them together is where the interesting engineering happens.
Why AWS Blocks?
Without AWS Blocks, building this app the traditional way would mean assembling every layer from scratch:
REST API routes → Authentication → Database schema → WebSocket server → Background scheduler → Frontend HTTP client → Deployment config
Instead, AWS Blocks replaced each of those layers with a composable building block:
Block | Responsibility |
|---|---|
AuthBasic | Sign-up, sign-in, and sessions |
DistributedTable | Poll metadata and vote records |
Realtime | Live vote count delivery to all browsers |
CronJob | Automatic poll expiry every minute |
ApiNamespace | Typed API surface shared by frontend and backend |
Scope | Application namespace and resource isolation |
The biggest surprise was what disappeared entirely.
There isn't a single REST endpoint in this app. No URL strings. No fetch calls. Instead of writing:
fetch('/api/castVote', { method: 'POST', body: JSON.stringify({ pollId, optionId }) })
the frontend just imports and calls:
await api.castVote(pollId, optionId)
The backend function is called like any local function -but it runs server-side, with full access to the database and session context. The transport is invisible, and the types flow end-to-end. If you rename a parameter on the backend, the frontend won't compile until you update the call site.
Architectural Diagram:

Sequence Diagram

How I Built It Authentication Started with AuthBasic. Immediately got: - Sign up - Sign in - Session management - Protected backend APIs - No custom authentication code. Poll Storage Used a single DistributedTable with a smart key design. One table holds everything - poll metadata and votes live side by side, distinguished by recordType. Poll records carry the question, options, and vote counts. Vote records use vote:<userId> as the sort key, which makes duplicate detection a zero-cost lookup. Keeping both in one table meant every query - get a poll, check a vote, scan results - was a single DynamoDB call. Voting Every vote follows exactly the same lifecycle:
Authenticate ↓Load Poll ↓Validate Status (open? not expired?) ↓Reserve Vote (atomic ifNotExists write) ↓Increment Option Count ↓Publish Snapshot (live to all subscribers)The atomic write is the key move - if two users hit vote at the same moment, only one lands. The other gets a ConditionalCheckFailed and the app returns "you've already voted" immediately, no race condition possible.
Preventing Duplicate Votes
The naive approach looks like this:
Does vote exist?↓No↓Insert voteFine in theory. Broken under load. Two requests arriving at the same millisecond both read "no vote exists" and both write successfully. The user votes twice.
Instead, the app skips the check entirely and uses a conditional write:
await pollTable.put({ pollId, recordType: vote:${user.username}, optionId, votedAt: Date.now() },{ ifNotExists: true });ifNotExists tells DynamoDB: write this record only if nothing exists at this key. The database enforces it atomically. No matter how many requests arrive simultaneously, exactly one succeeds. Every other request gets a ConditionalCheckFailed — no extra code, no locks, no retry logic needed.
The race condition can't happen because there's no gap between the check and the write. They're the same operation.
Why Snapshots Matter
Realtime isn't about broadcasting deltas:
+1 vote on option AThat breaks reconnects. If a client drops and reconnects mid-session, it missed updates and now shows stale counts with no way to recover.
Instead, every update publishes the complete poll state:
QuestionOptions + current vote countsStatus (open / closed)Expiry timestampThe client doesn't patch - it replaces. Whatever it's showing gets swapped out for the latest snapshot in full. A reconnecting client just receives the next publish and immediately has the correct state, no catchup logic, no gap detection, no missed-event handling.
Retries are safe for the same reason. Receiving the same snapshot twice has no effect - the client renders identical data and nothing changes on screen.
Live Updates
Realtime channels are scoped per poll. Subscribing to Poll A puts you on Channel A. Poll B has its own channel entirely. Votes on one poll never touch the other.
Poll A → Channel A → Subscribers of APoll B → Channel B → Subscribers of BEvery successful vote triggers one publish - the complete current state of that poll. Not a counter increment. Not a diff. The full picture: question, every option, every vote count, status, expiry.
Every browser subscribed to that channel receives the same payload at the same time and renders the same result. There's no divergence possible because no client is computing its own running total - they're all just displaying whatever the server last said.
Late joiners, reconnects, and concurrent voters all converge on the same state automatically.
Automatic Poll Closing This was one of my favourite parts to build. A CronJob fires every minute and scans the table for polls that have run their course:
status === 'open' AND expiresAt <= nowEvery qualifying poll goes through the same sequence:
Mark status closed ↓Write updated record ↓Publish final snapshotAll connected browsers receive the closed state instantly - no polling, no page refresh needed.
The best part is that the operation is idempotent. If the cron fires twice in quick succession, or a poll was already manually closed by its creator, nothing breaks. A closed poll doesn't match the filter, so it gets skipped. Running the scheduler ten times produces exactly the same outcome as running it once.
That property - safe to repeat - is what makes scheduled jobs reliable in production. You never have to worry about double-execution corrupting your data.
Local Development
This felt almost magical.
npm run devThat's it. No AWS account. No LocalStack. No Docker. No environment variables to wrestle with.
Polls and votes automatically persisted inside .bb-data. Restart the server - everything was still there. Create a poll, cast some votes, kill the process, come back an hour later, and your data is waiting exactly where you left it.
The local mock behaves identically to the real DynamoDB table. Same API, same key structure, same conditional write semantics. Code written against the mock deploys to AWS without a single change.
The only thing that caught me off guard was momentum - I kept building features and forgot I was supposed to be demoing a polling app, not a bookmark manager. 😄
Challenges
- Unlearning REST
My instinct for every action was an endpoint:
POST /voteGET /pollsDELETE /polls/:idAWS Blocks thinks in functions, not routes. Once I stopped mapping everything to HTTP verbs and just wrote:
api.castVote(pollId, optionId)api.listPolls()api.deletePoll(pollId)everything got cleaner and the mental overhead dropped significantly. The transport just disappears.
- Thinking about concurrency
My first instinct for duplicate vote prevention was a frontend guard - disable the button after clicking. That's not a solution, that's a suggestion. Two tabs, two devices, or two fast fingers break it immediately.
The real fix had nothing to do with the frontend. It was a database problem, solved at the database level with a conditional write. Once that clicked, the frontend guard became a nice-to-have rather than load-bearing logic.
- Realtime consistency
Publishing +1 felt like the obvious move - small payload, surgical update. But it falls apart the moment a client misses a message, reconnects late, or receives two updates out of order. Suddenly the count is wrong and there's no way to recover without a full reload.
Publishing the complete snapshot costs a little more bandwidth and gains a lot of correctness. Any client, at any point in time, receiving any message ends up in the right state. That tradeoff was worth it immediately.
What I Learned
The biggest lesson wasn't about polling. It was about how to think about architecture.
I used to start with endpoints. What routes do I need? What does the request body look like? What does the response return? That mental model puts HTTP at the center and everything else gets shaped around it.
Building this app flipped that. The question became:
"Which Block owns this responsibility?"
Authentication isn't a set of routes - it's a Block. Realtime delivery isn't a WebSocket server to configure - it's a Block. Storage isn't a database schema to design from scratch - it's a Block. Scheduling isn't a cron daemon to manage -it's a Block.
Each infrastructure concern got a clear owner and a clean boundary. The business logic - create a poll, cast a vote, close when expired - had nowhere left to hide complexity. It was just the actual problem, with nothing else mixed in.
The application got dramatically simpler not because the problem got easier, but because infrastructure stopped leaking into business logic. That separation is something I'll carry into every project after this.
Hands-on Demo
- Signed in as demouser

- Created a poll: "Which AWS service do you use most?" with Lambda, DynamoDB, S3

- Voted for Lambda - results switched instantly from vote buttons to live bar charts
- Lambda shows 1 (100%), others at 0 (0%)
- Countdown timer ticking (3m 19s remaining)

- "Results update live as votes come in" — WebSocket subscription is active
- Creator controls visible: Close Poll and Delete

Final Thoughts
A polling application looks deceptively simple. But build one properly and you run into nearly every challenge that shows up in real distributed systems - authentication, concurrency, realtime synchronization, background processing, and durable state. All in one small project.
AWS Blocks let me explore every one of those challenges without spending my time on infrastructure plumbing. No REST API to design. No WebSocket server to configure. No scheduler to wire up and keep running. Just the polling problem itself, from the first line to the last.
That's what stood out most. Every decision I made was about how polls should behave - not about how services should connect. The infrastructure was there, doing its job, completely out of the way.
If you're looking for a project that goes beyond basic CRUD while still being approachable, a live polling app is a great place to start. You'll touch auth, realtime, atomicity, and scheduled jobs - and with AWS Blocks, none of them will slow you down.
Series: Series: AWS User Group Madurai - Skill Sprint Challenge - DevTool Month - AWS Blocks (3 articles)
- 2Building Live Polls Without REST APIs Using AWS Blocks This article
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article