> For the complete documentation index, see [llms.txt](https://dnotifier.gitbook.io/product-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dnotifier.gitbook.io/product-docs/platform-overview/use-cases/realtime-communication.md). Agents can also search and read this documentation through its [MCP server](https://dnotifier.gitbook.io/product-docs/~gitbook/mcp).

# Realtime communication use cases

**Realtime communication** is DNotifier's **direct messaging layer**: connect clients over WebSocket, send payloads to explicit **receiver IDs**, and deliver from your backend via HTTP RPC. It is the foundation for live UX — distinct from **chat** (conversation history and UI) and **AI** (prompts and RAG).

{% hint style="warning" %}
DNotifier does **not** use broadcast topics or channel subscriptions. Every message is **directed** — from a `senderId` to one or more `receiverIds`. Design your IDs to represent users, devices, dashboard sessions, or service accounts.
{% endhint %}

***

## How realtime 1:1 messaging works

1. A client connects with the SDK using your app credentials and a **user ID**.
2. Your app (or server) sends a message addressed to a **receiver ID**.
3. If the receiver is connected, they receive the payload in `onMessage` immediately.
4. Your server can also send via **HTTP RPC** to reach online clients without a persistent server-side WebSocket.

This model fits **point-to-point** and **fan-out to known IDs** (`receiverIds: [...]`) — not anonymous broadcast rooms.

→ [Realtime communication overview](https://dnotifier.gitbook.io/product-docs/realtime-communication/overview.md) · [Send & receive text](https://dnotifier.gitbook.io/product-docs/realtime-communication/send-and-receive.md)

***

## Live dashboards

Operations teams, analytics products, and admin panels need metrics and status without polling.

### Pattern

| Component            | Role                                                               |
| -------------------- | ------------------------------------------------------------------ |
| **Dashboard client** | Connects as `userId: "dashboard-{sessionId}"` or per-admin user ID |
| **Backend / worker** | Computes metrics; sends updates to that user's ID                  |
| **Payload**          | JSON with chart data, KPIs, alert severity                         |

### Example flow

1. Admin opens dashboard → SDK connects with their user ID.
2. Metric service aggregates data every N seconds.
3. Service calls HTTP send (or a connected worker uses `send`) with `receiverId: adminUserId` and `{ type: "metrics", series: [...] }`.
4. Dashboard `onMessage` updates charts in place.

### Why directed messaging fits

Each admin sees **their** dashboard stream. You address updates to **specific IDs** — no shared channel where every subscriber receives every event.

→ [Multiple receivers](https://dnotifier.gitbook.io/product-docs/realtime-communication/multiple-receivers.md) (when one event should update several dashboard sessions)

***

## In-app notifications

Notify a user about order status, mentions, approvals, or system events while your app is open (or reconnect when they return).

### Pattern

| Component             | Role                                               |
| --------------------- | -------------------------------------------------- |
| **Mobile/web client** | Connected as the authenticated user's ID           |
| **Backend**           | On business events, send to `receiverId: userId`   |
| **Payload**           | `{ type: "notification", title, body, actionUrl }` |

### Example flow

1. User logs in → client connects with `userId`.
2. Order ships → order service sends message to that `userId`.
3. Client shows toast or inbox badge from `onMessage`.

Use **structured payload types** so one handler can route `notification`, `badge`, and `deep-link` events.

→ [Structured payloads](https://dnotifier.gitbook.io/product-docs/realtime-communication/structured-payloads.md)

***

## Collaborative UI sync

Multiplayer editors, whiteboards, shared forms, and presence indicators need low-latency sync between **known participants**.

### Pattern

| Approach                | Description                                                                      |
| ----------------------- | -------------------------------------------------------------------------------- |
| **Pairwise sync**       | User A sends to User B's ID with cursor/selection state                          |
| **Room via ID list**    | Maintain participant list in your app; broadcast by sending to each `receiverId` |
| **Session coordinator** | Backend merges state; pushes canonical snapshot to each participant ID           |

### Example flow

1. Two users join a document → both connect with distinct user IDs.
2. User A edits → client sends `{ type: "op", docId, patch }` to User B's ID (and optionally to a service ID for persistence).
3. User B applies patch in `onMessage`.

DNotifier delivers messages; **your app** defines document IDs, operational transform, and conflict rules.

→ [Binary messaging](https://dnotifier.gitbook.io/product-docs/realtime-communication/binary-messaging.md) (efficient op streams)

***

## Backend-to-client updates

Microservices, job runners, and webhooks often need to push results to **one** connected client — export finished, payment confirmed, deployment complete.

### Pattern

| Component         | Role                                                             |
| ----------------- | ---------------------------------------------------------------- |
| **Job worker**    | Completes long task; knows requesting `userId` from job metadata |
| **HTTP RPC send** | Server sends to `receiverId` without holding WebSocket           |
| **Client**        | Shows progress complete, download link, or error                 |

### Example flow

1. User starts export → UI connects (if not already) and displays spinner.
2. Worker processes file asynchronously.
3. Worker calls server-side send API with `receiverId: userId`, payload `{ type: "export-ready", url }`.
4. Client opens download dialog.

{% hint style="success" %}
Store the **user ID** on every async job when the job is created. Delivery is always `senderId` (service account) → `receiverId` (user).
{% endhint %}

→ [Developer integration guide — Webhooks to realtime bridge](https://dnotifier.gitbook.io/product-docs/platform-overview/developer-integration-guide.md#webhooks-to-realtime-bridge)

***

## Microservice events via direct messaging

In event-driven architectures, services can notify **specific consumers** by user or service ID instead of operating a separate message bus for client-facing events.

### Pattern

| ID type             | Example                                                   |
| ------------------- | --------------------------------------------------------- |
| **End user**        | `user-9281` — mobile app receives event                   |
| **Service account** | `svc-billing` — another connected worker receives command |
| **Device**          | `device-abc` — IoT gateway connection                     |

Service A sends to Service B's connected ID, or to a user's ID for last-mile delivery. Your platform layer maps business events to **receiver IDs**.

***

## Live progress tracking

Long-running AI jobs, uploads, and installs benefit from incremental progress pushed to the initiating user.

### Pattern

1. Client starts operation with `userId` connected.
2. Worker sends `{ type: "progress", percent: 42, stage: "indexing" }` to that ID repeatedly.
3. UI binds progress bar to `onMessage`.

Combine with **AI** or **workflows** for "AI is thinking" UX — see [Combined use cases](https://dnotifier.gitbook.io/product-docs/platform-overview/use-cases/combined.md).

→ [Large messages & chunking](https://dnotifier.gitbook.io/product-docs/realtime-communication/chunking.md)

***

## When to use chat or AI instead

| Need                              | Use                                                                                             |
| --------------------------------- | ----------------------------------------------------------------------------------------------- |
| Conversation threads with history | [Chat use cases](https://dnotifier.gitbook.io/product-docs/platform-overview/use-cases/chat.md) |
| LLM answers and RAG               | [AI use cases](https://dnotifier.gitbook.io/product-docs/platform-overview/use-cases/ai.md)     |
| Multi-step agent pipelines        | [Workflows](https://dnotifier.gitbook.io/product-docs/workflows-and-agents/overview.md)         |
| Simple live delivery to a user ID | **Realtime communication** (this page)                                                          |

***

## Next steps

| Task                           | Documentation                                                                                                             |
| ------------------------------ | ------------------------------------------------------------------------------------------------------------------------- |
| Connect and send first message | [Your first message](https://dnotifier.gitbook.io/product-docs/getting-started/first-message.md)                          |
| Server-side delivery           | [Developer integration guide](https://dnotifier.gitbook.io/product-docs/platform-overview/developer-integration-guide.md) |
| Plan limits                    | [Plan limits & quotas](https://dnotifier.gitbook.io/product-docs/realtime-communication/plan-limits.md)                   |
| Error handling                 | [Error handling & reconnection](https://dnotifier.gitbook.io/product-docs/realtime-communication/error-handling.md)       |
