Skip to content

feat(common): implement LRU connection cache and circuit breakers - #370

Merged
yash-pouranik merged 2 commits into
mainfrom
feature/lru-circuit-breaker
Jul 30, 2026
Merged

feat(common): implement LRU connection cache and circuit breakers#370
yash-pouranik merged 2 commits into
mainfrom
feature/lru-circuit-breaker

Conversation

@yash-pouranik

@yash-pouranik yash-pouranik commented Jul 30, 2026

Copy link
Copy Markdown
Member

Implemented LRU Cache for Database Connection Caching.

Summary by CodeRabbit

  • New Features
    • Added automatic recovery protection for repeated connection failures, temporarily blocking requests when a service is unavailable and retrying later.
    • Added automatic cleanup of inactive database and storage connections when capacity limits are reached.
    • Improved connection tracking by retaining recently used connections and removing older entries as needed.

@vercel

vercel Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

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

Project Deployment Actions Updated (UTC)
ur-backend-web-dashboard Ready Ready Preview Jul 30, 2026 9:15pm
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
urbackend Skipped Skipped Jul 30, 2026 9:15pm

@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@yash-pouranik, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 43 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 77514940-fe7e-4336-a128-0afaad4f231f

📥 Commits

Reviewing files that changed from the base of the PR and between b17b830 and 4474f70.

📒 Files selected for processing (2)
  • packages/common/src/utils/connection.manager.js
  • packages/common/src/utils/registry.js
📝 Walkthrough

Walkthrough

Changes

Connection resource resilience

Layer / File(s) Summary
Bounded connection registries
packages/common/src/utils/registry.js
Adds LruConnectionMap, bounds connection and storage registries, and closes or destroys evicted resources.
Circuit-breaker connection flow
packages/common/src/utils/connection.manager.js, packages/common/src/utils/registry.js
Adds per-project breaker state, fast-fails open circuits with 503, and records connection successes and failures.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: nitin-kumar-yadav1307

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant getConnection
  participant circuitBreakers
  participant registry
  participant Database
  Client->>getConnection: request project connection
  getConnection->>circuitBreakers: check breaker state
  circuitBreakers-->>getConnection: allow or return 503
  getConnection->>registry: read or create cached connection
  getConnection->>Database: establish connection
  Database-->>getConnection: success or failure
  getConnection->>circuitBreakers: reset or record failure
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: LRU connection caching plus circuit breakers.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/lru-circuit-breaker

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

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/common/src/utils/connection.manager.js`:
- Around line 37-40: Update the circuit-breaker transition in the half-open
branch to synchronously mark a probe as in flight before allowing the retry, and
reject concurrent callers with 503 while that marker is set. Ensure the marker
is cleared only by the probe’s success or failure handling, using the relevant
connection-manager callback paths, rather than clearing openUntil alone.

In `@packages/common/src/utils/registry.js`:
- Around line 70-71: Replace the unbounded circuitBreakers Map with a capped or
TTL-backed registry so entries for inactive projects are evicted while active
breaker state remains available. Update the registry access logic that uses
circuitBreakers to enforce the chosen size or expiration policy without changing
circuit-breaker behavior.
- Around line 55-59: Prevent stale asynchronous connection events from removing
or affecting replacement entries. In packages/common/src/utils/registry.js lines
55-59, expose a deleteIfCurrent(key, connection) operation that removes an entry
only when its value matches the supplied connection. In
packages/common/src/utils/connection.manager.js lines 131-145, update lifecycle
handlers to use this identity-checked removal and record breaker failures only
when removal succeeds; ignore events from evicted or superseded connections.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: a78a9a65-3c57-4c74-8d36-ab290b85aa68

📥 Commits

Reviewing files that changed from the base of the PR and between 2700b3b and b17b830.

📒 Files selected for processing (2)
  • packages/common/src/utils/connection.manager.js
  • packages/common/src/utils/registry.js

Comment thread packages/common/src/utils/connection.manager.js Outdated
Comment thread packages/common/src/utils/registry.js
Comment thread packages/common/src/utils/registry.js Outdated
@yash-pouranik
yash-pouranik temporarily deployed to feature/lru-circuit-breaker - urBackend-frankfrut PR #370 July 30, 2026 21:14 — with Render Destroyed
@vercel
vercel Bot temporarily deployed to Preview – urbackend July 30, 2026 21:14 Inactive
@yash-pouranik
yash-pouranik merged commit 94c9d71 into main Jul 30, 2026
11 checks passed
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.

1 participant