Centrifugo — Scalable Real-Time Messaging Server
Centrifugo is a scalable real-time messaging server that adds live updates to any application. It handles WebSocket connections, scales horizontally with Redis or NATS, and provides a language-agnostic API — a self-hosted alternative to Pusher, Ably, and Socket.IO.
What it is
Centrifugo is a scalable real-time messaging server that adds live update capabilities to any application regardless of its tech stack. It handles WebSocket connections, Server-Sent Events (SSE), HTTP streaming, and GRPC transports. The server is language-agnostic -- your backend publishes messages via HTTP or GRPC API, and Centrifugo delivers them to connected clients in real time. It supports Redis, Nats, and Tarantool as scalable backends for multi-node deployments.
Development teams that need to add real-time features (live notifications, chat, dashboards, collaborative editing) to existing applications without rewriting their backend benefit most.
How it saves time or tokens
Centrifugo decouples real-time message delivery from your application logic. Instead of implementing WebSocket handling, connection management, heartbeats, reconnection logic, and horizontal scaling yourself, you deploy Centrifugo as a sidecar service. Your backend only needs to make HTTP calls to publish messages. This reduces the engineering effort from weeks of WebSocket infrastructure work to hours of integration.
How to use
- Install and run Centrifugo:
# Docker
docker run -p 8000:8000 centrifugo/centrifugo:latest centrifugo --admin
# Or download binary
curl -sSL https://centrifugal.dev/install.sh | sh
centrifugo --config config.json
- Connect from a client:
import { Centrifuge } from 'centrifuge';
const client = new Centrifuge('ws://localhost:8000/connection/websocket');
const sub = client.newSubscription('notifications');
sub.on('publication', (ctx) => {
console.log('New message:', ctx.data);
});
sub.subscribe();
client.connect();
- Publish from your backend:
curl -X POST http://localhost:8000/api/publish \
-H 'Authorization: apikey YOUR_API_KEY' \
-d '{"channel": "notifications", "data": {"text": "Hello"}}'
Example
# Python backend publishing to Centrifugo
import requests
def notify_user(user_id, message):
requests.post('http://centrifugo:8000/api/publish', json={
'channel': f'user:{user_id}',
'data': {'type': 'notification', 'text': message}
}, headers={'Authorization': 'apikey YOUR_API_KEY'})
Related on TokRepo
- DevOps Tools -- Infrastructure tools for scalable applications
- Self-Hosted Solutions -- Self-hosted alternatives for real-time infrastructure
Common pitfalls
- Centrifugo requires a backend engine (Redis, Nats) for horizontal scaling. A single-node deployment works for development but does not scale in production without a broker.
- Client tokens must be generated by your backend with a shared secret. Exposing the API key in client-side code creates a security vulnerability.
- Channel naming conventions matter for authorization. Use namespaces to separate public channels from private user channels.
Frequently Asked Questions
Centrifugo supports WebSocket (bidirectional), Server-Sent Events (SSE, server-to-client), HTTP streaming, and GRPC. Clients automatically negotiate the best available transport. WebSocket is preferred for bidirectional communication.
Yes. Centrifugo supports Redis, Nats, and Tarantool as broker backends for multi-node deployments. Messages published to any node are distributed to subscribers connected to any other node through the broker.
Yes. Centrifugo uses JWT tokens for client authentication. Your backend generates a token with user identity and channel permissions. The server validates the token on connection and enforces channel-level authorization.
Official client SDKs exist for JavaScript (browser and Node.js), Go, Python, Dart (Flutter), Swift (iOS), and Java/Kotlin (Android). The JavaScript SDK is the most commonly used for web applications.
Yes. Centrifugo is open source under the MIT license. The server, client SDKs, and documentation are all freely available. A commercial Centrifugo PRO version adds features like push notifications and analytics.
Citations (3)
- Centrifugo GitHub Repository— Centrifugo supports WebSocket, SSE, HTTP streaming, and GRPC
- Centrifugo Documentation— Redis, Nats, and Tarantool backends for horizontal scaling
- Centrifugo Auth Documentation— JWT-based authentication and channel authorization
Related on TokRepo
Discussion
Related Assets
Conda — Cross-Platform Package and Environment Manager
Install, update, and manage packages and isolated environments for Python, R, C/C++, and hundreds of other languages from a single tool.
Sphinx — Python Documentation Generator
Generate professional documentation from reStructuredText and Markdown with cross-references, API autodoc, and multiple output formats.
Neutralinojs — Lightweight Cross-Platform Desktop Apps
Build desktop applications with HTML, CSS, and JavaScript using a tiny native runtime instead of bundling Chromium.