Skip to content
Laravel Backend Software Architecture

How to Leave a Hosted Hub for Laravel Reverb in One Afternoon

Raheel Shan

Raheel Shan

December 3rd, 2026 · 8 min read

How to Leave a Hosted Hub for Laravel Reverb in One Afternoon

The first objection to a hosted hub is lock-in. The answer is a plan you can read before you write a line of code.

I built RealtimeHub, so take this as the author arguing against his own product's stickiness. If the exit is hard, the series' advice is wrong.

What lives where

Start with what the hub actually holds:

  • The hub: open connections, channel membership and presence in memory, and a buffer of about 10,000 messages per app while your webhook is down
  • Your app: users, rooms, room_user, room_messages, the token route, the post route, and every authorization rule

Nothing durable is on the hub. History, membership, and permissions are in your database from article 6 onward. Leaving means replacing a transport. It does not mean moving data.

The reverse mapping

Article 8 mapped Echo to the hub. Here is the way back:

Hub Reverb
RealtimeHub::broadcast('room.5', 'e', $p) A ShouldBroadcast event on PrivateChannel('room.5')
RealtimeHub::send($id, 'e', $p) An event on the user's private channel
joinChannel and onEvent Echo.private('room.5').listen(...)
The token's channels list Broadcast::channel('room.{room}', ...) in routes/channels.php
sendToChannel(..., 'typing', {}) Echo.private(...).whisper('typing', {})
onPresence and getPresence() Echo.join(...) with here, joining, leaving
The post route, then broadcast() The same route, then a Reverb event
Webhook for one-to-one messages A controller, since the browser posts it

Almost every row is a rename. One row is a real change: a one-to-one message the browser sent over the socket becomes an HTTP post, the same as article 2's first workaround. Chat in rooms already goes through a route, so it moves untouched.

Step 1: put a seam in today

You do not need to plan a migration to prepare for one. Wrap the hub behind your own interface:

interface RealtimeTransport
{
    /** @param int[] $userIds */
    public function toUsers(array $userIds, string $event, array $payload): void;

    public function toChannel(string $channel, string $event, array $payload): void;
}

class HubTransport implements RealtimeTransport
{
    public function toUsers(array $userIds, string $event, array $payload): void
    {
        foreach (array_chunk($userIds, 50) as $chunk) {
            RealtimeHub::send(array_map('strval', $chunk), $event, $payload);
        }
    }

    public function toChannel(string $channel, string $event, array $payload): void
    {
        RealtimeHub::broadcast($channel, $event, $payload);
    }
}

Bind it in a service provider, and change the post route from RealtimeHub::broadcast(...) to app(RealtimeTransport::class)->toChannel(...).

This also makes the route testable. In a test you bind a fake transport that records its calls, and nothing touches the network (article 13).

Step 2: write the Reverb side

Install Reverb (article 3), then add a second transport:

class ChannelEvent implements ShouldBroadcastNow
{
    public function __construct(
        public string $channel,
        public string $name,
        public array $data,
    ) {}

    public function broadcastOn(): array { return [new PrivateChannel($this->channel)]; }
    public function broadcastAs(): string { return $this->name; }
    public function broadcastWith(): array { return $this->data; }
}

class ReverbTransport implements RealtimeTransport
{
    public function toChannel(string $channel, string $event, array $payload): void
    {
        broadcast(new ChannelEvent($channel, $event, $payload));
    }

    public function toUsers(array $userIds, string $event, array $payload): void
    {
        foreach ($userIds as $id) {
            $this->toChannel('App.Models.User.'.$id, $event, $payload);
        }
    }
}

ShouldBroadcastNow skips the queue, so you do not add a queue worker for this.

The token's channels list becomes a channel authorization callback, and it reads the same table:

// routes/channels.php
Broadcast::channel('room.{room}', fn ($user, Room $room) =>
    $room->members()->whereKey($user->id)->exists());

The hub's rule was the token lists the rooms. Reverb's rule is "the callback asks the database on each subscribe". Both say the same thing, and both are one line.

Step 3: the client adapter

The screens should not know which transport is live. One small adapter exposes what they use:

// realtime.js
const seen = new Set();

export function onRoomMessage(roomId, cb) {
    const handle = (m) => {
        if (seen.has(m.id)) return;
        seen.add(m.id);
        cb(m);
    };

    // hub path
    hub.onEvent = (m) =>
        m.channel === `room.${roomId}` && m.event === 'room.message' && handle(m.payload);

    // Reverb path
    Echo.private(`room.${roomId}`).listen('.room.message', handle);
}

export function sendTyping(roomId) {
    hub.sendToChannel(`room.${roomId}`, 'typing', {});
    Echo.private(`room.${roomId}`).whisper('typing', {});
}

The leading dot in .room.message tells Echo not to prefix the event name with a namespace, which broadcastAs() requires. A whisper needs client events switched on in the Reverb app config.

Step 4: run both for a week

A hard cutover is the risky version. The safe one:

  • Make the transport send through both HubTransport and ReverbTransport
  • Make the client listen on both, and drop a message whose id it has already shown
  • Watch for a week that every message arrives on the new path
  • Switch the one-to-one messages to an HTTP post
  • Remove the hub transport, the hub client, and the webhook listener

The id is the database id of the saved message, which is the same on both paths. That is why article 6's payload carries it. Typing and presence are harmless to run twice, because a repeated indicator changes nothing on screen.

What you gain and lose

You gain: Reverb's presence and channels with no per-server memory limit, no third-party dependency, and no hub limits.

You lose: one connection for both directions, the lack of a process to run, and the delivery buffer. You are back to Supervisor, a proxy, SSL and reverb:restart, which is the operations list from article 3.

When to leave

  • You pass 1,000 open connections per app, or the message rate passes 100 a second, and the operator will not raise them (the docs say the operator can)
  • Your rooms hold thousands of people each, or you need presence at that size
  • A customer requires that real-time traffic stays on infrastructure you own

When to stay

  • Your traffic is notifications, direct messages, and chat between known users
  • You have no wish to run a socket process
  • The limits are above what you use today

The exit is a choice you make in an afternoon, so you do not have to make it before you need to.

Try it: realtimehub.raheelshan.com/docs

Previous: Real-Time Message Not Arriving? 8 Places It Dies in Laravel

Next: How to Test Laravel Real-Time Code Without Opening a Socket

Comment "EXIT" and I'll send you the transport interface and both implementations.

Found this useful?

Support the work that goes into these posts.

Support
Comments


Comment created and will be displayed once approved.
Built with Brandidos