Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 13, 2025

Problem

The application's Google Calendar event creation was vulnerable to rate limit failures from the Google Calendar API. When users hit rate limits (HTTP 429 or Google-specific rate limit errors like rateLimitExceeded), the meeting creation would fail immediately without any retry mechanism, leading to a poor user experience.

Solution

This PR implements a robust exponential backoff retry utility that gracefully handles Google API rate limits:

🆕 New Features

Reusable Backoff Utility (src/lib/backoff.ts)

  • Generic withExponentialBackoff() function that can wrap any async function
  • Specialized withCalendarRetry() with Calendar API-optimized defaults
  • Comprehensive rate limit error detection for various Google API error formats
  • Configurable retry parameters (max retries, delays, jitter)

Rate Limit Detection

  • HTTP 429 status codes
  • Google API specific error reasons: rateLimitExceeded, userRateLimitExceeded, quotaExceeded, dailyLimitExceeded
  • Text-based detection for "rate limit", "quota exceeded", "too many requests"

Exponential Backoff Strategy

  • Base delay: 1000ms (configurable)
  • Exponential growth: baseDelay * 2^attempt
  • Maximum delay cap: 30000ms (configurable)
  • Jitter support to prevent thundering herd effect
  • Up to 5 retry attempts for Calendar operations (configurable)

🔧 Implementation

Enhanced Google Meet Creation

// Before: Direct API call (vulnerable to rate limits)
const event = await calendar.events.insert(eventParams);

// After: Retry-wrapped API call
const createCalendarEvent = withCalendarRetry(() => calendar.events.insert(eventParams));
const event = await createCalendarEvent();

Usage Examples

// Basic usage
const retryableFunction = withExponentialBackoff(apiCall, {
  maxRetries: 3,
  baseDelay: 1000
});

// Calendar-specific (recommended for Google Calendar)
const createEvent = withCalendarRetry(() => calendar.events.insert(params));

// Other Google APIs
const sendEmail = withExponentialBackoff(() => gmail.users.messages.send(params));

✅ Benefits

  • Improved Reliability: Google Meet creation now handles rate limits gracefully
  • Better User Experience: Transient rate limit errors are automatically resolved
  • Zero Breaking Changes: Existing business logic and API contracts unchanged
  • Reusable Design: Can be applied to other Google API calls (Gmail, Drive, etc.)
  • Production Ready: Includes proper logging, error handling, and TypeScript support

🧪 Testing

  • ✅ All ESLint rules pass
  • ✅ TypeScript compilation successful
  • ✅ Rate limit error detection verified
  • ✅ Exponential backoff calculation tested
  • ✅ No regression in existing functionality

The retry logic only activates for rate limit errors - all other errors (authentication, validation, etc.) continue to fail fast as expected.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • fonts.googleapis.com
    • Triggering command: /usr/local/bin/node /home/REDACTED/work/schedulo/schedulo/node_modules/next/dist/compiled/jest-worker/processChild.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

This pull request was created as a result of the following prompt from Copilot chat.

Implement exponential backoff retry logic for Google API rate limits in the repository. Specifically:

  1. Create a utility function (e.g., in src/lib/backoff.ts) that wraps an async function and retries it with exponential backoff if a rate-limit error is encountered (HTTP 429 or Google API rateLimitExceeded/userRateLimitExceeded error reasons).
  2. Refactor src/app/api/meet/route.ts to use this retry logic when creating Google Calendar events (calendar.events.insert), so rate limit errors are handled gracefully.
  3. Add clear comments and make the backoff utility reusable for other Google API calls.

Acceptance Criteria:

  • Google Calendar event creation is retried up to a maximum number of attempts with increasing delay if rate limit errors occur.
  • No change to existing business logic or API contract unless related to error handling for rate limits.
  • The utility is documented and placed in src/lib/backoff.ts.

💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

@vercel
Copy link

vercel bot commented Sep 13, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
schedulo Ready Ready Preview Comment Sep 13, 2025 11:09am
schedulo-app Ready Ready Preview Comment Sep 13, 2025 11:09am
schedulo-w4vm Canceled Canceled Sep 13, 2025 11:09am

@marvellousz marvellousz marked this pull request as ready for review September 13, 2025 11:00
@marvellousz marvellousz merged commit b815641 into main Sep 13, 2025
3 of 5 checks passed
Copilot AI changed the title [WIP] Implement exponential backoff for Google API rate limits Implement exponential backoff retry logic for Google API rate limits Sep 13, 2025
Copilot AI requested a review from marvellousz September 13, 2025 11:08
@vercel vercel bot temporarily deployed to Preview – schedulo-w4vm September 13, 2025 11:09 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants