Connection Pooling
Efficient database connection management for serverless and high-traffic environments using Prisma, PgBouncer, Neon serverless driver, and retry logic.
What's Included#
- Prisma client singleton with configurable connection URL and pool settings
- PgBouncer configuration for serverless connection reuse
- Neon serverless driver integration for edge functions
- Connection lifecycle management with connect/disconnect/health check
- Connection pool monitoring with query tracking and pg_stat_activity
- Database health check API endpoint
- Retry logic with exponential backoff for connection errors
- Edge-compatible database setup using Neon's HTTP driver
Usage#
Via CLI#
Loading code block...
Via AI Assistant#
Ask your AI assistant:
- "Use the connection pooling pattern from Bootspring"
- "Apply the Bootspring pooling pattern to my project"
Key Considerations#
- Always use the singleton pattern to prevent connection exhaustion during hot reloads
- Match pool size to your database's maximum connection limit
- Use PgBouncer in transaction mode for serverless deployments
- Implement health checks to monitor connection pool status
- Add retry logic with exponential backoff for transient connection failures
- Use a separate directUrl in Prisma schema for migrations that bypass PgBouncer
Related Patterns#
- Prisma - Prisma setup and basics
- Transactions - Transaction handling
- Queries - Query optimization