Source code Performance Cost

PrismaClient instantiated on every serverless invocation

Part of the Cost controls check · fix arrives as a pull request

What it is

A PrismaClient is constructed inside the request handler, so a new client and connection pool is created on every serverless invocation.

Why it matters

Each instance opens its own connections, and under concurrency they multiply until the database refuses new ones. The engine startup also runs per request, which shows up as latency on every call rather than once per container.

How to fix it

Instantiate the client once at module scope and reuse it across invocations. In development, cache it on globalThis so hot reload does not accumulate clients.

Run them all on your app

Connect your repo and your live services with read-only scopes. The first scan is free, and nothing changes without your approval.