fix: implement shared Redis-based TTL cache for distributed deployments#5401
Conversation
…ssue JhaSourav07#3574) Replace in-memory TTL cache with Redis-backed distributed cache to prevent data inconsistency across instances. Fixes JhaSourav07#3574
|
@anshul23102 is attempting to deploy a commit to the jhasourav07's projects Team on Vercel. A member of the Team first needs to authorize it. |
GSSoC 2026 ContributionThis PR addresses issue #3574 as part of the GSSoC 2026 program. The implementation solves critical data inconsistency issues in distributed deployments. Key Improvements:
Label Request: Please add the gssoc-approved label upon approval to recognize this GSSoC 2026 contribution. |
Aamod-Dev
left a comment
There was a problem hiding this comment.
Thanks for the contribution. A shared Redis-based TTL cache is a significant architectural enhancement for distributed deployments. Applied labels: \level:advanced\ (architectural core logic), \ ype:performance, \quality:clean.
Aamod-Dev
left a comment
There was a problem hiding this comment.
I noticed the CI checks (Vercel) are currently failing on this branch. Please take a look at the logs and fix the build issues so we can get this merged. (Labels applied previously)
Aamod-Dev
left a comment
There was a problem hiding this comment.
Thanks for implementing the Redis-based distributed TTL cache layer! This is a fantastic architectural step toward supporting horizontally scaled, multi-instance deployments without rate limit fragmentation.
However, I noticed a couple of technical issues that need addressing before we can merge:
- Explicit
anyusage: You are using theanytype forredisClient(private redisClient: any;). Our strict TypeScript and ESLint configuration will fail the build if you use explicitanytypes. Please type this correctly (e.g., using types fromioredisor@upstash/redisdepending on what the deployment provides). - CI Divergence: The CI pipeline will automatically fail due to an unrelated test divergence in
lib/svg/themes.test.tsthat occurred on themainbranch.
Please fix the TypeScript any types, run git pull --rebase origin main to resolve the test divergence, and force push. I'll take another look once that's done!
Labels Applied:
level:advanced: Distributed architecture cache layer.type:performance: Redis TTL implementations.quality:needs-improvement: Contains explicitanytypes.mentor:Aamod007
Aamod-Dev
left a comment
There was a problem hiding this comment.
Thanks for the contribution. I went through the changes and the overall approach looks good.
Aamod-Dev
left a comment
There was a problem hiding this comment.
This PR is currently marked with the \status:blocked\ label. Please resolve the blockers so we can proceed with a full review and approval.
Aamod-Dev
left a comment
There was a problem hiding this comment.
Thanks for the contribution! I went through the changes and have evaluated them according to the rubric.
Aamod-Dev
left a comment
There was a problem hiding this comment.
Please fix the issues that caused the blocked label before this can be approved.
Aamod-Dev
left a comment
There was a problem hiding this comment.
This PR is currently blocked due to a failing CI check or other blocking issues. Please fix the blocking issues so we can proceed with the review and approval process.
Create explicit RedisClient interface for type safety instead of using any type.
✅ Type Safety Issues ResolvedI've fixed the blocking TypeScript errors that were preventing CI checks from passing: Changes Made:
Status:
Suggested Labels:
The CI checks should now pass. Ready for maintainer review and approval. |
📦 Next.js Bundle Size Report (Gzipped Sizes)✨ No significant bundle size changes detected. 📊 Summary of Totals
|
Aamod-Dev
left a comment
There was a problem hiding this comment.
The Redis-backed cache wrapper is promising, but this version is not yet compatible with the rest of the codebase. lib/cache.ts already exposes a different DistributedCache API, so this new lib/distributed-cache.ts class needs either an integration path or a rename/adapter plan. Please wire it into the existing cache usage and add a test that proves get, set, and TTL expiration still behave the same across the current callers.
|
✅ Fixed Redis Cache Integration Resolved the maintainer feedback about API compatibility and naming conflict. Changes Made:
Test Results:All 15 tests pass, verifying:
Commit: The Redis cache is now properly integrated with a clear naming scheme and comprehensive test coverage proving TTL expiration works correctly. Ready for review! 🚀 |
Aamod-Dev
left a comment
There was a problem hiding this comment.
Difficulty: critical – Advanced security/infrastructure feature implementation.
Quality: clean – Production-ready.
Type: feature + security – Critical enhancement.
Excellent work!
|
🎉 Congratulations @anshul23102! Your PR has been successfully merged. 🚀 Thank you for contributing to CommitPulse. Your work helps us build a better tool for the community.
Keep building! 💻✨ |
Summary
Addresses issue #3574 by implementing a Redis-backed distributed cache layer to replace the in-memory cache. This ensures data consistency across multiple instances in serverless and distributed deployments.
Problem
The current in-memory TTL cache (DistributedCache in cache.ts) stores data locally in each instance. In distributed/serverless deployments:
Solution
Implement a Redis-based distributed cache that:
Implementation Details
Key Features:
Configuration:
If not configured, the cache gracefully falls back to in-memory storage.
Impact
Testing
Closes #3574