The Edge Runtime Cold Start Myth: Why We Moved Three Routes Back to Node
Edge runtime promised faster cold starts and lower latency. For three of our routes, it delivered the opposite. Here's what we measured, why it happened, and the rules we now use to decide.
We spent most of 2024 moving routes to the edge runtime. In early 2025 we moved three of them back to Node. The p95 dropped by roughly a third on two of them, and the third stopped timing out entirely. This is the honest story of why the "edge is always faster" assumption broke for us, and the checklist we now run before picking a runtime in Next.js App Router.
The pitch we believed
When Vercel and the Next.js team started pushing the edge runtime, the sales points were compelling: cold starts in single-digit milliseconds, code that runs geographically close to users, and a smaller API surface that forces you to write portable code. On paper, every API route and every middleware should live there.
We bought in. By the end of 2024, most of our product's App Router routes had export const runtime = 'edge' at the top. Auth callbacks, product search, a dashboard summary endpoint, the lot.
Then we started seeing weird tail latency on three specific routes. Not everywhere. Not always. But enough that our on-call rotation stopped trusting the dashboards.
What we actually measured
Before ripping anything out, we instrumented. We added timing marks at four points in each request:
// app/api/dashboard-summary/route.ts
import { NextResponse } from 'next/server';
export const runtime = 'edge';
export async function GET(req: Request) {
const t0 = performance.now();
const session = await getSession(req);
const t1 = performance.now();
const [orders, invoices, usage] = await Promise.all([
fetchOrders(session.userId),
fetchInvoices(session.userId),
fetchUsage(session.userId),
]);
const t2 = performance.now();
const summary = buildSummary(orders, invoices, usage);
const t3 = performance.now();
return NextResponse.json(summary, {
headers: {
'Server-Timing': [
`auth;dur=${(t1 - t0).toFixed(1)}`,
`fetch;dur=${(t2 - t1).toFixed(1)}`,
`compute;dur=${(t3 - t2).toFixed(1)}`,
].join(', '),
},
});
}
The Server-Timing header is a gift when you need per-phase breakdowns in a real browser's Network tab. We shipped this to a 10% canary and looked at the numbers for a week.
Three patterns emerged.
Pattern 1: fan-out to a distant database
Our primary Postgres lives in one region (eu-west). The edge runtime placed our function wherever the user was — São Paulo, Sydney, Mumbai. Each of those three parallel fetches in the handler above was now crossing an ocean. The fetch phase, which was 40–60 ms on Node in the same region as the database, ballooned to 300–600 ms from the edge, because three round trips were serialized at the TCP level even if logically parallel.
Connection pooling made it worse. The edge runtime can't hold a persistent Postgres connection the way a long-lived Node process can. Every invocation reached for an HTTP-based pooler, and the pooler itself was in eu-west. So we paid: user → edge PoP → pooler → database → back. Four hops, not two.
Pattern 2: heavy JSON work
One of our routes builds a navigation tree from a 300 KB CMS response. On Node, JSON.parse plus the tree-building loop ran in 8–12 ms. On the edge runtime, the same work hit 35–50 ms, sometimes more. The edge runtime is based on V8 isolates with tighter CPU budgets and different memory behaviour; synchronous CPU work that would be invisible on a Node Lambda became the dominant cost.
We weren't doing anything exotic. No WASM, no crypto. Just parsing and walking an object tree. But at the edge, CPU-bound work is the thing you most want to avoid, because you're billed and throttled differently than you expect.
Pattern 3: cold starts that weren't actually cold
This one surprised us. The edge runtime is supposed to have near-zero cold starts. And it does, if you measure the runtime boot. But our bundles weren't tiny. One route pulled in a validation library, a date utility, a markdown parser, and our internal auth SDK. Total bundle size for that edge function: around 1.1 MB.
That bundle has to be shipped to and evaluated at every PoP that serves it, the first time. "Cold start" in the edge sense means isolate startup, but there's a separate penalty the first time a specific PoP sees your code. For low-traffic routes in less-popular regions, that first hit was 400–800 ms. Not catastrophic, but not the 5 ms the marketing suggests.
When edge genuinely wins
We didn't move everything back. A few routes stayed on the edge and we'd put more there tomorrow:
- Middleware doing auth gating or header rewrites. Small, no database calls, runs on every request. The edge is perfect.
- A/B test assignment and cookie setting. Pure logic, deterministic, latency-sensitive because it blocks the HTML response.
- Geo-aware redirects. You literally need to know where the user is. Edge is the only sane place.
- Streaming AI responses where the function is mostly a proxy to a model provider that has its own global presence.
The common thread: little or no CPU work, no round trips to a single-region datastore, small bundles.
The rules we now use
We wrote these down and pinned them in the repo. They're boring on purpose.
1. Default to Node for App Router route handlers
Unless a route meets one of the "edge wins" conditions above, start it on Node. Switching later is a one-line change. The default should match the common case, which for our product is "call the database, do some work, return JSON".
2. Keep middleware ruthlessly thin
Middleware runs on the edge by design. That means no database calls, no heavy parsing, no large imports. If you catch yourself importing a 200 KB library into middleware.ts, stop. Push that work into a route handler or a server component instead.
// middleware.ts — good
import { NextResponse, type NextRequest } from 'next/server';
export function middleware(req: NextRequest) {
const token = req.cookies.get('session')?.value;
if (!token && req.nextUrl.pathname.startsWith('/app')) {
const url = req.nextUrl.clone();
url.pathname = '/login';
return NextResponse.redirect(url);
}
return NextResponse.next();
}
export const config = {
matcher: ['/app/:path*'],
};
Notice what's not there: no JWT verification, no database lookup, no feature flag SDK. Those happen in the route or layout that owns the page.
3. Measure before you move
Don't change a route's runtime based on a blog post (this one included). Add Server-Timing headers, ship to a canary, look at p50, p95, and p99 across at least three geographies. The edge runtime can look identical to Node on a local Mac and radically different for a user in Jakarta.
4. Watch the bundle
Next.js will tell you the size of each edge function in the build output. Treat anything over 500 KB with suspicion. The edge runtime has strict limits (currently around 1–4 MB depending on your host), and larger bundles hurt the first-hit penalty we described. Our rule: if an edge function imports more than three internal modules, it probably shouldn't be on the edge.
5. Co-locate compute with data
This is the single biggest predictor of which runtime wins. If your data lives in one region, your compute should too, or you need a data layer that's actually global (a read replica strategy, an edge-native database, or aggressive caching with unstable_cache and proper tags). Putting a function at the edge while its data sits in eu-west is the worst of both worlds: you pay for geographic distribution without getting any of its benefits.
The architectural lesson
The edge runtime isn't slower than Node. It's slower for the wrong workloads, and the wrong workloads turn out to be most of a typical business app: auth check, query a database, assemble a response. Those workloads were what traditional serverless Node functions were designed for, and they're still what Node functions are best at.
The edge is a specialist tool. It's brilliant for request-path logic that needs to be geographically close to the user and has no dependency on a centralised datastore. It's a poor fit for anything that fans out to a single-region backend or does meaningful CPU work.
If you're planning a serious App Router architecture or want a second pair of eyes on one that's already live, our team does this kind of per-route runtime audit regularly — our web development services page has more on how we approach it.
Where we'd start
If you're staring at a Next.js app with runtime = 'edge' scattered through it and unsure what to do, pick the three routes with the worst p95 latency. Add Server-Timing headers. Deploy to a canary for a week. For any route where the fetch phase dominates and your database is single-region, flip it to Node and compare. You'll know within a day whether the edge was helping or hurting. That's it — no rewrite, no big migration, just honest measurement one route at a time.
Want a team like ours?
72Technologies builds production software for the kind of teams who actually read this blog.
Start a projectKeep reading
Why Our Design System's Tokens Broke Dark Mode in Server Components
We shipped a design system with CSS variables, theme toggles, and server components. Then half our pages flashed white on reload and the other half rendered the wrong theme entirely. Here's what we learned.
Server Actions and the N+1 Problem Nobody Talks About
Server Actions feel like a free lunch until you profile a page that fires twelve of them on mount. Here's how we found a 3-second TTI regression hiding behind what looked like clean React code.
The Hidden Cost of `revalidateTag` at Scale: Why Our Cache Invalidations Took 40 Seconds
`revalidateTag` looks like a free lunch until you ship it to a site with 80,000 cached entries. Here's what we learned about Next.js tag invalidation when it stopped being instant.
