Back

Need Help Scaling Up Group Chat Notifications - Laravel

I initially broadcasted each message to a private channel (private-conversation.{id}), which worked well for one-on-one chats. Individual notifications were also sent via App.User.{id} to show updates outside the chat.

However, for group chats, this approach didn’t scale: each message triggered notifications to all members, quickly overloading the job queue. For instance, 20 messages in a group of 1,000 could result in 20,000 jobs. With 30 active users, it adds up to hundreds of thousands of jobs.

To tackle this, I’m considering a front-end subscription approach. On pages like ChatsList, users would subscribe to each conversation in a loop using Laravel Echo. This way, each new message requires only one event per conversation for updates, even outside the chat.

Trade-Off: This approach increases front-end complexity but drastically reduces backend load, enhancing efficiency.

Any thoughts or alternative ideas on this ?

1

135

In response to @namu

Got it sorted! It was slow because after creating a job to NotifyParticipantsJob, the event NotifyParticipant was implementing shouldBroadcast, which queued the event.(which is unecessary since the NotifyParticipantsJob is already queued in backgroud) To fix it, I just implemented shouldBroadcastNow in the NotifyParticipant event, making it 95% faster. Now, 3K members receive updates instantly in just 2-5 seconds, compared to the former approach, which took 1-3 minutes! It's crazy seeing such speeds after days of optimization. I hope this approach sticks!

92

  • No matching results...
  • Searching...

/ 1000