Two-way sync sounds simple. Things added in your app appear in the user's calendar. Things added in the calendar appear in your app. Then you build it and every event shows up twice.

I hit this on Chronicler, an AI assistant that keeps your notes and to-dos. This is the problem and the fix.

The setup

In Chronicler, every to-do the user added was also added to their Google Calendar. That was direction one.

Direction two: the app listened for changes from the calendar. If the user added an event straight into Google Calendar, a webhook told the app, and the app pulled the event in.

The loop

The calendar does not know who created an event. It reports every change.

  1. The user adds a to-do in the app.
  2. The app creates the event in the calendar.
  3. The calendar sends a webhook: there is a new event.
  4. The app sees a new event and adds it as a to-do.

Now the user has the same to-do twice. If step 4 writes to the calendar again, it does not stop at twice.

The fix

When the app created an event, it tagged that event as created by Chronicler. The tag was a hidden property on the event itself. The user never sees it, and it travels with the event wherever the event goes.

When a webhook came in, the app checked for the tag first:

  • Tag present: the app made this event itself. It already has it. Skip.
  • No tag: the user added this directly in their calendar. Sync it in.

One check, and both directions keep working. Events from the app are not added twice, and events added in the calendar still arrive.

Edits and deletes

New events are only a third of the problem. The same echo happens when the app edits an event or deletes one: the calendar reports the change back, and a careless sync applies it a second time or fights with itself.

The same tag handled those too. If the change was on an event the app owned and the app had just made that change, there was nothing to do. If the user had edited or deleted the event in their calendar, the change was real and the to-do was updated to match.

Why I prefer a marker to guessing

The tempting alternative is to compare incoming events to what you already have by title and time. That breaks the first time a user has two real meetings with the same name, or edits a title.

A marker does not guess. The event itself says where it came from.

If you are building this

  • Decide where the marker lives before writing any sync code. Google Calendar events can carry private properties that only your app sees, which is what I used.
  • Set the marker in the same request that creates the event. If it is added in a second step, the webhook can arrive before the marker does.
  • Check the marker on every kind of change the webhook reports, not only new events.
  • Test with two accounts and real webhooks. This bug does not show up when you test one direction at a time.

I'm Hassan Iqbal, a full-stack and AI developer. I build AI agents and full products for early-stage founders. This post first appeared on my site. More of my work: hassaniqbal.dev/full-stack.