'How to do rate control from Google Cloud Platform?

How should I go about controlling the rate of my Google Cloud Platform code calling an third party API?

Specifically, I need to send out SMS text messages over many different phone numbers via Twilio. And Twilio requires us to send a) no more than 3 messages/second per phone numbers, b) no more than 25 messages/second across all numbers.

I explored several approaches for my code, but they all come down to one point: how do I reliably control the number of parallel executions of those code on the platform.

Thanks!



Solution 1:[1]

Combining number of messages/second per phone and number of message/second globally is not possible.

Else, you can use Cloud Task. Queue all your messages on Cloud Task, and set a rate limit to call a Cloud Functions that call Twilio API. You can put that limit to 25 per second for the global value

For the error that you will get with the same phone number, you can configure retry policies.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 guillaume blaquiere