Get a free consultation
node.js

Building Real-Time Web Apps with WebSockets

By Sigmato Editorial TeamUpdated 9 Nov 20266 min read

Live data screens showing the result of real-time web app development

Live chat, delivery tracking, trading dashboards, multiplayer whiteboards and instant notifications all share one requirement: the server must push updates to users the moment something changes. Real-time web app development makes this possible, most often using WebSockets, a protocol that keeps a two-way connection open between browser and server. This guide explains how WebSockets work, when you need them and when you do not, and how to design a system that stays fast and reliable as you grow.

What Makes a Web App “Real-Time”?

A real-time web app delivers updates to users within a fraction of a second of the event, without the user refreshing the page. Traditional web apps follow a request-response pattern: the browser asks, the server answers, and the connection closes. That works for loading pages but not for events that originate on the server, such as a new message, a price change or a driver moving on a map.

Typical real-time use cases include:

  • Chat and customer support messaging.
  • Live location tracking for delivery, taxi and fleet management apps.
  • Collaborative editing, whiteboards and project boards.
  • Financial dashboards, auctions and sports scores.
  • Notifications, presence (“online now”) and typing indicators.
  • IoT monitoring and operational dashboards.

How WebSockets Work

WebSockets provide a persistent, full-duplex connection over a single TCP connection, so both client and server can send messages at any time. The connection begins as a normal HTTP request with an Upgrade header; if the server agrees, the protocol switches and the connection stays open. The protocol is defined in IETF RFC 6455, and every modern browser supports the WebSocket API.

Once connected, messages are sent as small frames with minimal overhead compared with repeated HTTP requests. Secure WebSockets (wss://) run over TLS, just like HTTPS, and should always be used in production.

WebSockets vs SSE vs Polling

WebSockets are the best choice for two-way, high-frequency communication, but simpler options are often enough for one-way updates.

TechniqueDirectionBest forTrade-offs
Short pollingClient asks every few secondsLow-frequency updates, simple dashboardsWasteful requests, delayed updates
Long pollingClient request held open until data arrivesFallback where WebSockets are blockedMore server work per update
Server-Sent Events (SSE)Server to client onlyNotifications, live feeds, AI text streamingOne-way; client sends via normal HTTP
WebSocketsBoth directionsChat, collaboration, games, live trackingStateful connections need careful scaling
WebRTCPeer to peerVoice, video, low-latency mediaComplex signaling; usually paired with WebSockets
Pick the simplest technique that meets your latency and direction needs.

A useful rule: if users mostly receive updates and rarely send them, consider SSE first. If they send and receive frequently, use WebSockets.

A Reference Architecture for Real-Time Web App Development

A production-ready real-time system usually separates connection handling from business logic and uses a message broker to fan out events. A common Node.js-based design looks like this:

  1. Client layer. A React, Vue or Angular web app (and often a mobile app) opens a secure WebSocket connection after login and subscribes to channels such as order:1234 or team:42.
  2. Real-time gateway. Node.js is a strong fit here because its event-driven, non-blocking model handles many concurrent idle connections efficiently. Libraries such as Socket.IO add rooms, automatic reconnection and fallbacks; the lighter ws library offers raw performance.
  3. Message broker. Redis Pub/Sub, Redis Streams, NATS or Kafka distribute events between gateway instances, so a message published on one server reaches users connected to another.
  4. Application services. Your REST or GraphQL API handles writes, validation and persistence, then publishes events to the broker.
  5. Data store. PostgreSQL, MongoDB or another database stores the durable state. Real-time messages are notifications of change; the database remains the source of truth.

Keeping writes in the regular API and using WebSockets mainly for pushing updates makes the system easier to test, secure and scale.

Team collaborating in a real-time web application on laptops

Scaling WebSocket Applications

Scaling real-time apps is mostly about managing many long-lived connections and delivering each message to the right ones. Key practices:

  • Horizontal scaling with a broker. Run several gateway instances behind a load balancer and use a pub/sub layer so messages reach users wherever they are connected.
  • Sticky sessions where needed. Some libraries require the load balancer to keep a client on the same instance during the connection handshake.
  • Keep connections lightweight. Store minimal state per connection and look up the rest from a cache.
  • Heartbeats and reconnection. Send periodic pings to detect dead connections, and reconnect clients with exponential backoff to avoid a “thundering herd” after a deployment.
  • Resynchronize on reconnect. When a client reconnects, fetch missed events or the latest state through the API so nothing is lost.
  • Managed services. For very spiky loads or small teams, managed options such as AWS API Gateway WebSocket APIs, Azure Web PubSub, Ably or Pusher remove much of the operational work at a per-message or per-connection cost.

Our guide to microservices vs monolith discusses when to split the real-time gateway into its own service; for most products it is one of the first components worth separating because its scaling profile differs from the rest of the app.

Security Essentials for Real-Time Apps

WebSocket connections bypass some protections that browsers apply to normal requests, so security needs explicit attention. The OWASP Top 10 risks apply here just as they do to any web app. In particular:

  • Always use wss:// (TLS).
  • Authenticate during the handshake with a short-lived token, and re-validate when tokens expire.
  • Check the Origin header to prevent cross-site WebSocket hijacking.
  • Authorize every subscription and every message: a user should only join channels they are allowed to see.
  • Validate and size-limit incoming messages, and rate-limit per connection.
  • Never trust client-sent identity fields; derive the user from the authenticated session.

Testing and Monitoring

Real-time features fail in ways that unit tests rarely catch, so plan load and resilience testing. Use tools such as k6 or Artillery to simulate thousands of concurrent connections, test what happens when a gateway instance restarts, and measure end-to-end latency from event to screen. In production, monitor open connections, message rates, delivery latency, reconnection spikes and memory per instance.

How Much Does a Real-Time Web App Cost?

The cost of real-time web app development depends mostly on how central live features are to the product. Costs depend on how central the real-time features are. As indicative ranges at blended offshore and onshore rates:

  • Adding live notifications or a simple chat to an existing app: about $8,000–$25,000.
  • A real-time dashboard or tracking web app (MVP): about $25,000–$60,000.
  • A collaborative platform with presence, editing conflict resolution and mobile clients: about $60,000–$150,000+.

Running costs scale with concurrent connections and message volume rather than page views. Your final quote depends on scope, expected traffic and whether you use managed real-time services.

Frequently Asked Questions

Is Node.js the best backend for WebSockets?

Node.js is one of the most popular choices because its event loop handles many concurrent connections efficiently and the JavaScript ecosystem has mature libraries. Go, Elixir (Phoenix) and Java are also strong options. The right choice depends on your team’s skills and the rest of your stack.

How many WebSocket connections can one server handle?

It varies with message volume, payload size and server resources. A well-tuned Node.js instance can often hold tens of thousands of mostly idle connections, but you should load test your own workload rather than rely on general figures.

Do WebSockets work on mobile apps?

Yes. iOS, Android, Flutter and React Native apps can all use WebSockets while in the foreground. For updates when the app is in the background, use push notifications, since mobile operating systems close idle connections to save battery.

Should I use Socket.IO or plain WebSockets?

Socket.IO speeds up development with rooms, acknowledgements and automatic reconnection, but it uses its own protocol, so clients need the Socket.IO library. Plain WebSockets are leaner and interoperable with any client, but you build those features yourself.

Build Your Real-Time Product with Sigmato

Sigmato builds real-time data communication systems, live dashboards and chat features on Node.js and modern frontends. You can engage us for a full project or hire dedicated Node.js developers to extend your team.

Sources and References

Sigmato Editorial Team

Written by

Sigmato Editorial Team

The Sigmato Editorial Team is made up of software engineers, UI/UX designers and AI specialists at Sigmato Solutions Pvt Ltd in Bengaluru, India and the UK. We write practical guides on web, mobile, cloud and AI development, drawing on the products we design and build for startups and enterprises worldwide.

Last updated 9 November 2026 · Talk to our team