Real time in Markmedi with Laravel Reverb: versioned channels and "doorbell" events
How Markmedi's calendar, waiting list and consultation room update themselves with Reverb, without sending patient data over the WebSocket and revoking access without presence channels.
In a clinic, the calendar is a screen that stays open all day. The receptionist keeps the week on screen, the doctor keeps the patient queue open in her office, and someone across town reschedules an appointment from their phone. If the front desk screen only finds out about the change when someone hits F5, the problem shows up at the counter: two patients arriving for the same slot, or a patient waiting for a room that has already been freed.
In Markmedi I solved this with Laravel Reverb, Laravel's official WebSocket server. In this post I explain how channels are authorized, why channel names carry a version and why the events that go through the socket carry almost nothing.
Where Reverb runs
Markmedi's infrastructure is lean: one container with Nginx, PHP-FPM, Horizon, the scheduler and Reverb, all managed by Supervisor. Reverb starts with reverb:start on its own port, and the proxy forwards WebSocket traffic to it. Since there is only one replica today, I don't need Reverb's horizontal scaling mode (which uses Redis pub/sub to keep several servers in sync). If the application ever gets more replicas, it's a configuration change, not an architectural one.
On the front end, I use @laravel/echo-vue with the Reverb broadcaster, configured once in app.ts. Vue components subscribe to channels through composables, and the subscription follows the component's lifecycle: enter the page, subscribe; leave it, leave the channel.
Private channels authorized by permission
Almost every channel is private. The authorization in routes/channels.php doesn't just ask "does this user belong to the clinic?". It asks whether they have the permission for that screen. The calendar channel requires seeing all appointments or at least one's own; the rooms and equipment channel requires the resources permission; the queue channel requires the queue permission. The transcription channel for a consultation is the most restricted: it requires being able to see patients, being able to view medical records, and being the doctor for that consultation (or having the permission to see all of them).
This matters because Markmedi's RBAC is per clinic and configurable. A receptionist may see the calendar and not see medical records. If the channel only checked clinic membership, WebSocket authorization would be looser than that of the screens themselves.
The revocation problem
Authorization for a private channel happens once, at subscription time. After that the socket stays open. If the clinic owner removes an employee's calendar permission at 10 a.m., their browser, open since 8 a.m., keeps receiving events. Presence channels would help to know who is connected, but they don't solve revocation, and I didn't want to maintain presence state just for that.
The solution was to put a version in the channel name. Each clinic has an access_version column. The calendar channel is called clinic.{id}.appointments.v{version}, and authorization rejects any version other than the current one. Every role or membership change increments the version and, after the commit, fires a ClinicAccessChanged event on each member's personal channel.
// routes/channels.php (simplified)
Broadcast::channel('clinic.{clinicId}.appointments.v{version}', function ($user, $clinicId, $version) {
$clinic = $user->clinics()->find($clinicId);
return $clinic
&& (int) $version === $clinic->access_version
&& $user->canInClinic($clinic, 'appointments.view_all', 'appointments.view_own');
});In the browser, the layout listens for that event on the user's channel and performs a new Inertia visit. The props come back with the new version and the new permissions, the composable notices the channel name has changed and subscribes again. If the user lost the permission, the new subscription is rejected, and the old channel ceases to exist for them. Revocation becomes a consequence of the channel name.

The composable that does this is small: it builds the name with the version from the shared props, watches for clinic or version changes and swaps the subscription. Every real-time screen uses the same composable, so nobody has to remember this rule when building a new screen.
"Doorbell" events
The second decision was about message content. The temptation is to send the whole appointment in the event: patient name, time, procedure. The front end receives it and updates the list without going to the server. It works, but it creates two problems. The first is that patient data now travels along one more path, which needs the same visibility rules as the screens. The second is that the event payload becomes a second API, with a different shape, that has to stay in sync with the page props.
That's why Markmedi's events work like a doorbell. They announce that something changed and say the bare minimum for the client to decide whether it cares: the appointment id and the type of action. Whoever receives it requests the data again through the normal path, with an Inertia partial reload:
useVersionedClinicChannel('appointments', '.calendar.updated', () => {
router.reload({ only: ['appointments', 'stats'] });
});The partial reload goes through the usual controller, policies and tenant scopes. The socket never shows anything the screen wouldn't show, because it shows nothing at all. The cost is one extra request per event, which in a clinic calendar is irrelevant.

Broadcast events also implement ShouldDispatchAfterCommit. Without it, the client could receive the doorbell, reload and read the database before the commit of the transaction that produced the event, seeing the old state. With dispatch after commit, by the time the doorbell rings, the data is already there.
Where this shows up
Rescheduling is the clearest example. When an appointment is rescheduled, by the staff or by a change coming from the doctor's Google Calendar, the action publishes the calendar event and every open screen for that clinic updates. Time blocks follow the same path. The patient queue uses its own channel: when the front desk registers a patient's arrival, the doctor sees the queue change in her office. The rooms and equipment screen also listens to its channel, so a room's occupancy shows up without reloading the page.
In the consultation room, Reverb carries the transcription. The audio is split into segments, each segment is transcribed by a job on the AI queue, and when one finishes, the job fires a segment-ready event on that consultation's channel. The doctor sees the text appear while the consultation is happening. This is the channel with the strictest authorization, for obvious reasons.
Progress for long-running jobs
The positioning report, which analyzes a clinic's digital presence, takes minutes and goes through several stages. The job publishes progress events with ShouldBroadcastNow, so it doesn't have to go back into a queue just to report progress, and the loading page shows the current stage.
This is the only public channel in the system, because the diagnostic page can be viewed before an account exists. The report identifier is a UUID, and the event only carries numbers and the stage name. Since a WebSocket can fail for reasons I don't control (corporate networks, proxies, background tabs), the page also polls the status every few seconds. If the socket works, polling is almost never needed; if it doesn't, the user still gets to the result.
Tests
In tests, broadcasting uses the null driver and I test two separate things: that the action fires the right event, with the minimal payload, and that channel authorization rejects an old version, a missing permission and someone else's clinic. The second part is the one that matters most, because a mistake there doesn't show up on any screen.
Wrapping up
The design in a nutshell: the WebSocket only rings the doorbell, and Inertia is the one who opens the door, with all the access rules that already exist. The version in the channel name solves revocation without extra state. More details on the queues that feed these events are in Queues with Laravel Horizon, and the per-clinic access rules in Multitenancy and security. The project context is on the Markmedi page.