I have two cloud functions that potentially change the same documents.
How do I avoid a potential race condition and ensure that one of the cloud functions finishes before the other one starts?
Thank you in advance.
There is no way to guarantee ordering of Cloud Function invocations.
This means that you will have to solve the problem in your implementation. It's impossible to say how to precisely do that for you use-case without seeing an MCVE, but it'll typically involve one of more database transactions.
Also see: