By Shubham Maurya, co-founder of BuildKodiq ·
We've built both halves of live dashboards: Go and FastAPI services that stream events over WebSockets to many clients at once, and Next.js and React dashboards. These are the problems worth planning for.
1. Agree the event contract before building screens
Most real-time bugs are contract bugs: a field that's sometimes missing, a number that's a string, events that arrive out of order, a message type nobody told the frontend about. Before writing UI we pin down every message the backend sends: its type, shape, units, expected rate and ordering guarantees, plus what a snapshot on connect looks like. We keep it as types shared by both sides and validate incoming messages at the edge, so a bad message is logged and dropped instead of breaking a screen.
2. Reconnect like the network will fail, because it will
Laptops sleep, phones switch networks, servers deploy. The client needs:
- Reconnect with exponential backoff and jitter, so a server restart doesn't get hit by every client at once
- Resubscribe to exactly what the user was watching
- Ask for a fresh snapshot after reconnecting, rather than trusting whatever was on screen
- A visible connection state. A dashboard that silently shows stale data as live is worse than one that says "reconnecting"
3. One store, not state scattered across components
Socket messages go into one normalised store keyed by id, outside React's render cycle. Components subscribe to the slice they need. That's what makes "this row changed" cheap, makes reconnect snapshots easy to apply, and stops two components from disagreeing about the same value.
4. Batch renders; don't re-render per message
At a few updates a second anything works. At hundreds, calling setState per message freezes the page. Buffer incoming messages and apply them once per animation frame. Virtualise long tables so only visible rows render, and throttle charts to what the eye can follow. The data is still exact; only the painting is batched.
5. Keep history and filters on REST
The socket is for what's happening now. History, search, filters, muting and exports go through normal REST endpoints with pagination. Mixing the two ("send me the last 10,000 events over the socket") is how connections get slow for everyone.
6. Put money and permissions on the server
If the dashboard is paid (for example with subscriptions), the server decides what a user may see, ideally when the WebSocket connection is opened. Verify webhooks and process them idempotently, so a retried event is never applied twice.
7. Test at peak, not at demo rates
Record a busy period from the real feed or simulate one, replay it at two or three times the expected rate, and watch frame times and memory for an hour. Most real-time problems (leaks, growing arrays, slow re-renders) only show up under sustained load.
We've published a small working version of these patterns as an open-source starter (FastAPI WebSocket server plus Next.js dashboard): github.com/Shubham996633/realtime-dashboard-starter.
Shubham Maurya leads our real-time frontend work. If you have a live dashboard to build or fix, see the related projects below or email hello@buildkodiq.com.
Drafted with AI assistance and reviewed by Shubham.