Configure SQLAlchemy connection pool for production load #14

Open
opened 2026-04-20 09:35:52 +00:00 by sharang · 0 comments
Owner

Problem

classroom_engine/database.py creates the SQLAlchemy engine with default pool settings:

  • Default pool_size=5 — exhausted under moderate load (10+ concurrent requests)
  • No pool_timeout — requests block indefinitely waiting for a connection
  • No pool_pre_ping=True — stale connections after DB restart cause errors

Required Actions

  1. Update create_engine() call with production-safe settings:
create_engine(
    DATABASE_URL,
    pool_size=20,
    max_overflow=40,
    pool_timeout=30,
    pool_pre_ping=True,
    pool_recycle=1800,
)
  1. Expose pool settings as env vars so they can be tuned without a code deploy
  2. Add pool exhaustion metric: log a warning when the pool queue grows > 10

Acceptance Criteria

  • App handles 50 concurrent requests without QueuePool limit exceeded errors
  • Stale connection after DB restart resolves automatically (pre_ping)
## Problem `classroom_engine/database.py` creates the SQLAlchemy engine with default pool settings: - Default `pool_size=5` — exhausted under moderate load (10+ concurrent requests) - No `pool_timeout` — requests block indefinitely waiting for a connection - No `pool_pre_ping=True` — stale connections after DB restart cause errors ## Required Actions 1. Update `create_engine()` call with production-safe settings: ```python create_engine( DATABASE_URL, pool_size=20, max_overflow=40, pool_timeout=30, pool_pre_ping=True, pool_recycle=1800, ) ``` 2. Expose pool settings as env vars so they can be tuned without a code deploy 3. Add pool exhaustion metric: log a warning when the pool queue grows > 10 ## Acceptance Criteria - App handles 50 concurrent requests without `QueuePool limit exceeded` errors - Stale connection after DB restart resolves automatically (pre_ping)
sharang added this to the M2: Data Integrity & Reliability milestone 2026-04-20 09:35:52 +00:00
sharang added the configreliabilityseverity: medium labels 2026-04-20 09:35:52 +00:00
Sign in to join this conversation.