Skip to main content
InterviewHubPRO
Section Overview
Q38

Question 38 of 50

Part 3: Advanced Internals, Scale & Production Architecture (Senior / Lead)

76%
Next.js & App Router (50 Qs)•Part 3: Advanced Internals, Scale & Production Architecture (Senior / Lead)

Database Connection Pooling in Serverless & Next.js.

senior LevelSystem DesignDatabases & SQL

In Simple Words: Serverless functions scale horizontally by creating hundreds of concurrent container instances:

  • If 500 serverless instances each open a direct TCP connection to PostgreSQL, the database exceeds max_connections and crashes!
  • Mitigation:
    1. Use a connection pooler like PgBouncer or AWS RDS Proxy.
    2. Use HTTP-based serverless database drivers (Neon Serverless, PlanetScale, Supabase over HTTP).
    3. In long-lived Node.js servers, instantiate Prisma/Drizzle as a global singleton to prevent re-opening pools on hot reload.