Skip to content
~/cynarski.me

Sockudo: my new favourite WebSocket server (and why I'm done with Pusher)

8 min read Architecture

I have a new obsession, and it's called Sockudo.

It's a WebSocket server written in Rust that speaks the Pusher protocol. Laravel's broadcasting, Laravel Echo and pusher-js talk to it exactly as they would to Pusher or Reverb. No new client library, no rewrite of your events. You point the app at a different host and that's it.

I've only just found it, I can't stop playing with it, and I've already made a decision: no more Pusher, not even for fresh projects. Here's why, and where Laravel Reverb still fits.

Why not just keep Pusher?

Pusher is lovely on day one. Then you look at the pricing page again: it charges per connection and per message, and a busy app with presence channels gets expensive fast. Your real-time traffic also goes through a third party, and every connection limit is someone else's decision.

Sockudo gives me the same protocol on my own infrastructure, for the cost of a few small containers.

Sockudo vs Reverb in production

Reverb is great, and I'll come back to it. But in production, these are the reasons I reach for Sockudo:

  • Rust, not a PHP event loop. Reverb runs on a ReactPHP event loop. Past about a thousand connections you need ext-uv, raised open-file limits, Supervisor tuning and so on. Sockudo is a single binary in a small container, built for lots of long-lived connections, and it uses very little memory doing it.
  • Many apps, one cluster. Sockudo keeps its apps in a database (Postgres, MySQL, DynamoDB and others). Each app has its own key and secret, connection limits, allowed origins, client-event switch and webhooks. With Reverb, extra apps live in config/reverb.php of the one Laravel app that runs the server. With Sockudo, adding a site is inserting a row.
  • Built for running in a cluster. Prometheus metrics come out of the box, and /up checks the dependencies. /ready reports when a pod is nearly full, so the load balancer stops sending it new clients. Shutdown drains connections gracefully. These are exactly the things you need for Kubernetes.
  • Protection built in. Rate limiting for the HTTP API and for WebSocket clients, per-app limits on payload size, channels and presence members, and origin checks.
  • It isn't part of your app. Reverb runs inside your Laravel codebase, so it's deployed, restarted and scaled with it. Sockudo is infrastructure: upgrade it, scale it or restart it without touching the app.

Scaling: Redis is the glue

A single WebSocket server holds every connection in its own memory. As soon as you run two, you have a problem: a client connected to server B never hears an event that your app published through server A.

The fix is a shared adapter. Every Sockudo node publishes incoming events to Redis pub/sub and receives the events from every other node. So it doesn't matter which pod the app publishes to or which pod the browser is connected to.

text
Laravel ──publish──▶ Sockudo pod A ─┐
                                    ├──▶ Redis pub/sub ──▶ every pod ──▶ its connected browsers
Laravel ──publish──▶ Sockudo pod B ─┘

Three settings matter:

  • ADAPTER_DRIVER=redis makes the nodes share events.
  • CACHE_DRIVER=redis is required with the Redis adapter. Sockudo refuses to start without it, because a node-local cache can't authorise or de-duplicate across nodes. That's a good refusal.
  • ADAPTER_FALLBACK_TO_LOCAL=false makes a node fail rather than quietly run on its own when Redis is down. A node that silently can't see the others is the worst kind of bug: everything looks fine, and half your users miss messages.

Then you just add pods. Here's roughly how I deploy it on Kubernetes with the official Helm chart:

values.yaml
# Sockudo Helm chart values (oci://ghcr.io/sockudo/charts/sockudo)
replicaCount: 4

image:
  repository: sockudo/sockudo
  tag: "5.1.0"

# Never drop below 3 pods during a rollout or a node drain
pdb:
  enabled: true
  minAvailable: 3

terminationGracePeriodSeconds: 45 # longer than shutdownGracePeriod

config:
  shutdownGracePeriod: 30
  adapterDriver: redis       # fan-out between pods over Redis pub/sub
  cacheDriver: redis         # required with the redis adapter
  appManagerDriver: postgres # one row per app in `applications`
  rateLimiter:
    enabled: true
    apiMaxRequests: 6000     # per IP per window; your app servers publish a lot
    apiWindowSeconds: 60
    wsMaxRequests: 60
    wsWindowSeconds: 60

redis:
  host: your-redis.internal
  port: 6379

extraEnv:
  # Refuse to run split-brain: without Redis, pods can't see each other's clients
  - name: ADAPTER_FALLBACK_TO_LOCAL
    value: "false"
  - name: SOCKUDO_MAX_CONNECTIONS
    value: "50000"

serviceMonitor:
  enabled: true # Prometheus metrics on :9601

To be fair to Reverb: it scales horizontally over Redis too (REVERB_SCALING_ENABLED=true plus a shared Redis). The difference is everything around that: the runtime, multi-app management, probes, metrics and limits. With Sockudo all of that is already there; with Reverb a lot of it is your own work.

Update: how it actually performs

Added a few weeks after this post, once it had been running in production.

Here's a normal afternoon on the cluster from the values file above: four pods serving about 50 sites, read from the Grafana dashboard over six hours.

Connected sockets ~3,650 (850–960 per pod)
Active channels ~3,200
Connects / disconnects ~13 per second each, all day long
Messages and API calls ~18 WebSocket messages/s, ~12 REST API calls/s
Broadcast latency p50 0.83 ms, p95 2.3 ms, p99 3.6 ms
Cross-pod requests over Valkey ~115/s, zero unanswered, p50 0.84 ms, p99 6.6 ms
CPU per pod 0.02–0.03 cores
Memory per pod 170–200 MiB working set
Busiest Tokio worker ~0.3% busy
Connection errors 0

The numbers I keep showing people:

  • Sub-millisecond median broadcast latency, and a p99 under 4 ms. The hop between pods through Valkey adds well under a millisecond at the median.
  • About 3 hundredths of a CPU core per pod, holding nearly a thousand open sockets each. The busiest async worker is idle 99.7% of the time.
  • Under 200 MiB of memory per pod, so the whole cluster fits in less than a gigabyte.
  • Zero connection errors and zero unanswered cross-pod requests, with the rate limiter checking every API call and WebSocket upgrade.

This isn't a huge load, and that's the point: the four pods are there for availability, not capacity. On these numbers, one pod could carry the whole lot many times over.

Where Reverb still shines

I'm not throwing Reverb away. It's the perfect tool when:

  • You're developing locally and don't want anything outside PHP: php artisan reverb:start and you're done.
  • You're starting a project, with one server and a few hundred connections. Reverb on the same box is the least moving parts you can have.
  • You want everything in one Laravel codebase.

The best part: because both speak the Pusher protocol, you don't have to choose up front. Laravel's reverb broadcasting driver is the Pusher driver underneath, so the same .env works against both servers:

.env
; .env (local). The same names work for Reverb and for Sockudo.
BROADCAST_CONNECTION=reverb

REVERB_APP_ID=app-id
REVERB_APP_KEY=app-key
REVERB_APP_SECRET=app-secret

; Where Laravel publishes and where the browser connects
REVERB_HOST=localhost
REVERB_PORT=6001
REVERB_SCHEME=http

; Only used by `php artisan reverb:start`: run Reverb on the same port
REVERB_SERVER_PORT=6001

VITE_REVERB_APP_KEY="${REVERB_APP_KEY}"
VITE_REVERB_HOST="${REVERB_HOST}"
VITE_REVERB_PORT="${REVERB_PORT}"
VITE_REVERB_SCHEME="${REVERB_SCHEME}"

Run php artisan reverb:start on port 6001, or run Sockudo on port 6001, and your app and Echo don't notice the difference. Start on Reverb, move to Sockudo when you outgrow it, and change nothing but the server. And you never needed Pusher.

Running Sockudo locally with Podman

One command, no config file. The default app is set through environment variables:

bash
podman run --rm --replace --name sockudo -p 6001:6001 \
  -e SOCKUDO_DEFAULT_APP_ENABLED=true \
  -e SOCKUDO_DEFAULT_APP_ID=app-id \
  -e SOCKUDO_DEFAULT_APP_KEY=app-key \
  -e SOCKUDO_DEFAULT_APP_SECRET=app-secret \
  -e SOCKUDO_DEFAULT_APP_ENABLE_CLIENT_MESSAGES=true \
  docker.io/sockudo/sockudo:5.1.0

curl http://127.0.0.1:6001/up   # OK

ENABLE_CLIENT_MESSAGES lets Echo's whisper() work, for things like typing indicators.

Want to see the scaling with your own eyes? Run two nodes and a Redis-compatible Valkey on one Podman network. Subscribe a client on port 6002, publish through port 6001, and the event arrives:

bash
podman network create sockudo-net
podman run -d --rm --name valkey --network sockudo-net docker.io/valkey/valkey:8-alpine

for n in 1 2; do
  podman run -d --rm --replace --name sockudo-$n --network sockudo-net -p 600$n:6001 \
    -e ADAPTER_DRIVER=redis -e CACHE_DRIVER=redis -e REDIS_URL=redis://valkey:6379 \
    -e ADAPTER_FALLBACK_TO_LOCAL=false \
    -e SOCKUDO_DEFAULT_APP_ENABLED=true -e SOCKUDO_DEFAULT_APP_ID=app-id \
    -e SOCKUDO_DEFAULT_APP_KEY=app-key -e SOCKUDO_DEFAULT_APP_SECRET=app-secret \
    docker.io/sockudo/sockudo:5.1.0
done

Sockudo inside php artisan dev

Laravel 13's php artisan dev runs your dev processes side by side: serve, the queue, pail logs and Vite. You can register your own processes with DevCommands, so Sockudo starts and stops with everything else:

app/Providers/AppServiceProvider.php
<?php

namespace App\Providers;

use Illuminate\Foundation\DevCommands;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    public function boot(): void
    {
        // `php artisan dev` starts Sockudo in Podman next to serve, queue, logs and vite.
        // It reuses the REVERB_* settings, so the app can't tell which server it talks to.
        if ($this->app->isLocal()) {
            $reverb = config('broadcasting.connections.reverb');

            DevCommands::register(implode(' ', [
                'podman run --rm --replace --name sockudo-dev',
                '-p '.(int) $reverb['options']['port'].':6001',
                '-e SOCKUDO_DEFAULT_APP_ENABLED=true',
                '-e SOCKUDO_DEFAULT_APP_ENABLE_CLIENT_MESSAGES=true',
                '-e SOCKUDO_DEFAULT_APP_ID='.escapeshellarg((string) $reverb['app_id']),
                '-e SOCKUDO_DEFAULT_APP_KEY='.escapeshellarg((string) $reverb['key']),
                '-e SOCKUDO_DEFAULT_APP_SECRET='.escapeshellarg((string) $reverb['secret']),
                'docker.io/sockudo/sockudo:5.1.0',
            ]), 'sockudo')->purple();
        }
    }
}
  • It reads the same REVERB_* settings, so the container always matches what Laravel and Echo use.
  • --replace takes over a leftover container from a previous run, and --rm cleans up when you stop.
  • php artisan dev:list shows it next to the defaults. If you'd rather keep Reverb locally, just don't register it: the .env stays the same.

That's my whole setup: Reverb or Sockudo locally, Sockudo with Redis in production, and the same protocol and .env everywhere. No Pusher bill, ever again.