Skip to content

Implement database connection multiplexing for serverless environments #600

Description

@Smartdevs17

Context

Serverless functions (webhook handlers, auth callbacks, scheduled jobs) create a new database connection on each invocation, exhausting connection limits during traffic spikes.

Current Limitation/Problem

During traffic spikes, serverless functions open 100+ simultaneous database connections, hitting the 200-connection limit and causing connection refused errors.

Expected Outcome

Database connection multiplexing via PgBouncer (or RDS Proxy), with transaction-level pooling and automatic scaling for serverless workloads.

Acceptance Criteria

  • PgBouncer deployment as sidecar container or RDS Proxy configuration
  • Transaction pooling mode: connections reused across function invocations
  • Prepared statement support: PgBouncer in prepared-statement mode with statement cache
  • Authentication: IAM-based (AWS RDS) or SCRAM-256 (self-hosted)
  • Connection limits: max 50 pooled connections serving 500+ concurrent functions
  • Lambda handler adaptation: db.release() called after each invocation via finally block
  • Edge case: connection leak detection (abandoned connection >30s, log and force-close)

Technical Scope

  • infra/terraform/ - PgBouncer or RDS Proxy resource provisioning
  • backend/shared/db/ - serverless connection pool adapter
  • backend/serverless/ - Lambda function database configuration
  • docker-compose.yml - local PgBouncer service for development
  • backend/monitoring/ - connection pool metrics and leak detection

Metadata

Metadata

Assignees

Labels

200-points200 point issueStellar WaveIssues in the Stellar wave programdrips-waveIssues in the Drips Wave programhighHigh complexity issue

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions