Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle backpressure using google cloud functions

Using google cloud functions, is there a way to manage execution concurrency the way AWS Lambda is doing? (https://docs.aws.amazon.com/lambda/latest/dg/concurrent-executions.html)

My intent is to design a function that consumes a file of tasks and publish those tasks to a work queue (pub/sub). I want to have a function that consumes tasks from the work queue (pub/sub) and execute the task.

The above could result in a large number of almost concurrent execution. My dowstream consumer service is slow and cannot consume many concurrent requests at a time. In all likelyhood, it would return HTTP 429 response to try to slow down the producer.

Is there a way to limit the concurrency for a given Google Cloud functions the way it is possible to do it using AWS?

like image 936
simon Avatar asked Jan 29 '23 17:01

simon


1 Answers

This functionality is not available for Google Cloud Functions. Instead, since you are asking to handle the pace at which the system will open concurrent tasks, Task Queues is the solution.

Push queues dispatch requests at a reliable, steady rate. They guarantee reliable task execution. Because you can control the rate at which tasks are sent from the queue, you can control the workers' scaling behavior and hence your costs.

In your case, you can control the rate at which the downstream consumer service is called.

like image 164
Tudormi Avatar answered Feb 05 '23 16:02

Tudormi