2

I am getting the error below when I send bulk messages using Twilio Message Service. [HTTP 429] Unable to create record: Too Many Requests

I have around 50 numbers in the sender pool in this Message Service. And I am trying to send about 5K messages at once, some delays are Okay, But the messages couldn't be sent due to this error,

Thanks in advance,

MichaelWu
  • 31
  • 1
  • 4

1 Answers1

4

Twilio developer evangelist here.

A 429 error means that you are exceeding the number of concurrent connections to the Twilio API. By default, this is 100, though it can vary depending on your account.

To counteract this, you should aim to make less than 100 concurrent requests to the API and implement retries with an exponential back off to allow for your other requests to finish.

There is more information on the 429 error here including further links for implementing the above strategies.

philnash
  • 70,667
  • 10
  • 60
  • 88
  • I am going to split the number of requests, – MichaelWu Aug 04 '20 at 12:55
  • It is always best to implement retries with back off so that if limits change your application can dynamically adapt to it. And limiting the concurrency should stop that from being an issue most of the time. – philnash Aug 04 '20 at 12:56
  • I got you, Phil, I justs checked the Twilio document for retried implementation, but I am not sure how to implement, would you please let me know details? – MichaelWu Aug 04 '20 at 13:38
  • That all depends on what you are working with. Can you share the current way you are making all of these API calls? The more detail the easier it will be to help you come up with a solution. – philnash Aug 04 '20 at 13:41
  • I use PHP/Laravel to send API Request, using Horizon for Job queue, – MichaelWu Aug 04 '20 at 15:02
  • I'm no Laravel developer I'm afraid, but these articles seem to suggest ways to build backing off into your retries: https://medium.com/maatwebsite/laravel-and-murphys-law-e22731be31d9 and http://snags88.github.io/backoff-strategy-for-laravel-jobs. This documentation suggests you can rate limit your queue too: https://laravel.com/docs/7.x/queues#rate-limiting. – philnash Aug 05 '20 at 01:14
  • I got it, Phill, the thing is the job queue works well, all jobs are successfully sent, is there any way to handle this on Twilio? why doesn't Twilio Message Service handle this? – MichaelWu Aug 05 '20 at 02:24
  • [2020-08-04 08:33:33][274636] Processed: App\Jobs\SendText [2020-08-04 08:33:32][274822] Processed: App\Jobs\SendText – MichaelWu Aug 05 '20 at 02:24
  • But you're telling me that you are getting 429 errors. Which means your job queue is dispatching the API requests quicker than your Twilio account API access can handle. These restrictions exist to ensure quality of service for everyone, if there were no limits on API access then other users could potentially impact on your use of the API by flooding the service with connections. So, it is up to you to handle 429 errors by retrying and reducing your concurrency. – philnash Aug 05 '20 at 04:55