SwiftQuiz is a live quiz platform in the style of Kahoot and Slido. The host creates a room, players join with a code or a QR, questions advance on the host’s screen, everyone sees the results at the same time. Standard stuff.
The interesting part is what happens when you try to build it on Vercel.
The Core Problem
Kahoot-style platforms are fundamentally real-time. Players need to see the question appear. The host needs to see answers arriving. Everyone needs to see the leaderboard update. That means persistent connections, and persistent connections mean WebSockets.
Vercel’s serverless functions cannot hold a persistent WebSocket connection. Each request comes in, gets handled, and the function freezes or dies. There is no “stay open and push updates to the client” mode.
The answer here is Ably, a managed pub/sub service. Rather than the server pushing updates to clients, the server publishes events to an Ably channel and every connected browser subscribes to it directly. Vercel stays stateless and dumb. Ably handles the connections. The browser talks to both.
Each quiz room is exactly one Ably channel. The host subscribes to it. Players subscribe to it. When a question starts, the server publishes a state change event and everyone’s browser receives it simultaneously. No polling. No long-lived server connections. No problem. Largely.
The State Machine
The room moves through a fixed sequence of states: LOBBY, then QUESTION_PREVIEW, then VOTING_ACTIVE, then VOTING_CLOSED, then LEADERBOARD, then back around or to QUIZ_OVER. Every transition is driven by the host calling a single API endpoint. Players cannot advance state directly — they can only submit answers while the room is in VOTING_ACTIVE.
This matters more than it sounds. The temptation with a real-time platform is to let clients publish events onto the shared channel freely. The problem is that clients lie. Or, more charitably, they misbehave. Enforcing state transitions server-side, with the backend as the single source of truth, means a player can’t submit an answer after voting has closed, can’t trigger the leaderboard early, and can’t advance to the next question by publishing a rogue event. The host always advances. It’s in the name.
Room state lives in Upstash Redis rather than in memory, because “in memory” on a serverless platform means “in this particular function instance’s memory, which will not be the same instance that handles the next request.” Redis is the shared state store that all instances can read from and write to consistently.
Why Players Submit Answers Over HTTP
Here is the part worth explaining.
An obvious implementation would have players publish their answers directly onto the Ably channel. It’s already there, they’re already subscribed to it. Why not?
Because if a hundred players all hit BIGLY at the same millisecond, a hundred events arrive on the channel simultaneously and your answer-aggregation logic has to handle concurrent writes to shared state without corrupting it. That is a tractable problem, but it requires careful design. More importantly, it means your Ably channel is now carrying a hundred publishes per question per room, and Ably charges for publishes.
Instead, players submit answers over plain HTTP to a Next.js API route. That route records the answer using atomic Redis operations, so concurrent submissions from different players never race or overwrite each other. The aggregate tally is then broadcast back to the host’s screen via a separate Ably publish, throttled to at most one per 200 milliseconds per room.
The throttle is implemented as a Redis lock rather than an in-process timer, because an in-process timer only exists in one function instance and Vercel’s routing will happily send the next request to a completely different one. Redis is the only place where state survives the hop between instances.
The Things That Went Wrong on Deploy
The git log from the first evening tells a story.
Initial commit at 22:21. Working build by 22:53. Then: fix Vercel build failure because of Ably and Redis clients being initialised at module load time, which Vercel doesn’t like. Then: make every API route always respond with JSON even on unhandled errors, because the client was receiving HTML error pages and trying to parse them as JSON. Then: accept Vercel’s native Upstash integration’s variable names, which are different from the names Upstash itself uses.
None of these are interesting problems. They are the specific tax you pay for deploying to a platform you haven’t deployed to before. The fixes took about an hour total. The commits are there in the history if posterity cares.
The Auth
There are two auth systems and neither of them uses a library.
The first issues signed bearer tokens using HMAC via Node’s built-in crypto module. Players get a token scoped to their player identity. The host gets one scoped to their host identity. The token gates answer submission and state advancement, so a player can’t submit as someone else and can’t advance the quiz.
The second is Google sign-in, for saving quizzes. By default, saved quizzes are tied to an anonymous identity stored in localStorage, which works fine until you switch browsers. Signing in with Google replaces the anonymous identity with one derived from the Google account, and any quizzes saved before sign-in are transferred across automatically.
The OAuth flow is hand-rolled using the same crypto module. No next-auth, no passport, no library. This was a choice made partly for consistency and partly for the experience of understanding what is actually happening at each step of the Authorization Code flow. The session is a signed, httpOnly cookie. It is fine.
The Stack
Next.js 15. Ably for pub/sub. Upstash Redis over HTTP. Three.js for some visual effects on the results screen. Framer Motion. canvas-confetti, because canvas-confetti is now a fixture in every project. QR code generation via qrcode.react for the join screen. Tailwind 3.
RESULT
It’s live at swiftquiz.baudypositive.com. The real-time works. The state machine holds. The throttled broadcast means answer volume on the host’s screen doesn’t spike into illegibility when multiple players answer at once.
Building it clarified something about serverless platforms that is easy to theorise about but useful to experience: statefulness is not gone, it has just moved. Everything that used to live in process memory now lives in Redis. Everything that used to be a persistent connection now goes through a managed service. The constraints are real but they have known solutions. You just have to find them in roughly the right order.
Which is more or less what the git log documents.