I manage a service that utilizes whatsapp-web.js to send messages to large (more than 400 participants) groups. This service operates on an Ubuntu Linux server and is implemented using a Node.js script.

When the script sends a few messages per minute, it typically begins to experience significant delays in message delivery—ranging from 15 seconds to several minutes, depending on the number of messages. In some instances, the script stops sending messages altogether and does not recover until approximately 30 minutes have passed. Restarting the server does not resolve the issue. This issue also happens when forwarding messages as well. Monitoring the service with PM2 revealed that the script itself does not consume many resources, but the Chrome instance running in headless mode via Puppeteer does.

To troubleshoot, I began debugging by sending the same messages to a single-person chat, where they were delivered instantly. This led me to conclude that the size of the group is the primary factor affecting message delivery performance.

I attempted to open a case on GitHub regarding this issue, but it was unfortunately closed as “not planned.”

After extensive investigation, I believe I have identified the root cause of the problem: the chat itself was exceptionally large. Although it contained no images or other media, it had accumulated thousands of messages over time. Loading such a vast chat in the web UI likely caused the system to become unresponsive, leading to the delays and interruptions in message delivery.

So, the solution for me was to clear all the chats that are a group in a function, and after running it everything went back to being instantaneous:

Also, I found that sending to group chats like this provides the best performance:

How to use?

As a message trigger:

On client ready:

 

 

Cloud solutions

If you’re looking for a reliable cloud solution and want to support my work at the same time, DigitalOcean is the perfect choice. With my affiliate link, you’ll receive $200 worth of free hosting products, giving you the chance to explore their powerful and easy-to-use platform at no cost. Whether you’re a beginner or an experienced developer, DigitalOcean offers everything you need to build, scale, and manage your website or app with ease. By signing up through my link, you not only help me but also get an incredible deal to start your cloud journey. Don’t miss this opportunity—get started with DigitalOcean today!

Click on the affiliate link below to get your free 200$ starter budget.

DigitalOcean Referral Badge

Leave a comment