Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multi-Thread Firebase function

So I am developing a Firebase function that accepts requests from users and updates few nodes under a branch these users are listening to.

My issue is if the function receives two client requests at the same time, that triggers two functions to execute and update the data at the same time.

I know this is typically solved by a transaction, but my updates are done on various nodes not only one value (i.e counter).

In a traditional multi-threading programming, this problems is solved by locking the code from executing so it can only be executed by one thread, where the next one resumes when the current one finishes.

Is this an option in Firebase Functions? If so, how can it be done?

like image 423
masood elsad Avatar asked Jun 13 '26 22:06

masood elsad


1 Answers

There is currently no threading in Cloud Functions in any environment, both node and python included. You should not be depending on process level locking in Cloud Function - use a database transaction to ensure that updates are atomic and consistent. Each of your function invocations is going to be completely isolated from each other.

like image 85
Doug Stevenson Avatar answered Jun 16 '26 10:06

Doug Stevenson