Sockudo: A High-Performance WebSockets Server in Rust
Hey Devs! π
Are you looking for a high-performance, memory-efficient, and scalable WebSockets server that plays nicely with your existing Laravel Echo or Pusher client setup? Say hello to Sockudo! π
Sockudo is a brand-new WebSockets server written entirely in Rust π¦, designed from the ground up to be a robust and seamless replacement for services like Pusher, especially if you're in the Laravel ecosystem. It leverages Rust's incredible performance, memory safety, and concurrency features to deliver a top-notch real-time communication solution.
π₯ Why Sockudo? What's Under the Hood?
Sockudo isn't just another WebSocket server; it's packed with features to make your real-time applications shine:
- Full Pusher Protocol Compatibility: Drop-in replacement! Works seamlessly with Laravel Echo and other Pusher client libraries (JavaScript, Node.js, PHP, and more!).
- Built with Rust: Get the speed, safety, and concurrency benefits of Rust for a high-throughput, low-latency experience.
- Modular Architecture: Need to swap out components? Sockudo's design makes it easy.
- Horizontal Scaling Out-of-the-Box: Built-in adapters for Redis, Redis Cluster, and NATS mean you can scale as your application grows.
- Flexible App Management: Supports memory, MySQL, and DynamoDB backends for managing your application configurations.
- Rich Channel Support: Public, private, presence, and even encrypted private channels are all supported.
-
Webhooks: Keep your application in the loop when channels become occupied or vacated. You can configure event types like
member_added
,member_removed
, andsubscription_count
. -
Performance Monitoring: Integrated Prometheus metrics endpoint (
/metrics
) to keep an eye on active connections, message stats, memory usage, and more. - Rate Limiting: Protect your server from abuse with configurable rate limiting (supports Redis).
- Caching: Memory and Redis cache providers to speed things up.
- Authentication: Secure your channels with robust subscription verification and user authentication.
π οΈ The Tech Stack
Sockudo leverages a modern and powerful stack:
- Core: Rust
- Scaling Adapters: Redis, Redis Cluster, NATS
- App Management Backends: In-Memory, MySQL, DynamoDB
- Caching: In-Memory, Redis
- Metrics: Prometheus
- Queueing (for webhooks, etc.): Redis, SQS
π Quick Start - Get Up and Running!
Want to take Sockudo for a spin? It's easy:
Prerequisites:
- Rust (1.85 or newer)
- Redis (optional, for scaling)
Clone & Build:
git clone https://github.com/RustNSparks/sockudo.git
cd sockudo
cargo build --release
Run!:
./target/release/sockudo
This will start Sockudo with the default in-memory configuration.
βοΈ Configuration - Tailor It to Your Needs
Sockudo is super flexible. You can configure it via a config.json
file or using environment variables.
Here's a glimpse of what a config.json
might look like for app management and adapter setup:
{
"app_manager": {
"driver": "memory", // Or "mysql", "dynamodb"
"array": { // Used if driver is "memory"
"apps": [
{
"id": "demo-app",
"key": "demo-key",
"secret": "demo-secret",
"max_connections": "1000", // Can be a string or number
"enable_client_messages": true,
"max_client_events_per_second": "200" // Can be a string or number
}
]
}
},
"adapter": {
"driver": "redis", // Or "nats", "local"
"redis": {
"requests_timeout": 5000,
"prefix": "sockudo",
"redis_pub_options": {
"url": "redis://127.0.0.1:6379"
},
"redis_sub_options": {
"url": "redis://127.0.0.1:6379"
}
}
},
"port": 6001, // Default WebSocket port
"metrics": {
"enabled": true,
"port": 9601 // Default metrics port
}
}
(For all available options, check out options.rs
in the project!)
Or, use environment variables for quick setup:
export PORT=6001
export ADAPTER_DRIVER=redis
export REDIS_URL=redis://127.0.0.1:6379
./target/release/sockudo
π Laravel Integration? Smooth as Butter!
If you're a Laravel developer, you'll feel right at home. Just update your Laravel Echo configuration in resources/js/bootstrap.js
:
// resources/js/bootstrap.js
import Echo from 'laravel-echo';
import Pusher from 'pusher-js';
window.Pusher = Pusher;
window.Echo = new Echo({
broadcaster: 'pusher',
key: import.meta.env.VITE_PUSHER_APP_KEY,
wsHost: import.meta.env.VITE_PUSHER_HOST ?? window.location.hostname,
wsPort: import.meta.env.VITE_PUSHER_PORT ?? 6001, // Point to Sockudo's port
forceTLS: (import.meta.env.VITE_PUSHER_SCHEME ?? 'http') === 'https',
disableStats: true,
cluster: import.meta.env.VITE_PUSHER_APP_CLUSTER ?? 'mt1', // Sockudo uses 'mt1' as a default or your app ID
});
And your .env
file:
BROADCAST_DRIVER=pusher
VITE_PUSHER_APP_ID=demo-app # Your Sockudo App ID
VITE_PUSHER_APP_KEY=demo-key # Your Sockudo App Key
VITE_PUSHER_APP_SECRET=demo-secret # Your Sockudo App Secret
VITE_PUSHER_HOST=localhost
VITE_PUSHER_PORT=6001
VITE_PUSHER_SCHEME=http
VITE_PUSHER_APP_CLUSTER=mt1 # Or your Sockudo App ID
π€ Works with Your Favorite Pusher Clients
Since Sockudo is Pusher-compatible, you can use standard Pusher client libraries in JavaScript, Node.js, PHP, etc., by simply pointing them to your Sockudo server instance.
Example (JavaScript):
const pusher = new Pusher('demo-key', { // Your Sockudo App Key
wsHost: 'localhost',
wsPort: 6001,
enabledTransports: ['ws', 'wss'],
disableStats: true,
forceTLS: false,
});
const channel = pusher.subscribe('my-channel');
channel.bind('my-event', function(data) {
console.log('Received event:', data);
});
π Ready to Scale?
Sockudo is built for growth:
- Horizontal Scaling: Easily configure the Redis or NATS adapter.
- App Management: Use MySQL or DynamoDB for robust, production-ready app credential management.
π Dive Deeper & Contribute!
Sockudo is an open-source project licensed under AGPL 3.0. We're excited to see how the community uses and improves it!
- β Star us on GitHub: RustNSparks/sockudo
- π Check out the full documentation: sockudo.app
- π€ Got questions or feedback? Open an issue on GitHub!
If you're looking for a performant, modern, and highly compatible WebSocket server, especially if you're working with Rust or Laravel, give Sockudo a try. We think you'll love the speed and efficiency!
Top comments (0)