Live chat, collaborative editing, instant notifications, dashboards that update without refreshing: users increasingly expect software to feel alive. Building a realtime web app with WebSockets is the most common way to deliver that, but it changes how your system behaves in ways a typical request-response app never has to consider. Here is what to know before you start.
Do you actually need realtime?
Realtime adds infrastructure and complexity, so be specific about the requirement. Strong candidates include:
- Messaging, comments and collaboration where people interact at the same time.
- Live status, such as order tracking, job progress or device monitoring.
- Presence, showing who is online or viewing the same record.
- Streaming results, for example AI responses or audio delivered as they are generated.
If data only needs to be reasonably fresh, such as a report updated every few minutes, simple periodic refreshes may be all you need.
Choosing a transport
| Technique | How it works | Best for | Limitations |
|---|---|---|---|
| Polling | Client asks the server for updates on a timer | Infrequent updates, simple setups | Wasted requests and delayed updates |
| Long polling | Server holds the request open until there is news | Fallback where persistent connections are blocked | More complex than it looks; overhead per message |
| Server-Sent Events | One-way stream from server to browser over HTTP | Notifications, live feeds, streaming text | Server to client only |
| WebSockets | Persistent two-way connection | Chat, collaboration, games, audio and interactive apps | Requires connection management and suitable hosting |
| Managed realtime services | Hosted pub/sub and presence over WebSockets | Teams that want realtime without running the infrastructure | Ongoing service cost and some vendor coupling |
Managed options include Supabase Realtime, Pusher and Ably, among others. If you already use Supabase for your database, its realtime features can broadcast database changes to subscribed clients; see our comparison of Supabase vs Firebase for startups.
Designing WebSockets for a reliable realtime web app
Authenticate the connection, then authorize every channel
Verify the user when the socket opens, typically with a short-lived token, and check permissions again whenever they subscribe to a channel or room. A user who can connect should not automatically be able to listen to every organization’s events. Plan for tokens expiring during long-lived connections.
Expect disconnects
Mobile networks drop, laptops sleep and servers restart during deployments. Clients must reconnect automatically with backoff, and the interface should show connection status honestly. Critically, decide how clients catch up on messages missed while disconnected. A common pattern is to give events sequence numbers or timestamps and fetch anything newer through a normal API call after reconnecting.
Keep the database as the source of truth
This also keeps the rest of your system simple. Reports, exports, search and background jobs keep reading from the database as usual, and they do not need to know that a realtime layer exists at all.
Treat realtime messages as notifications that something changed, not as the only record of it. Write to the database first, then broadcast. That way a missed message is an inconvenience, not lost data.
Scaling beyond a single server
Before scaling, estimate your peak number of concurrent connections and how many messages each one sends and receives. Those two numbers drive most infrastructure decisions.
With one server, every connected client is in the same place. With several, a message received by server A must reach clients connected to server B. The usual solution is a pub/sub layer, such as Redis or a message broker, that every server subscribes to. Other scaling considerations:
- Hosting model. Typical serverless functions are short-lived and are not designed to hold persistent connections. Use a long-running service or a managed realtime provider for the socket layer.
- Load balancer support for WebSocket upgrades and appropriate idle timeouts.
- Heartbeats to detect dead connections and free resources.
- Message size and rate limits so one misbehaving client cannot overload the system.
- Fan-out costs, since a single event broadcast to thousands of subscribers multiplies quickly.
Realtime beyond text: audio and AI
WebSockets also suit streaming binary data. In our Oryn project, a realtime voice-first AI companion, audio flows between the browser and the server over WebSockets, the Web Audio API handles capture and playback in the browser, and a language model generates responses, with Supabase providing authentication and realtime features. Low-latency experiences like this depend on careful buffering, interruption handling and graceful recovery when the connection wobbles. If you are exploring AI features that act on behalf of users, our explainer on AI agents for business is a useful starting point.
Testing realtime features
Realtime bugs tend to appear only under conditions that are rare on a developer machine: slow networks, many simultaneous users and deployments mid-session. Make those conditions part of your routine testing:
- Simulate flaky networks and confirm reconnection and catch-up work.
- Test with several users in the same room, including permission edge cases.
- Load test with realistic numbers of concurrent connections and message rates.
- Deploy during active sessions in staging to see how clients recover.
Ship realtime features with SiteWright Technologies
SiteWright Technologies builds realtime products, from live dashboards and collaboration tools to voice-driven AI apps, with the authentication, reconnection logic and scaling they need to stay dependable. Explore our full-stack development services or talk to us about your project.


