
Some pages get refreshed like they owe people money. Election counts at two in the morning. A league table on the last day of the season.
Draw results for everyone who spent the evening betting on the lotto and is now glaring at six little numbers, waiting.
Anyone who’s built one probably still remembers watching the CPU graph shoot straight up about a minute after the first result went live.
On paper, getting live data in front of people is a solved problem. In practice it’s fiddly. You want it quick, you want it correct, and you want it to survive fifty thousand people hammering refresh at once, and those three don’t always get along.
Below is roughly the order I’d think about it in: how the data gets from server to browser, how to stop it going wrong, then a bit of front-end polish.
Picking Between Polling, WebSockets and SSE
Most of us start with polling, and honestly that’s fine. The browser asks the server “anything new?” every few seconds and the server answers. It’s dead simple, it works through every proxy on earth, and because each request is plain HTTP you can stick a CDN in front of it.
The downside is waste. Most of those requests come back with nothing, and your updates can only ever be as fresh as the polling interval.
Also, if every client polls on the exact same five-second tick, congrats, your origin now gets a little spike every five seconds. Add a random offset to each client’s timer and it smooths right out.
WebSockets are the opposite approach. One connection, kept open, and either side can fire a message down it whenever. For chat, multiplayer stuff or Google Docs style editors they’re great, because the user is constantly sending things back.
On a results page though, the user mostly just… watches. Kind of overkill, if I’m honest. Each open socket lives on some server, so once you scale past one box you need sticky sessions or a pub/sub layer, and reconnecting after a drop is your problem to write.
SSE doesn’t get talked about much, and I’ve never really understood why, since a results page is basically its ideal use case.
Data only flows one direction, server down to browser, and it rides on regular old HTTP. One annoying catch.
Over HTTP/1.1 a browser only lets you hold six connections to one domain, so a user with your site open in a bunch of tabs runs out pretty quick. Serve it over HTTP/2 and that problem mostly goes away.
Rough rule, then. If users only read, try SSE first. If they also send data back constantly, use WebSockets. If you just need something working by Friday, poll, and poll politely.
Keeping Data Accurate When Thousands Are Watching
Speed is nice. Being wrong in front of a huge audience is not. The first rule is boring but it saves you: one source of truth.
Results get written to a single place, and every update that goes out to browsers comes from there, usually through a pub/sub channel like Redis that fans messages out to however many app servers you’re running.
Next, number your updates. Give every change a sequence number or version, and have the client ignore anything older than what it already has.
Networks reorder things more often than you’d think, and without this you’ll get a score flicking backwards for a second, which people absolutely do notice and screenshot.
On reconnect, don’t bother replaying every message the client missed. Just hand it a fresh snapshot and carry on from there.
Which means the snapshot endpoint gets hammered. Stick a cache in front of it, even just a second or two at the CDN.
Micro-caching, people call it. Sounds too small to matter, but it’s the gap between your origin seeing a trickle of requests and seeing thousands of folks all grabbing the same JSON.
Also stick stale-while-revalidate in the headers. Someone who shows up mid-refresh gets the slightly older copy right away and nobody’s left hanging.
Two more, both usually learned painfully. Early numbers aren’t final numbers, so send a status along with them, provisional or confirmed, and actually show it on the page, otherwise someone will screenshot an early count and post it as the result.
The other one: restart your server and every single client reconnects at the same moment, which is basically a DDoS you did to yourself. Back off exponentially, add some random jitter, and they’ll trickle back in instead.
A Few Front-End Bits That Make It Feel Fast
Once the data is arriving reliably, a lot of the “feels fast” part comes down to the front end. First, only touch what changed.
Don’t re-render the whole table because one cell moved. On a cheap Android phone you’ll actually see it stutter, and the page has a habit of jumping. Just patch that one value.
It helps to show people where the change happened, too. A quick yellow flash on the row that just changed works nicely, as long as it fades out fast. A second is plenty.
Don’t forget screen readers either. I’d drop the results into an aria-live=”polite” region, which waits for a gap before reading anything out. Nobody wants a voice cutting in each time some score goes up by one.
Watch your layout as well. Few things are more irritating than reading a row and having it shoved down the page because something above got longer, and Google counts that against you under Cumulative Layout Shift anyway. Give things a fixed height from the start.
Tell people how old the data is. A small “updated 4 seconds ago” line, plus a connection dot that goes amber when the stream drops, will save you a surprising number of “is this broken?” emails. Users relax a lot once they can tell whether the page is live or not.
Lastly, think about battery and data. The Page Visibility API tells you when a tab is hidden, so pause the stream then and pull a fresh snapshot when the person comes back. Nobody needs updates pouring into a tab buried behind twenty others.
None of this is rocket science, really. The hard part is you need most of it working together, and you need it before the big night, not halfway through.
Run a load test or two the week before. Then on the night you can sit back with a coffee and watch the graph instead of firefighting.