CA
feat: outlook cache
calcom/cal.com#21072

What does this PR do?

  • Fixes #21050 /claim #21050

This PR implements the functionality to -

  • Subscribe for notifications of - create, update or delete events in Microsoft Outlook Calendars (These calendars are pre-connected by team members with their Cal.com accounts, and are mapped to the cal.com events)
  • Receive notifications through a web-hook
  • Validates & filters these notifications and computes the set of outlook calendars (having unique externalIDs) for which the calendar-cache needs invalidation( or update)
  • fetchAvailabilityAndSetCache() is called for above outlook calendars to update the calendar-cache.
  • watch and unwatch functionality is implemented through Microsoft Graph APIs /subscribe , so that the existing cron job can start to subscribe or unsubscribe based on conditions (to avoid duplicate subscriptions).
  • With the calendar-cache available for outlook calendars ,the latest availabilities are shown in real time on public event page with low latency as Graph APIs are not called every time.

Key points: Visit the team public page with cal.cache query parameter set to true, to see the Cache effect or see [Cache Hit] in logs for office365_calendar. Example : http://localhost:3000/team/devs/teamevent?overlayCalendar=true&layout=month_view&cal.cache=true

In this PR, the startWatchingCalendarInMicrosoft() calls /subscription endpoint targeting specific calendars. This avoids subscribing to overly broad resources (e.g., me/events for all calendar events). Instead, target specific calendars or folders (e.g., me/calendars/{calendar_id}/events) to reduce notification volume. Screenshot 2025-05-04 at 11 02 29 PM

Next Steps or Improvements for scaling Given the volume of usage, if we have very high number of teams, team members, team events, simultaneously updating events in outlook - the volume of subscriptions received by the web-hook can be overwhelming even with load balancers.

We can consider Asynchronous Processing: Process notifications asynchronously to avoid blocking the webhook endpoint. For example, queue incoming notifications (using a cloud message queuing system like AWS SQS or RabbitMQ or Azure Queue Storage) and process them in the background with worker nodes. This ensures the endpoint remains responsive under high load.

Also we can consider using Azure Event Hubs or Azure Event Grid as alternative delivery channels. These services are designed for high-throughput event streaming and can buffer notifications, reducing the load on our application.

Video Demo

This demo shows - on creation of an event in outlook calendar the CalendarCache is updated through the webhook Cron job was triggered manually through api - http://localhost:3000/api/calendar-cache/cron?apiKey=

https://www.loom.com/share/468bf851a93d49849b2dab27fe751efd?sid=458f9244-e4fe-4632-897d-b93835535ff6

The second demo shows the effect of caching on public team event page-

https://www.loom.com/share/567c3d5af03e478e97a44299e9bcc8da?sid=9254a7e4-a28b-4a49-b17e-2890489fcf84

Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected).
  • I have updated the developer docs in /docs if this PR makes changes that would require a documentation change. If N/A, write N/A here and check the checkbox.
  • I confirm automated tests are in place that prove my fix is effective or that my feature works.

How should this be tested?

  • Are there environment variables that should be set? MICROSOFT_WEBHOOK_TOKEN - This token is sent with subscription requests through /subscriptions Graph API. The notifications received by webhook are verified with this token
  • What are the minimal test data to have? Enable calendar-cache feature flag for the team. Create a team event with hosts having their outlook calendars connected
  • What is expected (happy path) to have (input and output)? At any given point of time Calendar-Cache in cal.com has the latest busy slots in sync with changes in outlook calendar busy times or events. Update or create or delete event in Microsoft outlook calendar , there should be instant update in cal.com calendar-cache On visiting the team event public page with &cal.cahce=true, latest available slots are displayed with low latency
  • Any other important info that could help to test that PR To test locally use port forwarding providers

Summary by mrge

Added caching and webhook support for Outlook (Office365) calendar availability to improve performance and enable real-time updates.

  • New Features
    • Implemented webhook endpoint to receive Outlook calendar change notifications and refresh cache.
    • Added cache layer for Outlook calendar availability queries.
    • Updated database schema to store Outlook subscription info.

Claim

Total prize pool $500
Total paid $0
Status Pending
Submitted May 02, 2025
Last updated May 02, 2025

Contributors

VI

Vijay

@vijayraghav-io

100%

Sponsors

CA

Cal.com, Inc.

@cal

$500