4

I know this has been asked a few times but I'm trying to track down what my exact issue could be.

I've got a C# app, which queues up messages to be sent (using Azure Storage Queues) and these are processed by an Azure Webjob. We're using the twilio-csharp nuget package to send the messages.

The code to send a message is pretty simple:

MessageResource.Create(
   body: message.Message,
   from: new Twilio.Types.PhoneNumber(TwilioFromNumber),
   to: new Twilio.Types.PhoneNumber(message.SendToPhoneNumber));

By default, the Webjob will process up to 16 messages at a time but to combat this issue we've set:

context.BatchSize = 2;
context.NewBatchThreshold = 0;

So, at any given point, we're not making more than 2 requests at a time.

Even with this low threshold, we still see these errors in the log periodically:

Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Microsoft.Azure.WebJobs.Host.FunctionInvocationException: Exception while executing function: TextMessageFunctions.SendTextMessage ---> Twilio.Exceptions.ApiException: Too Many Requests at Twilio.Clients.TwilioRestClient.ProcessResponse(Response response)

Some other thoughts:

  1. The answer on this question, from a Twilio Developer Evangelist, suggests the REST API's concurrency limit is 100 by default. Is this still true or there a way for me to check this on my account? There's no way we're close to 100. We never queue up more than 20-30 messages at a time, and that is on the extreme end of things.
  2. We're using a Toll-Free US number to send from. According to Twilio, we should be able to queue up 43,200 messages on their end.

That same article says:

Notice: You can send messages to Twilio at a rapid rate, as long as the requests do not max out Twilio's REST API concurrency limit.

This makes me think I'm doing something wrong, because surely "a rapid rate" could be more than 2 requests at a time (and I still wonder about the rate of 100 mentioned above). Can we truly not call the Twilio API with 2 concurrent requests without getting this error?

lhan
  • 4,585
  • 11
  • 60
  • 105

1 Answers1

4

Twilio developer evangelist here.

There has been a bit of a change in the concurrency limits recently that has affected you here. New accounts are now receiving a much lower concurrency allowance for POST requests, as low as 1 concurrent request. This was to combat a recent rise in fraudulent activity.

I am sure your activity isn't fraudulent, so here's what you should do:

  • For now reduce your batch size to 1 so that you only make 1 request at a time to the Twilio API.
  • Add code to catch errors and if they are 429 response, re-queue the job to happen later (with exponential back off if possible)
  • Get in touch with Twilio Sales to talk to them about your use case and request an increased concurrency limit

I am sure this limit is not going to be the long term solution to the issues we were facing and I am sorry that you are experiencing problems with this.

philnash
  • 70,667
  • 10
  • 60
  • 88