Skip to content

fix: pool DB connections to prevent Supabase client exhaustion#61

Open
madhavcodez wants to merge 1 commit intomainfrom
fix/connection-pooling
Open

fix: pool DB connections to prevent Supabase client exhaustion#61
madhavcodez wants to merge 1 commit intomainfrom
fix/connection-pooling

Conversation

@madhavcodez
Copy link
Copy Markdown
Contributor

What this does

Adds connection pooling to the SQLAlchemy engine so the backend reuses a small set of warm database connections instead of opening a fresh one for every single request.

Why

Without pooling, hammering the map (pan + /locations + /image-pairs fires many requests per second) would exhaust the Supabase free-tier connection cap and the backend would start returning OperationalError: too many clients. Five workers + five overflow + pre-ping + 5-minute recycle keeps usage safely under the shared cap while surviving Supabase's idle drops.

Plain-English settings

  • pool_size=5 — keep 5 warm connections ready to reuse
  • max_overflow=5 — allow up to 5 extra short-lived connections during spikes
  • pool_pre_ping=True — test a connection with SELECT 1 before using it, in case Supabase dropped it while idle
  • pool_recycle=300 — throw away any connection older than 5 minutes to avoid stale TCP state

How to verify

Pan the map hard for 30 seconds. Backend logs stay clean; no too many clients errors.

Closes #60

Configure the SQLAlchemy engine with pool_size=5, max_overflow=5,
pool_pre_ping=True, and pool_recycle=300. Without pooling, every
request opened a fresh connection, causing OperationalError:
too many clients under modest traffic on Supabase's shared
connection cap.

Closes #60
@madhavcodez madhavcodez self-assigned this Apr 14, 2026
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 14, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
backend Ready Ready Preview, Comment Apr 14, 2026 3:56pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix db connection limits

1 participant