Realtime (Centrifugo)
Real-time WebSocket messaging with channels, presence, and pub/sub.
Creating a Realtime Server
To create a realtime instance:
- Navigate to Realtime Servers in the sh0 dashboard.
- Click Create Realtime Server.
- Enter a name (e.g., "my-app-realtime").
- Click Create. sh0 deploys a Centrifugo instance with auto-SSL.
Your realtime server is immediately accessible at wss://<name>.sh0.app/connection/websocket.
Channels
Channels are the primary abstraction in Centrifugo. Clients subscribe to channels and receive messages published to them. Channel names are strings -- you define the naming convention.
Namespaces
Use channel namespaces to group channels with shared configuration. For example, channels named chat:room-1 and chat:room-2 belong to the chat namespace (using : as separator).
Configure namespace-level settings for history retention, presence tracking, and permissions in the Centrifugo configuration.
Presence
Enable presence on a channel to track which users are currently subscribed. Presence information includes client ID and user ID. Useful for:
- Showing who is online in a chat room.
- Displaying active collaborators in a document.
- Tracking viewer count on a live stream.
Publish API
Publish messages from your backend to any channel via the HTTP API:
The API key is generated when you create the realtime server and is visible in the dashboard.
JavaScript Client
Install the Centrifugo JavaScript client:
npm install centrifuge
Connect and subscribe:
Authentication
Centrifugo supports JWT-based authentication. When creating the client connection, pass a token:
The token should contain the user's sub (subject) claim. If you are using the sh0 Auth service (Logto), the access token works directly.
Admin Dashboard
Centrifugo includes a built-in admin dashboard for monitoring your realtime server. Access it at your realtime server's domain. The dashboard shows:
- Active connections count.
- Messages per second throughput.
- Active channels and their subscriber counts.
- Server node information and health status.