fix(db): bound the Lambda connection pool + DB circuit breaker#38
Merged
Conversation
The Lambda DB path handed PrismaPg a connection string with ?connection_limit=1, which @prisma/adapter-pg ignores, so each warm execution environment's pool used the pg default max:10. Under a burst of signups (or a pre-token cache-miss storm) the Lambda fleet could exhaust RDS max_connections and make Postgres reject connections from every client. Fix: construct an explicit pg.Pool({max:1, connectionTimeoutMillis, idleTimeoutMillis}) and pass it to PrismaPg so per-Lambda connection count is deterministic (env knobs LAMBDA_DATABASE_POOL_MAX / LAMBDA_DATABASE_CONNECT_TIMEOUT_MS); add a LAMBDA_DATABASE_PROXY_HOST override to route through an RDS Proxy when provisioned; add a per-environment circuit breaker (withLambdaDbBreaker over DatabaseCircuitBreaker) wired into pre-token (loadFromRds) and post-confirmation (provisioning transaction) so a saturated DB fails fast instead of being retried; and emit a pre-token cache_miss event for a miss-rate metric.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…ening Cuts 0.10.8 carrying the Lambda DB pool cap (max:1), RDS Proxy host override, and the Lambda circuit breaker from this PR. (0.10.7 was the generic entity-feed release.) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
7354d00 to
3bc9f07
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
The Lambda DB path passed
PrismaPga connection string with?connection_limit=1, which@prisma/adapter-pgignores — so each warm execution environment's pool used thepgdefaultmax: 10. Under a burst of signups (or apre-tokencache-miss storm) the Lambda fleet could exhaust RDSmax_connectionsand make Postgres reject connections from every client — a global outage, not just failed signups.Changes
lambda-prisma: construct an explicitpg.Pool({ max: 1, connectionTimeoutMillis, idleTimeoutMillis })and pass it toPrismaPg, so per-Lambda connection count is deterministic (= concurrency, not concurrency × 10). Env-configurable:LAMBDA_DATABASE_POOL_MAX(default 1),LAMBDA_DATABASE_CONNECT_TIMEOUT_MS(default 2000).LAMBDA_DATABASE_PROXY_HOSToverride so handlers route through an RDS Proxy endpoint when one is provisioned (falls back to the direct instance — default deployment unchanged).withLambdaDbBreaker, over the existingDatabaseCircuitBreaker) wired intopre-token(loadFromRds) andpost-confirmation(provisioning transaction) so a saturated DB fails fast instead of being retried into the incident.pre-token: emit acache_missevent so a miss-rate metric can be derived.Tests
test/unit/lambda/lambda-prisma.test.ts— 7/7 passing (poolmax === 1, connect timeout, proxy-host override, client caching, breaker trip + fail-fast).tsctype-clean for the changed files (the lone pre-existingextensions.tsbuild error is unrelated — present onmainwithout this change).🤖 Generated with Claude Code