Google calendar has decent documentation for most of its products and supports most of the libraries, even then, it's confusing enough to take the wrong approach while integrating with google calendar.

When I set out to build calendar integration for one of my products, I had never thought that it would end up becoming so complicated to do things which I had initially thought to be simple.

Product Requirements

During Signup/Login ask for permission to view/edit/create the events in their primary google calendar. Fetch the calendar events(both recurring and 1 time) and show them to the users so that they can add more details to it(specific to the product). Keep in sync with any new events that are created. Sync existing events between the product and the calendar. Updating the correct recurring events in google calendar for any updates done to them in my product.

Remember that, my product required 2-way sync of events.

The Incorrect Approach

During my research, most of the blog posts I read pointed to using the Calendar Events List API and my brain started to work in that direction. I took the following approach which is inefficient and unscalable -

Integrated the Calendar Events List API which got me the event information for all the upcoming events. Saved the ones which matched as per the algorithm of the product If the user performed any update to these events then update the calendar events accordingly(changes to date/time/description) Write a Cron job which runs every 30 minutes to check if any new events were added/existing events changed(biggest blunder) for all the users in the database.

The Correct Approach

Soon, I realised that this was not the most efficient and scalable way to achieve the results I wanted.

I dug deeper into the google documentation to realize that there is a synch API which helps in incremental synch of data and works as a webhook. This is what made complete sense and would fit my requirements perfectly.

I am going to talk about this approach in a new series. Stay Tuned