Real-Time Laravel: Why WebSockets Beat Polling Every Time

By Amas
Real-Time Laravel: Why WebSockets Beat Polling Every Time

If you’ve ever built a chat feature, a live dashboard, or a notification system, chances are you started with polling. It’s the classic hack: the frontend keeps asking the backend, “Anything new yet? How about now? Now?”

It works, sort of. But it’s also like trying to hold a conversation by repeatedly poking someone in the shoulder until they finally answer.

The good news? Laravel has Reverb, its very own WebSocket server. And with it, you can finally build real-time applications that feel smooth, instant, and modern, without hacks or external services.

The Pain of Polling

Let’s paint the picture.

Imagine you’re building a dashboard that shows the number of active users on your app. With polling, the client would hit /api/users/active every few seconds:

setInterval(async () => {
    const res = await fetch('/api/users/active');
    const data = await res.json();
    updateCounter(data.count);
}, 3000);

On paper, it’s fine. In practice:

  • It’s wasteful. 9 out of 10 requests return nothing new.

  • It feels slow. If something changes right after your poll, the user won’t see it until the next cycle.

  • It doesn’t scale. Multiply that by thousands of users all polling every few seconds… your server starts sweating.

This is why chat apps built with polling always felt laggy. Why dashboards refreshed with a stutter. Why developers looked for better solutions.

WebSockets: A Conversation, Not an Interrogation

WebSockets flip the model. Instead of the client asking, the server just tells the client when something happens.

Think of it as the difference between: knocking on a door every 5 seconds asking, “Pizza ready yet?” vs. having the chef text you the moment your order’s out of the oven.

That’s what a persistent, two-way WebSocket connection gives you: instant communication without wasted effort.


Enter Laravel Reverb

Laravel Reverb is the framework’s official WebSocket server, built specifically for real-time broadcasting. Instead of gluing on an external service or spinning up a separate stack, Reverb runs right alongside your Laravel app.

It’s fast, lightweight, and built for high concurrency. More importantly, it feels native, the same elegant developer experience Laravel is known for, now extended to real-time apps.

No extra infrastructure. No separate runtime. Just Laravel, speaking WebSocket natively.

 

Getting Started with Reverb

1. Installation

Reverb ships as a package:

composer require laravel/reverb
php artisan install:broadcasting

That last command sets up your broadcasting configuration for Reverb.

2. Configure Your .env

 
BROADCAST_CONNECTION=reverb

REVERB_APP_ID=app-id
REVERB_APP_KEY=app-key
REVERB_APP_SECRET=app-secret
REVERB_HOST=127.0.0.1
REVERB_PORT=8080


3. Start the WebSocket Server

php artisan reverb:start

And just like that, your Laravel app is speaking WebSockets.

 

Broadcasting an Event: Example

Let’s say you’re running an online store and you want to update a dashboard whenever someone places a new order.

  1. Create the event:

    php artisan make:event OrderPlaced
    
  2. Update the event:
    use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
    
    class OrderPlaced implements ShouldBroadcast
    {
        public function __construct(public string $orderId) {}
    
        public function broadcastOn(): array
        {
            return ['orders'];
        }
    }
    
  3. Fire the event when an order is created:
    event(new OrderPlaced($order->id));
    

That’s all the backend needs.


Listening on the Frontend with Echo

On the frontend, Laravel Echo connects you to Reverb:

 
npm install laravel-echo

In resources/js/bootstrap.js (or any other JS app you use in your application):

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,
    cluster: import.meta.env.VITE_PUSHER_APP_CLUSTER,
    forceTLS: true
});

Now Subscribe to listen to the updates:

window.Echo.channel('orders')
    .listen('OrderPlaced', (e) => {
        console.log("New order received:", e.orderId);
    });

When someone checks out, everyone connected instantly sees the update. No reload. No delay.

 

Understanding Reverb Channel Types

When working with Reverb, everything revolves around channels. A channel is like a “room” where your events get broadcast and your clients listen in. Laravel gives you a few types of channels, each suited to different use cases.

1. Public Channels

These are open to everyone. Any connected client can listen to them without authentication.

When to use: For data that doesn’t depend on user identity, like live counters, public feeds, or dashboards.

// routes/channels.php
Broadcast::channel('updates', function () {
    return true; // No auth required
});

On the frontend: 

window.Echo.channel('updates')
    .listen('NewPostCreated', (e) => {
        console.log(e.post);
    });

 

2. Private Channels

Private channels require authentication. They’re tied to a specific authenticated user.

When to use: Notifications, private dashboards, or anything that belongs to a single user.

// routes/channels.php
Broadcast::channel('user.{id}', function ($user, $id) {
    return (int) $user->id === (int) $id;
});

 On Frontend:

window.Echo.private(`user.${userId}`)
    .listen('MessageReceived', (e) => {
        console.log('New message:', e.message);
    });


3. Presence Channels

Presence channels are like private channels but with an extra layer: they know who is inside. Laravel will track connected users, so you can show online lists, typing indicators, or collaborative features.

When to use: Chat rooms, multiplayer games, collaborative editors.

// routes/channels.php
Broadcast::channel('chat.{roomId}', function ($user, $roomId) {
    return ['id' => $user->id, 'name' => $user->name];
});

Frontend:

 
window.Echo.join(`chat.${roomId}`)
    .here((users) => {
        console.log('Currently online:', users);
    })
    .joining((user) => {
        console.log(user.name, 'joined');
    })
    .leaving((user) => {
        console.log(user.name, 'left');
    });


What You Can Build with Reverb

Once you have Reverb set up, it’s hard not to see possibilities everywhere. A few ideas to get your imagination going:

  • 💬 Chat apps
    The classic. Whether it’s a simple support chat or a Slack-style team tool, WebSockets make sure messages appear instantly without refreshes.

  • 📊 Live dashboards
    Think server monitoring, sales dashboards, or even real-time sports stats. Instead of refreshing every few seconds, numbers just flow in.

  • 🔔 Instant notifications
    Push alerts when someone comments, likes, tags, or @mentions you, just like you’d expect in modern social apps.

  • 🛒 E-commerce stock updates
    Flash sales, countdown timers, “only 2 left in stock” messages, all powered by live updates instead of page reloads.

  • 🎮 Multiplayer games
    Card games, trivia, real-time scoreboards, or even collaborative drawing apps. WebSockets make every move visible across players immediately.

  • 📈 Financial & trading apps
    Stock tickers, crypto price changes, order books, users expect those to update by the second.

  • 🚌 Real-time maps & tracking
    Show delivery drivers, public transport locations, or even “your order is on the way” updates. One socket connection, everyone sees the live movement.

  • 📝 Collaborative editing
    Think Google Docs style: multiple people editing the same document or whiteboard at once, with changes appearing live.

  • 🎤 Live Q&A / polling systems
    Great for conferences, online classrooms, or webinars, attendees vote or submit questions, and results appear instantly.

  • 🎧 Music & watch parties
    Sync playback of audio or video across users, everyone presses play at the same time, and Reverb keeps streams aligned.

  • ⚡ IoT dashboards
    Monitor connected devices in real-time (temperature sensors, smart meters, etc.) and update the UI without refreshing.

  • 📦 Logistics & delivery tracking
    Show customers when their package leaves the warehouse, when it’s on the truck, and when it’s about to arrive, all updated instantly.

  • 🎟️ Ticketing systems
    When event seats sell out, reflect that immediately so two users aren’t fighting over the same last ticket.

 

Final Thoughts

Polling had its moment. It was simple, it worked, and it let us fake “real-time” before the web was ready for it.

But today, users expect immediacy. A chat that lags feels broken. A dashboard that only updates every 10 seconds feels outdated.

Laravel Reverb changes the game by making real-time features part of Laravel itself. No extra infrastructure, no expensive third-party services, just native WebSockets that “feel Laravel.”

So the next time you reach for setInterval, pause.

Ask yourself: Would this be better as an event broadcast over Reverb?
Chances are, the answer is yes.

And your users will feel the difference.

Keep building great stuff! 🚀

Share this post.
Liked that? Subscribe to our newsletter for more
Ship fast & don't reinvent the wheel

Build your SaaS using SaaSykit

SaaSykit is a SaaS boilerplate that comes packed with all components required to run a modern SaaS software.

Don't miss this

You might also like