1
votes

I have an app with tens of thousands of users where every second we are capturing data (location data). For analysis we are trying to allow this data to be queryable to generate reports for the user.

The idea is to pass the data in the Realtime database to Spanner so that I can query the data in SQL format and generate reports based on that. I want to be able to do this from my trigger everytime that I update the realtime database. So data follows this flow:

iOS / Android location data -> writes Firebase Realtime DB -> Function trigger based on write event -> Add to Spanner

Is this possible and if so how do you suggest it being done? I am already using firebase functions to trigger notifications and keep database consistency, but not sure how to connect to spanner. The documentation that I have found is all about Cloud functions and when I do

const Spanner = require('@google-cloud/spanner'); 

I get the "Error: Error parsing triggers: Cannot find module '@google-cloud/spanner'"

My first limitation is: Are firebase functions limited to firebase itself or can I integrate with other cloud tools such as spanner?

Thanks,

Ricardo

2
Are you asking how to Query Data in Firebase or how to add data to Spanner? It's going to be difficult to answer without understanding your Firebase structure, what you are querying for and what's you've tried. Please take a moment and review How do I ask a good question? and How to create a Minimal, Complete, and Verifiable exampleJay
Thanks. I have updated the description to reflect your query. Thank you for taking the time.user2091936

2 Answers

2
votes

I don't have experience with Realtime Database, PubSub and Functions, but I'm also interested :)

I imagine 2 steps: [1] Firestore triggers can publish message to PubSub, and [2] Functions can subscribe and handle PubSub events which interact with Spanner.

1
votes

The error means you haven't (correctly) installed the Cloud Spanner client library. To fix this, in your functions folder run:

npm install @google-cloud/spanner

Unless you actually need the data in RTDB, you can avoid that step entirely and call a Cloud Function directly: See HTTP Functions.

There is a handy 'How-to Guide' on writing a Cloud Function for interacting with Cloud Spanner in the documentation, just modify it for put instead of get: See Using Cloud Spanner with Cloud Functions