Jump to Content
Databases

Firestore adds three new trigger destinations through an integration with Eventarc

May 22, 2023
Hansi Mou

Software Engineer, Firestore

Minh Nguyen

Senior Product Manager Lead, Firestore

Firestore triggers, commonly referred to in industry as change data capture, is a popular feature that lets you trigger custom compute logic in response to Firestore document changes. This feature is commonly utilized to replicate Firestore document changes to third-party services, notify them of changes to Firestore documents, and archive deleted Firestore documents in a different storage system. 

To support a broader set of Firestore triggering destinations, we’re excited to share a new integration with Eventarc. Through this integration, we’re adding support for three new Eventarc supported triggering destinations: Cloud Run, Google Kubernetes Engine (GKE), and Cloud Functions (2nd gen). The integration uses the CloudEvents format, which is a unified specification for describing event data. Support for these new triggering destinations is in addition to the existing Firestore triggering support for Cloud Functions (1st gen). 

Example walkthrough

Let’s say that you’re building a chat messaging system on Firestore, and you want newly created chat messages written to Firestore to cause an invocation of another process elsewhere. Your data model might be similar to the example below:

https://storage.googleapis.com/gweb-cloudblog-publish/images/Firestore_is_now_integrated_with_Eventarc-.max-1400x1400.jpg

To start, you’ll need to set up a Firestore trigger. You can choose among destinations like Cloud Functions (2nd gen), Cloud Run, and Google Kubernetes Engine

In this case, let’s say we have a Cloud Run service named hello that exposes an HTTP endpoint. The sample container provided by Cloud Run can serve this purpose. By navigating to the triggers tab in Cloud Run, we can create a new trigger which invokes this endpoint anytime a document is created.

https://storage.googleapis.com/gweb-cloudblog-publish/images/2_w8MtkaR.max-1300x1300.jpg

When you configure a new trigger, you can also apply filters. The example below only triggers when a document is created under the Chats collection in the (default) database:

https://storage.googleapis.com/gweb-cloudblog-publish/images/3_IowbmLI.max-1300x1300.jpg

That's it! Now when documents are created in the Chats collection, you’ll see that these documents are passed to the configured Cloud Run service named hello almost immediately!

For Firebase users, you can setup and manage Cloud Functions (2nd gen) using the Firebase CLI. You can also use the Firebase emulator suite to test everything locally before deploying to production. 

Next steps

For more information on how to set up and configure Firestore triggers, simply check out our documentation.


Thanks to Juan Lara, Senior Technical Writer, Firestore, for their contributions to this blog post.

Posted in