Skip to content

Comments

feat: implement Redis-based caching for getSchedule endpoint#22608

Closed
hbjORbj wants to merge 4 commits intomainfrom
devin/redis-schedule-caching-1752786274
Closed

feat: implement Redis-based caching for getSchedule endpoint#22608
hbjORbj wants to merge 4 commits intomainfrom
devin/redis-schedule-caching-1752786274

Conversation

@hbjORbj
Copy link
Contributor

@hbjORbj hbjORbj commented Jul 17, 2025

feat: implement Redis-based caching for getSchedule endpoint

Summary

Implements a Redis-based caching strategy for the getScheduleHandler endpoint to mitigate DDoS-like behavior from repeated identical requests. The implementation uses Vercel KV instead of the existing Redis infrastructure as requested.

Key Changes:

  • New VercelKVService (packages/features/redis/VercelKVService.ts): Implements IRedisService interface using @vercel/kv
  • Cache utilities (packages/lib/cache.ts): SHA1-based cache key generation, 10-second TTL, error handling
  • Caching integration in getScheduleHandler: Checks cache before computation, respects existing getShouldServeCache feature flags
  • Cache invalidation hooks in booking creation and schedule updates
  • Dependency addition: @vercel/kv package added to web app

Review & Testing Checklist for Human

  • 🚨 CRITICAL: End-to-end testing required - This implementation was NOT tested locally due to environment issues. Must verify the complete caching flow works in a real environment with Vercel KV configured.
  • Verify Vercel KV environment configuration - Ensure KV_URL, KV_REST_API_URL, and KV_REST_API_TOKEN environment variables are properly set up
  • Test cache invalidation scenarios - The current invalidation logic is a placeholder that only logs parameters. Verify this doesn't cause stale cache issues and implement proper invalidation if needed
  • Validate API compatibility - Confirm that Vercel KV's get(), set(), expire(), lpush() methods behave identically to Redis, especially return types and error handling
  • Test feature flag integration - Verify that caching only activates when getShouldServeCache returns true for relevant teams/users

Recommended test plan:

  1. Configure Vercel KV environment variables
  2. Enable relevant feature flags for a test team/user
  3. Make identical schedule requests and verify cache hits via logging
  4. Create a booking and verify cache behavior
  5. Test with Redis unavailable to ensure graceful fallback

Diagram

%%{ init : { "theme" : "default" }}%%
graph TD
    Client[Client Request] --> Handler["getSchedule.handler.ts<br/>(Modified)"]
    Handler --> FeatureFlag["getShouldServeCache<br/>(Existing)"]
    FeatureFlag -->|enabled| Cache["cache.ts<br/>(Modified)"]
    FeatureFlag -->|disabled| Direct[Direct Computation]
    Cache --> VercelKV["VercelKVService<br/>(New)"]
    Cache -->|miss| Compute["availableSlotsService<br/>(Existing)"]
    Compute --> Cache
    
    Booking["handleNewBooking.ts<br/>(Modified)"] --> Invalidate["invalidateScheduleCache"]
    Schedule["updateSchedule.ts<br/>(Modified)"] --> Invalidate
    Invalidate --> VercelKV
    
    subgraph Legend
        L1[Major Edit]:::major-edit
        L2[Minor Edit]:::minor-edit  
        L3[Context/No Edit]:::context
    end
    
    classDef major-edit fill:#90EE90
    classDef minor-edit fill:#87CEEB
    classDef context fill:#FFFFFF
    
    class Handler,Cache,VercelKV,Booking,Schedule major-edit
    class Invalidate minor-edit
    class Client,FeatureFlag,Direct,Compute context
Loading

Notes

  • ⚠️ HIGH RISK: This implementation was not tested locally due to environment setup issues. Manual testing is absolutely critical before merging.
  • Cache invalidation is incomplete: Currently only logs invalidation requests but doesn't actually clear cache keys. This may need enhancement based on testing results.
  • Vercel KV vs Redis: Replaced Redis with Vercel KV as requested, but kept the existing RedisService intact for other use cases.
  • Future enhancement: More sophisticated pattern-based cache invalidation could be implemented later if needed.

Session details: Requested by @hbjORbj
Link to Devin run: https://app.devin.ai/sessions/09b101be4b2c48f4a848e09b37ece640

- Add cache utilities with SHA1-based key generation and 10s TTL
- Integrate caching into getScheduleHandler with feature flag support
- Add cache invalidation on booking creation and schedule updates
- Use existing RedisService infrastructure and getShouldServeCache logic
- Maintain type safety and existing functionality

Co-Authored-By: benny@cal.com <sldisek783@gmail.com>
@vercel
Copy link

vercel bot commented Jul 17, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

2 Skipped Deployments
Name Status Preview Comments Updated (UTC)
cal ⬜️ Ignored (Inspect) Aug 6, 2025 3:44am
cal-eu ⬜️ Ignored (Inspect) Aug 6, 2025 3:44am

@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR that start with 'DevinAI'.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 17, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch devin/redis-schedule-caching-1752786274

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@keithwillcode keithwillcode added core area: core, team members only foundation labels Jul 17, 2025
@delve-auditor
Copy link

delve-auditor bot commented Jul 17, 2025

No security or compliance issues detected. Reviewed everything up to 33c1c57.

Security Overview
  • 🔎 Scanned files: 4 changed file(s)
Detected Code Changes
Change Type Relevant files
Enhancement ► handleNewBooking.ts
    Add cache invalidation for bookings
► cache.ts
    Implement Redis-based caching utilities with TTL
► updateSchedule.ts
    Add cache invalidation for schedule updates
► getSchedule.handler.ts
    Integrate caching into schedule retrieval

Reply to this PR with @delve-auditor followed by a description of what change you want and we'll auto-submit a change to this PR to implement it.

…tation

- Create new VercelKVService implementing IRedisService interface
- Update cache utilities to use VercelKVService instead of RedisService
- Add @vercel/kv dependency to apps/web package.json
- Maintain existing RedisService for other use cases
- Keep same cache functionality with 10s TTL and SHA1 keys

Co-Authored-By: benny@cal.com <sldisek783@gmail.com>
@github-actions
Copy link
Contributor

github-actions bot commented Aug 1, 2025

This PR is being marked as stale due to inactivity.

@github-actions github-actions bot added the Stale label Aug 1, 2025
@socket-security
Copy link

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedclassnames@​2.5.110010010079100
Addedentities@​4.5.010010010081100

View full report

@github-actions github-actions bot removed the Stale label Aug 5, 2025
@hbjORbj hbjORbj marked this pull request as ready for review August 6, 2025 03:44
@hbjORbj hbjORbj requested a review from a team as a code owner August 6, 2025 03:44
@hbjORbj hbjORbj marked this pull request as draft August 6, 2025 03:44
@graphite-app graphite-app bot requested a review from a team August 6, 2025 03:44
@graphite-app
Copy link

graphite-app bot commented Aug 6, 2025

Graphite Automations

"Add consumer team as reviewer" took an action on this PR • (08/06/25)

1 reviewer was added to this PR based on Keith Williams's automation.

@dosubot dosubot bot added bookings area: bookings, availability, timezones, double booking ✨ feature New feature or request labels Aug 6, 2025
@keithwillcode
Copy link
Contributor

This was done in #22787

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bookings area: bookings, availability, timezones, double booking core area: core, team members only ✨ feature New feature or request foundation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants