WebSocket Bus
Cloudillo’s WebSocket Bus provides real-time notifications for connected clients. It is a general-purpose broadcast channel — separate from the RTDB and CRDT WebSocket protocols.
WebSocket Endpoints Overview
Cloudillo provides three WebSocket endpoints for different real-time use cases:
| Endpoint | Purpose | Protocol | Documentation |
|---|---|---|---|
/ws/bus |
Notifications and action forwarding | JSON messages | This page |
/ws/rtdb/{file_id} |
Real-time database subscriptions | Binary protocol | RTDB Protocol |
/ws/crdt/{doc_id} |
Collaborative document editing (Yjs) | Binary sync protocol | CRDT Protocol |
Connection
URL: wss://cl-o.{domain}/ws/bus
Authentication: Required — the client is authenticated at connection time via the Axum auth middleware. Once connected, the connection is registered in the BroadcastManager per (tenant, user), so broadcasts can target a whole tenant or a single user.
The server sends a WebSocket Ping frame every 30 seconds to keep the connection alive; the connection is cleaned up when either side closes.
Message Protocol
All messages use JSON format. The bus uses a generic, flexible message structure rather than strict typed enums.
BusMessage (Client ↔ Server)
| Field | Type | Description |
|---|---|---|
id |
string | Unique message ID (for matching responses) |
cmd |
string | Command type |
data |
object | JSON payload (command-specific) |
Client → Server Messages
ping
Keep connection alive:
Server responds with:
Other Commands
Any other cmd value is accepted and acknowledged:
The bus is designed as a generic transport — application-specific command handling can be added without changing the protocol.
Server → Client Messages (Broadcasts)
The server pushes broadcast messages to connected clients via the BroadcastManager. Messages are delivered to all connections for a tenant (send_to_tenant) or to a specific user (send_to_user).
ACTION
Sent when an action is created locally or received via federation:
This is the primary real-time event — it notifies connected clients about new posts, comments, reactions, messages, connection requests, and all other action types.
notification
Sent by the action DSL hook system for targeted notifications:
FILE_ID_GENERATED
Sent when a file upload completes and the content-addressed file ID is computed:
Architecture
BroadcastManager
The BroadcastManager maintains a registry of connected users per tenant, using tokio::broadcast channels for message distribution:
- Multi-tenant isolation — each tenant’s broadcasts are separate
- Per-user targeting —
send_to_tenantreaches all of a tenant’s connections;send_to_userreaches one user’s connections - Bounded buffer — 128 messages per channel; a slow receiver that lags is skipped forward (warned), not disconnected
- Automatic cleanup — connections are removed when the WebSocket closes
Action Forwarding
The bus integrates with the action processing pipeline:
Outbound (local action creation):
- User creates action via
POST /api/actions ActionCreatorTaskcompletes- Action broadcast to all connected sessions for the user’s tenant
Inbound (federated action reception):
- Remote action arrives at
POST /api/inbox ActionVerifierTaskverifies and stores the action- Action broadcast to all connected sessions for the target tenant
See Also
- RTDB WebSocket Protocol - Real-time database subscriptions
- CRDT WebSocket Protocol - Collaborative editing
- System Architecture - Overall architecture
- Actions - Action token types that trigger notifications