Executive Summary: Techniques to prevent HTTP 429 Too Many Requests when broadcasting to massive contact lists.
Meta imposes strict rate limits on the WhatsApp Cloud API. If you try to loop through 10,000 contacts and fire Guzzle HTTP requests synchronously, your account will be throttled and potentially flagged.
### The Queue-Driven Approach
Instead of sending messages immediately, dispatch them to a queue with a dynamic delay:
```php
foreach ($contacts as $index => $contact) {
// Stagger jobs by 1 second each to respect rate limits
SendWhatsAppMessageJob::dispatch($contact, $template)
->delay(now()->addSeconds($index));
}
```
### Exponential Backoff
Always configure your queue workers with exponential backoff. If a job fails due to a temporary API outage or limit, Laravel will wait longer before retrying.
```php
public $backoff = [10, 30, 60, 120]; // Wait 10s, then 30s, etc.
```
This ensures your application gracefully handles traffic spikes.