Documentation

Message Ordering

This page explains ordered streams, message identity, and application versions.

Video: Message ordering. The YouTube player loads when you click play.

Celeris preserves the order of messages within a segment from the same origin server. This order also applies when messages travel across regions. The SDK calls your message listeners in the order that messages arrive.

For chat, order status, or game state, your application can process the messages of one sender in sequence. Celeris routes those messages to connected subscribers.

How ordering works

Celeris runs many servers, in several regions. As an example, take one server in the US and one server in the EU. Messages travel between the servers inside the Celeris network. A client connects through the nearest of 130 AWS Global Accelerator Points of Presence. To keep it simple, the diagram below shows each client connected directly to a server. Each server delivers messages to its subscribers in the order that the messages reach that server.

The origin server is the server that first accepts a published message. A channel connection stays on one server, so all messages from one connection have the same origin server. Two channel handles are two connections, and they can use different servers. The new connection after a reconnect can also use a different server.

As an example, your backend publishes these messages in sequence to one segment over the same connection:

Order received -> Preparing -> Ready for collection

Celeris preserves that sequence for the delivered messages, whether a subscriber is connected locally or in another region. You do not need to sort that stream on the client, while the publisher stays within its rate limit. If a publisher goes over its rate limit, the SDK recovers for it: it sends the recent publishes again, one time, and receivers remove the repeated copies. A recovered message can arrive after a newer message. The same ordering applies to retained messages that Celeris replays from that origin server.

ScopeOrdering behavior
One segment, one origin serverMessages retain their order, also across regions
One segment, several origin serversEach publisher's stream retains its order. Messages from different servers can interleave
Separate segmentsEach is a separate stream, also on one connection. One segment gives related messages a shared ordering scope

This applies to default as well as named segments. Ordering describes the sequence of delivered messages. Delivery is at least once, and the SDK removes repeated copies. In rare cases, a message can be missing without a disconnection, for example when a publisher stays over its rate limit or a subscriber falls too far behind. Versions keep important state correct in these cases. See Reconnection and Recovery for the recovery of messages that were sent during a disconnection.

The SDK invokes listeners synchronously. If a listener starts asynchronous work, that work can finish out of order. Apply simple interface changes directly in the listener. Serialize asynchronous work when the completion order matters.

Coordinate messages from multiple publishers

Independent publishers can publish to the same segment concurrently. When they connect to different servers, Celeris keeps the sequence of each publisher. Celeris does not hold messages back to build a single global order between the publishers. Each server delivers in the order that the messages reach it, without waiting for other servers. Thus, subscribers on different servers can receive a different mix:

Both subscribers receive A1 before A2, and B1 before B2. Subscribers on the same server receive the same order. Subscribers on different servers can receive a different mix.

For messages about shared business state, include a version from the backend that owns that state:

{
  "orderId": "order-42",
  "version": 18,
  "status": "ready"
}

Store the latest version together with the displayed order. Apply a newer complete snapshot. Ignore an older snapshot. If messages contain incremental changes and a version is absent, fetch the current state from your API before you continue. Your database or the service that owns the state assigns these versions. The versions are application data, not Celeris message metadata.

This keeps the responsibilities clear. Celeris delivers the live stream. Your application decides which message represents the current business state.

Identify messages consistently

Every delivered message includes a messageId. Supply your own ID at publish time to correlate a message with your application. If you do not supply one, the SDK generates a unique ID.

The JavaScript SDK uses these IDs to filter duplicates within its most recent 1,024 IDs per channel. Use one ID per logical message. Different messages must have different IDs.

A message ID identifies one message. An application version describes the position of that change in your business state. Treat them separately. IDs are not sequence numbers or replay cursors. For durable operations such as payments, also keep idempotency in your own backend.

Continue after a disconnection

After an established connection drops, the SDK automatically attempts to reconnect. It obtains fresh credentials and restores held subscriptions. Your listeners remain registered. When your server authorizes replay, Celeris can deliver retained messages to help the application catch up.

For a live dashboard, use the recovery event to refresh the current state from your API. Then continue with the live messages. This combines recent-message replay with an authoritative snapshot when the outage extends beyond retained history. Replay is bounded, so applications must prepare for possible gaps and duplicates.

See Reconnection and Recovery for the recovery lifecycle, and Replay for the replay policy. For the distinction between local publish completion and remote delivery, see Publishing messages.

Next: Read Reconnection and Recovery.

We use Google cookies for analytics and for advertising measurement, only if you allow them. Until you choose, Google sets no cookies. Refer to our Cookie Policy.