Skip to content

feat: add database connection pooling configuration and connection health checks #164

@BigBen-7

Description

@BigBen-7

Description

get_engine() in src/analytics/models.py and _pg_engine() in multiple files each call create_engine() without configuring connection pool settings. Under load, each analytics write opens a new connection and the pool grows unboundedly. Postgres has a default max_connections=100 — a spike in QR validations can exhaust all connections.

Requirements & context

  • Centralise all engine creation into a single src/db.py module with a module-level engine singleton
  • Configure the pool: pool_size=5, max_overflow=10, pool_timeout=30, pool_recycle=1800
  • Add POOL_SIZE and POOL_MAX_OVERFLOW env vars to Settings with the above defaults
  • Replace all create_engine() / get_engine() / _pg_engine() calls across the codebase to use the singleton
  • Add GET /health/db that runs SELECT 1 and returns pool stats: { "pool_size", "checked_in", "checked_out", "overflow" }

Suggested execution

git checkout -b feat/db-connection-pooling
  • Create src/db.py
  • Update src/analytics/models.py, src/etl/__init__.py, src/report_service.py
  • Add /health/db route
  • Write tests

Guidelines

  • PR must include: Closes #[issue_id]
  • Timeframe: 72 hours

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programenhancementNew feature or improvementinfrastructureInfrastructure and DevOps

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions