Real-Time Polling App with WebSockets
Build a live polling app like the ones used in classes and meetings: a host creates a poll with a question and options and shares a room code; participants join from their phones and vote, and everyone sees the results update instantly as votes come in. It's built with React, Express and Socket.IO, with the message types shared between client and server in TypeScript, so both sides always agree on what each event contains. Each participant can vote only once, even after refreshing the page or reconnecting, and the host controls when voting opens and closes. You'll learn Socket.IO rooms and events, typed events shared by client and server, keeping state consistent in real time, reconnection, and testing real-time flows.
- Estimate
- ~12h
- Steps
- 6
- Completed by
- 0
- Proposed by
- codeseed.app
Socket.IO · React · Express
Project roadmap
- 01
Define shared event types
~1.5hSet up a monorepo (for example with npm workspaces) with shared, server and client packages. In shared, define the Poll type (room code, question, options with vote counts and status draft, open or closed) and the Socket.IO event interfaces (ClientToServerEvents and ServerToClientEvents), such as createPoll, joinRoom, vote, openPoll, closePoll and pollUpdated. Done when: both server and client compile using the shared types.
- 02
Build the server
~2.5hBuild an Express server with Socket.IO typed with the shared interfaces. Hosts create polls (getting a random 6-character room code and a secret host token), participants join rooms, and votes are accepted only while the poll is open and for valid options. Broadcast updated results to the room after each vote. Keep polls in memory with an expiry. Done when: a script with socket.io-client can create a poll, join and vote.
- 03
Build the host view
~2hBuild a React page for hosts to create a poll (a question and 2 to 8 options, validated), see the room code and a join link, open and close voting, and watch results as a live bar chart with vote counts and percentages. Only the holder of the host token can control the poll. Done when: a host can create, open and close a poll and see live results.
- 04
Build the participant view
~2hBuild a mobile-friendly page where participants enter the room code (or open the link), see the question and options, vote with one tap, and then see live results. Show clearly when the poll isn't open yet or has closed. Done when: several phones or browser tabs can join and vote, and everyone sees results update instantly.
- 05
Prevent duplicate votes and handle reconnects
~2hGive each participant a random id stored in localStorage and sent when joining, and record one vote per participant id per poll on the server (a second vote is rejected, or replaces the first if you allow changing votes). On reconnect, rejoin the room automatically and receive the current state. Rate limit events per connection. Done when: refreshing the page doesn't allow a second vote, and reconnecting shows the latest results.
- 06
Write an end-to-end test
~2hWrite an automated test (with Vitest and socket.io-client) that starts the server, creates a poll as a host, connects 20 participants, opens the poll, casts votes including duplicates and votes for invalid options, closes it, and checks every client received the same final results and that votes after closing were rejected. Done when: the test passes reliably.
Resources
Ready to build this?
Get a GitHub repo and start building. Your AI reviewer checks each step as you go.
Tech stack