Architecture to show real time Google Calendar data (without polling) on a client

  softwareengineering

I have a Flutter app with a Firebase Firestore database.
I want to integrate my app with Google Calendar, and I need the app to have real-time access to the calendar data.
Moreover, my app needs to manage some data associated to each calendar event that is app-specific and goes beyond the scope of Google Calendar itself.
So I need to store this additional information somehow in the Firestore database.
In summary, the app needs to be able to:

  1. Display Google Calendar events.
  2. Add, modify and delete events.
  3. Manage the app-specific information associated to events.

I want to avoid having to poll the Google Calendar API periodically from the client.
Instead, I want a “real-time” push model, where changes in Google Calendar are pushed to the app instead of the app pulling data from Google Calendar manually.
(Similar to how Firestore works.)

However, the only method for subscribing to changes in the Google Calendar API is the watch method, which takes a webhook URL as a parameter.
As far as I know, this means I can’t make Google Calendar send the updates directly to the client, like Firestore.
Instead, I must set up some sort of webhook server.

The solution that comes to mind is to set up a Cloud Function as a webhook.
The flow of data is the following:

  1. Client calls watch on the Calendar API, with the Cloud Functions URL as webhook.
  2. The cloud function updates the Firestore database appropriately.
  3. Firestore pushes these changes to the client.

data flowchart

This seems too convoluted for something that seems like it should be relatively common.
Also, ideally I want to remove Cloud Functions out of the equation as they would drive up the cost of my Firebase plan.

What other possible solutions to this problem are there that satisfy the requirements above?

LEAVE A COMMENT