Skip to content

Google Integrations

Google integration uses a provider-agnostic OAuth system:

  • oauth_connections — Stores tokens per (teacherId, provider, providerAccountId)
  • integration_settings — Stores typed JSONB config per (teacherId, integrationType)

Integration types: calendar_read, calendar_write, drive, meet

Use ConnectionService methods — never read/write tokens directly from the teachers table.

The Slot Engine uses Google Calendar’s freebusy.query API to check teacher availability:

  1. Fetch selected calendars from integration_settings (calendar_read config)
  2. Query FreeBusy API for the date range
  3. Merge busy blocks with DB sessions
  4. Remove overlapping slots

When sessions are confirmed, calendar events are created/updated:

Session confirmed → Create/update Google Calendar event
Session cancelled → Cancel calendar event
Session rescheduled → Update event time

Sync tracked in session_calendar_sync:

  • syncStatus: synced / pending / failed
  • googleCalendarEventId: event reference
  • googleMeetLink: auto-generated Meet link

A cron job (every 5 minutes) retries pending calendar sync operations:

  • Batch of 20 records at a time
  • Skips if google-calendar circuit breaker is open
  • Automatic retry with backoff

Teachers can add Drive files as resources via the file picker:

  1. Teacher opens Drive file picker
  2. Selects files to import as resources
  3. Files tracked in teacher_resources (provider: ‘drive’)

When Drive resources are linked to a session, files are automatically copied to student folders:

1. Resource linked to session
2. DriveCopyService queues BullMQ job
3. Worker copies file to student's folder (students.driveFolderId)
4. Progress tracked in drive_file_copies table
Status: pending → copying → copied / failed

Daily cron (3 AM) verifies Drive file integrity:

  • Checks if files still exist in Drive
  • Marks trashed/deleted files
  • Reports inconsistencies

Both Calendar and Drive API calls are protected by circuit breakers:

ServiceFailure ThresholdWindowRecovery
Google Calendar5 failures60s30s
Google Drive5 failures60s60s

Only infrastructure errors (429, 5xx, timeouts) trip the circuit.

Calendar fallback: Sets syncStatus='pending', session creation never fails. Calendar-sync cron retries later.

Drive fallback: Workers skip and retry later via BullMQ DelayedError.

Redis-backed sliding-window rate limiting at two levels:

ServicePer-TeacherGlobal
Google Calendar10 req/10s400/100s
Google Drive5 req/10s10,000/60s

Execution order: Circuit Breaker → Rate Limiter → Token refresh → API call → 429 Retry