Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Event type: google.cloud.storage.object.v1.finalized is triggered many times

My Cloud function(V1) is triggered by files uploaded to a storage bucket (i.e. event trigger "google.cloud.storage.object.v1.finalized" ) and it works fine; however after upgrading to Cloud Run Function V2, it appears it's trigged many times for the same uploaded file.  Is this a Cloud Run Function V2 (container based) issue or is this a storage bucket messaging issue?

0 1 1,417
1 REPLY 1

Hi @jasonwang2,

Welcome to Google Cloud Community!

The issue is that Cloud Run Function V2's horizontal scaling can cause multiple instances of a function to process the same Cloud Storage Pub/Sub message, leading to duplicate function executions. The solution isn't to change message delivery, but to make the function idempotent. This involves using a unique identifier (e.g., object name and timestamp) to check if the file has already been processed before acting. Atomic operations should also be used for multiple-step processes. For enhanced reliability and scalability, using Eventarc with its built-in retry and deduplication features is recommended.

I hope the above information is helpful.

Top Solution Authors