Hello Google Cloud community,
I’m developing a multi-tenant SaaS application using Firebase Authentication, Cloud Firestore and Google Cloud Functions (Node.js 20).
We are preparing a security migration of our account onboarding system. Before deploying the changes, we need to establish a reliable cutover point that prevents older Cloud Function executions from committing privileged Firestore writes.
Our current architecture
We have three existing callable functions:
-
resolveMyEnterprise— can provision an enterprise and its owner membership. -
createWorkerInvitation— creates worker invitations. -
acceptWorkerInvitation— accepts invitations and provisions worker relationships.
These functions currently use the same runtime service account as other business functions.
Our new implementation introduces explicit tenant verification, server-side authorization, transactional idempotency and a Firestore-based onboarding barrier.
The problem
We reproduced three race conditions using the Firestore Emulator:
-
An older Cloud Function starts a Firestore transaction.
-
The new onboarding barrier is set to CLOSED and its transaction commits.
-
The older function continues and successfully commits a privileged write after the barrier was closed.
The old functions do not read the new barrier document, so the barrier cannot invalidate their transactions.
We understand that:
-
Changing IAM permissions may prevent new invocations but does not necessarily terminate requests already running.
-
Deploying a new function revision does not automatically prove that every previous execution has finished.
-
Firestore Security Rules do not restrict Admin SDK writes.
-
Revoking permissions from the shared service account could affect unrelated production functions.
Our questions
-
Is there an officially supported way to stop admission and safely drain or terminate all in-flight executions of specific Cloud Functions without affecting other functions sharing the same service account?
-
Does replacing, disabling or deleting a function provide any documented guarantee regarding already-running executions and Firestore transactions?
-
How can we establish a verifiable cutover point after which no legacy execution can commit a privileged Firestore write?
-
Can Cloud Run revision controls provide a stronger solution for second-generation functions? How should already-running requests be handled?
-
Would migrating the replacement handlers to dedicated service accounts help, given that existing instances still use the shared identity?
-
If strict quiescence cannot be guaranteed by the platform, what migration pattern would you recommend for this situation?
We are willing to temporarily disable new registrations and worker invitations during maintenance. Existing users and unrelated business functionality should remain available.
We have not deployed the migration because our local concurrency tests demonstrate that our current cutover strategy is insufficient.
We are looking for a documented and operationally verifiable solution, not merely a fixed waiting period or the absence of requests in logs.
The exact Cloud Functions generation (1st or 2nd generation) is still being verified.
Any guidance or official documentation would be greatly appreciated.
Thank you!