appwrite / appwrite/sdk-for-android

Realtime messages can come out of order (and in fact are processed in parallel)

Open
#103 0 comments 0 reactions 1 assignee Claimed by @ChiragAgg5k View on GitHub
Dominant language
Kotlin
Stars
154
Forks
30
Avg merge
5h 41m
Merged PRs (30d)
3

Description

### 👟 Reproduction steps

1. In Kotlin, create a `Realtime` subscription.
2. Trigger multiple messages (for example, createOperations and create multiple items at the same time)
3. Observe they are not ordered, but are processed in parallel.

In my code, I used a `callbackFlow` to convert the callback to a flow, so I essentially processed them sequentially, but due to the callback, they don't necessarily enter the queue in order.

Note: this does not happen all the time, so repeated attempts to reproduce may be required before it occurs. Best way is to ensure multiple updates come at the same time and are ordered in a fashion that's easy to notice (such as an increasing text field or something).

Note in Realtime.kt, `AppwriteWebSocketListener` `onMessage`, when it receives a message, it performs launch(IO) to handle the response event. This means each message gets scheduled to run in parallel, which means the messages are not serialized per subscriber.

### 👍 Expected behavior

I expect to get my callback called in the order of messages I get from the server, and not have parallel callbacks, as I might reasonably expect updates to be processed in order.

Alternatively and perhaps better, I would like to have the API expose the server messages as a `Flow` instead of a callback model.

### 👎 Actual Behavior

Actual behavior is the messages can come in arbitrary order. Often they're in order but not always. Here's some example logging output:
2026-01-04 20:44:48.717 22217-22295 D Got an item id=A
2026-01-04 20:44:48.722 22217-29657 D Got an item id=C
2026-01-04 20:44:48.725 22217-22291 D Got an item id=B

Note the process ID is the same 22217 but the thread id is different for each message.

For reference, in another (web) client, I got:

A $createdAt=2026-01-05T04:44:50.074+00:00 timestamp=2026-01-05T04:44:50.095+00:00
B $createdAt=2026-01-05T04:44:50.078+00:00 timestamp=2026-01-05T04:44:50.100+00:00
C $createdAt=2026-01-05T04:44:50.078+00:00 timestamp=2026-01-05T04:44:50.105+00:00

### 🎲 Appwrite version

Version 1.8.x

### 💻 Operating system

Linux

### 🧱 Your Environment

This is using the Android Kotlin library io.appwrite:sdk-for-android:11.4.0

### 👀 Have you spent some time to check if this issue has been raised before?

- [x] I checked and didn't find similar issue

### 🏢 Have you read the Code of Conduct?

- [x] I have read the [Code of Conduct](https://github.com/appwrite/.github/blob/main/CODE_OF_CONDUCT.md)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.