Problem Statement
quantara/web_app/db/database.py:24 creates the SQLAlchemy engine with create_engine(SQLALCHEMY_DATABASE_URL) using all defaults — no pool_size, max_overflow, pool_recycle, or pool_pre_ping configured. Under load, connections may exhaust or become stale.
Evidence
# quantara/web_app/db/database.py:24
engine = create_engine(SQLALCHEMY_DATABASE_URL)
# No pool_size, max_overflow, pool_recycle, pool_pre_ping configured.
Note: DBConnector.__init__() in crud/base.py:23 creates its own engine too — another unconfigured pool.
Impact
Medium — connection exhaustion under load. Default pool_size is 5, which is insufficient for a web application under concurrent requests. Idle connections not recycled may become stale (PostgreSQL closes idle connections after timeout). Stale connections cause "server closed the connection unexpectedly" errors.
Proposed Solution
Configure engine with: pool_size=10, max_overflow=20, pool_recycle=3600 (1 hour), pool_pre_ping=True. Make pool_size configurable via environment variable.
Acceptance Criteria
File Map
quantara/web_app/db/database.py:24 — configure pool settings
quantara/web_app/db/crud/base.py:23 — configure pool settings in DBConnector
Testing Strategy
- Integration: Run concurrent requests, verify no connection exhaustion errors
Security Considerations
No direct security impact. pool_pre_ping=True prevents use of stale connections.
Definition of Done
Labels: performance
Priority: Medium
Difficulty: Beginner
Estimated Effort: 0.5h
Problem Statement
quantara/web_app/db/database.py:24creates the SQLAlchemy engine withcreate_engine(SQLALCHEMY_DATABASE_URL)using all defaults — nopool_size,max_overflow,pool_recycle, orpool_pre_pingconfigured. Under load, connections may exhaust or become stale.Evidence
Note:
DBConnector.__init__()incrud/base.py:23creates its own engine too — another unconfigured pool.Impact
Medium — connection exhaustion under load. Default pool_size is 5, which is insufficient for a web application under concurrent requests. Idle connections not recycled may become stale (PostgreSQL closes idle connections after timeout). Stale connections cause "server closed the connection unexpectedly" errors.
Proposed Solution
Configure engine with:
pool_size=10,max_overflow=20,pool_recycle=3600(1 hour),pool_pre_ping=True. Makepool_sizeconfigurable via environment variable.Acceptance Criteria
create_engine()configured withpool_size,max_overflow,pool_recycle,pool_pre_pingpool_sizeconfigurable viaDB_POOL_SIZEenv var (default 10)database.pyandcrud/base.py) configuredFile Map
quantara/web_app/db/database.py:24— configure pool settingsquantara/web_app/db/crud/base.py:23— configure pool settings in DBConnectorTesting Strategy
Security Considerations
No direct security impact.
pool_pre_ping=Trueprevents use of stale connections.Definition of Done
Labels: performance
Priority: Medium
Difficulty: Beginner
Estimated Effort: 0.5h