Realtime Messaging API Explained: How It Works in 2026
Learn what a realtime messaging API is, how WebSockets and polling compare, how delivery guarantees work, and when your app needs one.
You know the moment. A football match is deep in stoppage time, the app in your hand buzzes, and the score flips to 2-1 before the television replay has even finished loading. Nobody pulled down to refresh. Nobody reloaded a page.
The same thing happens when a colleague's cursor drifts across a shared document, when a courier's dot slides along a map, and when a chat message lands with that small grey tick underneath it. Different products, one mechanism behind all of them.
That mechanism deserves a proper look, because most of the confusion around it isn't about speed. It's about what happens when the connection breaks, and what the system promised you before it did.
What a Realtime Messaging API Actually Does
A realtime messaging API is a service that pushes events and messages to connected apps the moment they happen, and accepts messages from those same apps over one open channel. The scoreboard, the shared cursor and the delivery dot all lean on it.
The cleanest way to hold the difference in your head is this. A conventional request-response API is a newspaper: you walk to the stand, buy a copy, and read whatever was printed before you arrived. If the score changes, you walk back for another copy. A realtime messaging API is a radio broadcast: the transmitter sends continuously, and the receiver plays whatever is airing now. You don't fetch the news. It reaches you.

Every realtime system reduces to three parts. The publisher is whatever produces the event: a match server, a chat backend, a courier's phone. The channel, often called a room or a topic, is a named grouping so that only interested clients receive the event. The subscribers are the connected clients listening on that channel.
Say a scoring service publishes a goal to a channel called match:4417. Every phone subscribed to that channel receives the payload within a fraction of a second, and a phone that joins two minutes later subscribes and starts receiving the next event. The pattern is identical for chat, presence (who is online), collaborative editing and live dashboards, so one vocabulary covers all of them.
This isn't a niche corner of the market either. The global real-time messaging-as-a-service market was valued at USD 6.4 billion in 2024, according to Growth Market Reports, which tells you how many products now depend on the pattern.
Four questions decide whether your implementation works. They're worth holding in mind from here: how the transport behaves under load, what delivery guarantee you promised, how to read performance numbers without fooling yourself, and which use cases justify the complexity at all. The transport is only one layer of the job; the rest is ordinary backend application development with a timing constraint attached.
Polling, Long Polling and WebSockets Compared
A chat app that checks for new messages every few seconds can make a fresh reply feel late. The basic request-and-response pattern explains why: the browser asks, the server answers, and the exchange ends. Short polling repeats that exchange on a timer. Long polling keeps each request open until an event arrives or a timeout occurs. WebSockets keep a two-way connection open so either side can send messages without starting a new request each time.
Short polling is easy to set up, but many requests return no new data, and users may wait until the next check. Long polling reduces that wait by letting the server respond as soon as it has an update. The client then opens another request, so a large number of waiting clients can mean many open requests to manage.
WebSocket was standardized as IETF RFC 6455 in 2011. A connection begins with an HTTP request that the server agrees to upgrade; after that, both sides can exchange data over the same open connection.
The four transports side by side
| Method | Direction | How updates arrive | Best fit | Main drawback |
|---|---|---|---|---|
| Short polling | Client to server | Client asks on a timer | Data that changes rarely | Repeated requests and delay |
| Long polling | Client to server | Server holds the request until data exists | Notifications at modest traffic | Open requests and repeated reconnects |
| Server-Sent Events | Server to client | Server pushes over one HTTP stream | Feeds, live scores, dashboards | Server-to-client only |
| WebSocket | Both directions | Persistent full-duplex channel | Chat, presence, collaboration | Connection management at scale |
Choose the simplest transport that meets the app's latency and direction needs. If the server only needs to push score updates to a browser, Server-Sent Events may be enough. If clients and servers both send frequent messages, WebSockets fit better.
A persistent connection improves how quickly a message can arrive. It does not, by itself, guarantee that the message arrived, was processed, or can be recovered after a disconnect. Those guarantees are a separate part of the design.
A measurement study of the Tranco Top 1 Million found 71,637 WebSocket connections across 55,805 websites, according to the researchers' WebSocket measurement paper. The study also found HTTP polling more common than WebSockets, with WebSocket adoption largely flat over the prior two to three years. WebSockets are an established option, but they are not the right choice for every update.
How a Message Travels Through a Realtime Channel
A chat message can cross several boundaries before it reaches another person: the sender's connection, an authorization check, a room or topic, and the connections of everyone listening. Each step affects whether the message arrives, not just how quickly.

- The client opens a connection. A WebSocket begins as an HTTP request that asks to upgrade the connection. After the server accepts, both sides exchange WebSocket frames over the persistent connection.
- The server authenticates the client. The client can provide a short-lived token during the handshake or in its first message. Avoid putting a long-lived secret in a URL, where it may appear in logs. If authentication fails, the server closes the connection.
- The client subscribes to a channel. It sends a request naming the room or topic it wants to receive messages from. The server checks whether the user may join, then associates that connection with the channel.
- A publisher sends an event. Another client or service publishes a message to the channel. The publisher does not need to address each listener individually.
- The server fans out the event. It sends a copy to each subscribed connection. A busy room can therefore create substantial outbound traffic even when the number of connected clients seems manageable.
- The application can acknowledge receipt. An acknowledgement containing a message ID can tell the server that the client received a particular message. A live connection alone does not confirm that.
- The connection checks for life. WebSocket Ping and Pong control frames let either side check whether its peer is still responding. A matching Pong can echo the Ping's payload, giving the sender a way to measure round-trip time and detect a silent connection.
Set heartbeat intervals shorter than the idle timeouts of proxies, load balancers, and NAT gateways on the route. Otherwise, a middlebox may drop a connection while the client still treats it as healthy.
If the connection closes, the client can reconnect with exponential backoff and jitter, resubscribe, and request messages after its last known ID. That replay requires a place to keep messages. For a broader look at storage options, compare free database apps.
Delivery Guarantees Every Realtime API Must Define
A message that arrives late is an inconvenience. A message that vanishes is a bug report you can't reproduce. Yet plenty of systems are built as though latency were the only variable that matters, and the moment a phone sleeps or a deploy restarts a server, the missing piece shows up in production.
"Realtime" doesn't necessarily mean "reliable." WebSocket provides transport, not persistence, retries, deduplication, or confirmation that a user processed anything. A library like Socket.IO gives you ordering but defaults to at-most-once delivery, so messages can disappear without automatic retry, as this realtime communication design guide spells out. A lower-latency live channel can be less trustworthy than a slower workflow backed by durable storage.
The three guarantees and their price
| Guarantee | What it promises | Typical mechanism | Trade-off |
|---|---|---|---|
| At-most-once | Delivered zero or one time | Fire and forget | Messages can disappear during drops or deploys |
| At-least-once | Delivered one or more times | Acknowledgements and retries | Receivers must handle duplicates |
| Effectively-once | Processed once in effect | At-least-once delivery plus idempotent handlers and durable IDs | More storage and code to maintain |
Concrete examples make the choice obvious. A typing indicator can be dropped without anyone noticing or caring. A payment confirmation cannot, and neither can a message saying a prescription is ready for collection.
The rule that saves you later: decide the guarantee per event type, in writing, before you write the handler. One app routinely needs all three.
Effectively-once is the one people ask about, and it's worth being precise. You can't get it from the protocol. You build it from at-least-once delivery plus durable message IDs, client acknowledgements, replay from a message store after reconnect, handlers that ignore a duplicate ID they've already processed, and bounded offline queues so a phone that sleeps for three days doesn't wake up to an unbounded backlog.
Reconnect behaviour deserves its own paragraph, because it's the failure mode that takes systems down. A million mostly idle connections can be entirely feasible to hold. The problem is the moment they all come back at once after a deployment, hammering authentication, load balancers and subscription services simultaneously. Exponential backoff with jitter on the client and rolling connection drains on the server are operational requirements, not refinements you add later.
Ordering is the same kind of decision. If two events for the same object must be applied in sequence, that ordering has to be enforced somewhere durable, because a reconnect hands you a brand-new connection with no memory of what came before.
Performance Numbers and What They Really Mean
A message that arrives quickly can still be missing, duplicated, or delayed for some users. Performance numbers matter, but they describe only part of the service: a fast transport does not guarantee trustworthy delivery.
Transport comparisons are useful as general guidance. WebSockets support ongoing two-way communication without repeatedly opening a request, while long polling waits for an update and then starts another request. Under a particular workload, one may show lower latency or use fewer resources than the other. The result depends on the implementation and test conditions, so no single comparison predicts how your system will perform.
Why averages mislead and what to measure instead
An average can hide the users having the worst experience. Tail latency, measured with percentiles such as p95 and p99, shows how long slower deliveries take.
Test each intended workload separately: one-to-one delivery, broadcast fan-out to a large room, reconnect storms, and slow consumers that cannot keep up. Record median latency, p95 and p99, messages per second, dropped messages, connection churn, CPU, memory, and broker lag. Track recovery after failures alongside delivery speed.
Raw connection counts are a weak capacity measure. A million idle connections use resources differently from a thousand busy fan-out rooms pushing frequent updates. Measure cost and load per active connection, delivered event, fan-out recipient, retained message, region, and reconnect. Include publish-to-deliver latency by geography on the same dashboard.
Regional placement changes more than latency. Locating services closer to users can shorten network paths, while distributing message handling across regions raises questions about consistency, routing, replay, and data residency. Decide where messages may be stored, then measure round-trip time from each target region against the latency budget for each workload. A low-latency result is useful only if the system can also deliver the right messages to the right recipients.
Use Cases and Choosing a Delivery Model
A live delivery map has two kinds of updates. A courier's position becomes stale when a newer position arrives, while a delivery confirmation must still be available after the customer closes the app. The right delivery model depends on what each event means, not just how quickly it travels.
| Use case | Update speed needed | Loss tolerance | Subscribers per event |
|---|---|---|---|
| Group chat | Ordered within a room, seconds | Typing indicators can be dropped; messages cannot | Members of one room |
| Presence | Brief staleness is acceptable | A lost update is fine | Contacts or room members |
| Live sports scores and stock prices | Low latency | Intermediate ticks can be lost; the latest value matters | Very high fan-out |
| Collaborative editing | Low latency, two-way | Every change must be ordered | Collaborators on one document |
| Notifications and live dashboards | Seconds | Dashboards tolerate some loss; alerts do not | Mostly one-way, with a fallback |
| Live location tracking | Tight latency budget | Some points can be lost | Followers of one vehicle |
| Delivery tracker | Map updates arrive live | Confirmations must remain available | Customer and courier |
Five questions that pick your delivery model
Work through these questions in order. Start with the consequence of losing an event.
- Can the app lose this event without harm? If the next update corrects the display, at-most-once delivery may be enough. If a missed event changes an order or erases a user action, store it durably before optimizing for speed.
- What delay will users notice? A cursor in a shared document can feel broken when it lags, while a dashboard counter refreshed every few seconds may still feel current. Set a latency target based on the feature's job.
- Does traffic flow one way or both ways? A score feed or notification stream mainly sends updates outward. Chat and editing need clients and servers to exchange messages, so a full-duplex channel is a better fit.
- How many subscribers receive each event? Sending one update to many followers creates a different fan-out workload from sending it to two collaborators, even if the payload is identical.
- How do clients resume after a disconnect or deployment? Specify whether they resume from a last-seen message ID, replay a stored window, or fetch the current state again. If clients only reload the page, they may miss events that were never stored.
Then match the guarantee to the consequence. Events that tolerate loss can use at-most-once delivery without storage. Events that must not disappear need durable IDs, retries, and idempotent handlers so a repeated message does not create a duplicate order or notification. One application can use both approaches for different event types.
Choose a delivery guarantee based on what happens when a message is lost. Speed alone cannot make delivery trustworthy.
One product, two guarantees
A delivery tracker makes the distinction clear. The courier's location changes every few seconds, and the map should show the newest point. Older points can be discarded because a later update replaces them.
The delivery confirmation has a different job. It must be stored and available when the customer returns to the app. That means two event types on one screen can require different guarantees: one favors fresh state, the other durable history.
If you want to provision the supporting services together, ExtraOrbital can provision realtime rooms, Postgres, Redis, and auth for a project with one command, then write credentials where the application expects them. Its API keys are scoped to a team and optionally a project; see the guide to using an API key for the details.
Record the guarantee for each event type in the project design, then test the workload that matters most against the performance targets. Together, those decisions define what the feature promises users.