Any advice to use Vercel + Neon + Prisma + Edge Runtime?

I’m using Next.js and Vercel for long time and all this time I try to avoid using Edge runtime for large apps and use it for small experiments only. Problem is the unpredictable “timeout error”.

Recently I’ve got a task to find out how to finally make it work but my investigation got into a dead end again. The requests are handled 50/50 times. Since I use multiple HTTP requests, at least one of the requests give me the timeout error making the entire app unusable.

import { PrismaClient } from "@prisma/client";
import { PrismaNeon } from "@prisma/adapter-neon";
// ... getClient function
const adapter = new PrismaNeon({
      connectionString: `${process.env.DATABASE_URL}`,
});
const prisma = new PrismaClient({ adapter });
return prisma;

I’ve got a small DB with 2 models made with Prisma and wanted to do a full-stack application completely made of Edge Functions. As Vercel advices I use Neon DB ad Postgres provider. First I’ve got “maximum edge function size error” because my edge function was about 1.1 MB. @next/bundle-analyzer didn’t provide me any useful information, so I’ve checked the packages I import on Bundlephobia. All bundles I’ve used was about 300 KB in total, and I assume that Next.js adds a lot of extra code over what I actually use.

I switched to the Pro plan, but still got this 50/50 error. I’ve set Function CPU to “Performance”, still same result.

Next move would be purchasing a paid plan on Neon, but it sounds like I just moving a wrong direction.

I’ve googled a lot of issues and found out that the stack I’m trying to use isn’t runnable at the edge runtime for many users (too big function, or timeout errors). But Vercel as well as Neon are advertised as Edge Runtime compatible envs and I’ve got very confused because of the problems I’ve described.

My questions are:

  • Is Edge Runtime actually capable to host back-end functions with DB retrieval, maintaining stability and performance that is higher than with nodejs runtime? It doesn’t make sense to create an app that works time to time, even with .1% chance to get the error. Can anyone share their experience?
  • If yes, what’s the recommended stack? Are Prisma and Edge compatible? Maybe something else is wrong?

UPD: There is what my logs look like

Is Edge Runtime actually capable to host back-end functions with DB retrieval, maintaining stability and performance that is higher than with nodejs runtime?

The argument for edge runtime was always lower latency, rather than better performance. You get a less powerful worker with lower limits and less compatibility with modules since it doesn’t run Node.js, but in exchange it can start up faster and be physically located closer to users

This tradeoff hasn’t paid off as well as we thought it would, based on data from our own sites and many many enterprise customers. The performance bottleneck is usually server → database latency, not user → server latency. For that reason, we actually moved vercel.com off of Edge and back to the node runtime

So I would also recommend you use the regular node runtime as a default, unless you have a specific reason for choosing edge

Are Prisma and Edge compatible?

Prisma in particular is a rather heavy dependency and if you want to stick to edge, Drizzle is much lighter alternative that could help you stay in your limits