Summary
This PR addresses memory issues in Railway by implementing the Prisma singleton pattern and adding configurable connection pool sizing.
Changes
- Default connection pool size reduced from 10 to 3 connections
- Added
PRISMA_CONNECTION_LIMIT environment variable to override the default
- Automatically appends
connection_limit to DATABASE_URL if not already set
- Implements Prisma singleton pattern using
globalThis to prevent multiple instances
Why This Matters
In containerized environments like Railway:
- Each PrismaClient instance opens its own connection pool (default: 10 connections)
- Multiple instances can accumulate during container restarts or hot reloads
- Each connection consumes memory for buffering
- Smaller containers (512MB-1GB) can quickly run out of memory
Configuration
Set the PRISMA_CONNECTION_LIMIT environment variable in Railway to adjust:
PRISMA_CONNECTION_LIMIT=3 # for 512MB containers
PRISMA_CONNECTION_LIMIT=5 # for 1GB+ containers
Or set it directly in your DATABASE_URL:
postgresql://...?connection_limit=3
Testing
Fixes memory issues observed in Railway deployment.
Summary
This PR addresses memory issues in Railway by implementing the Prisma singleton pattern and adding configurable connection pool sizing.
Changes
PRISMA_CONNECTION_LIMITenvironment variable to override the defaultconnection_limittoDATABASE_URLif not already setglobalThisto prevent multiple instancesWhy This Matters
In containerized environments like Railway:
Configuration
Set the
PRISMA_CONNECTION_LIMITenvironment variable in Railway to adjust:Or set it directly in your
DATABASE_URL:Testing
Fixes memory issues observed in Railway deployment.