[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"blog-en-edge-runtime-vs-node-llm-db-routes":3},{"id":4,"title":5,"author":6,"body":7,"cover":396,"description":397,"draft":398,"extension":399,"locale":400,"meta":401,"navigation":208,"path":402,"publishedAt":403,"seo":404,"seoTitle":405,"slug":406,"stem":407,"tags":408,"__hash__":410},"blog\u002Fen\u002Fblog\u002Fedge-runtime-vs-node-llm-db-routes.md","Edge vs Node for LLM and DB routes: limits and split patterns","Manuel Tardivo",{"type":8,"value":9,"toc":384},"minimark",[10,46,81,86,119,123,146,150,153,163,170,174,193,197,233,237,251,257,277,290,294,332,339,343,370,374],[11,12,13,14,18,19,23,24,27,28,31,32,23,35,23,38,41,42,45],"p",{},"“Edge” (Vercel Edge, Cloudflare Workers, some Nitro builds configured as edge) is not full Node: do ",[15,16,17],"strong",{},"not"," assume ",[20,21,22],"code",{},"fs",", ",[20,25,26],{},"child_process",", native C++ addons, or arbitrary TCP sockets. ",[15,29,30],{},"Classic database drivers"," (",[20,33,34],{},"pg",[20,36,37],{},"mysql2",[20,39,40],{},"better-sqlite3",") need TCP or native bindings → usually ",[15,43,44],{},"Node only",", not edge.",[11,47,48,49,52,53,56,57,23,60,63,64,67,68,23,75,80],{},"Outbound ",[15,50,51],{},"HTTP"," to LLM APIs (",[20,54,55],{},"fetch"," to OpenAI\u002FAnthropic) often works on edge, but you still hit ",[15,58,59],{},"CPU",[15,61,62],{},"wall-clock",", and ",[15,65,66],{},"bundle size"," ceilings. Read current vendor limits (e.g. ",[69,70,74],"a",{"href":71,"rel":72},"https:\u002F\u002Fvercel.com\u002Fdocs\u002Ffunctions\u002Fruntimes\u002Fedge-runtime#limits",[73],"nofollow","Vercel Edge limits",[69,76,79],{"href":77,"rel":78},"https:\u002F\u002Fdevelopers.cloudflare.com\u002Fworkers\u002Fplatform\u002Flimits\u002F",[73],"Cloudflare Workers limits",")—they evolve.",[82,83,85],"h2",{"id":84},"edge-what-works-well","Edge: what works well",[87,88,89,96,105,111],"ul",{},[90,91,92,95],"li",{},[15,93,94],{},"Lightweight JWT"," handling (verify with Web Crypto–friendly libs).",[90,97,98,101,102,104],{},[15,99,100],{},"Rewrites, A\u002FB tests",", geolocation headers, cached ",[20,103,55],{},".",[90,106,107,110],{},[15,108,109],{},"Proxying"," to a Node API that performs heavy I\u002FO.",[90,112,113,118],{},[15,114,115,116],{},"Vendor calls via ",[20,117,55],{}," with moderate payloads.",[82,120,122],{"id":121},"node-what-almost-always-needs-it","Node: what almost always needs it",[87,124,125,134,140],{},[90,126,127,130,131,133],{},[15,128,129],{},"SQL ORMs\u002Fdrivers"," with TCP pools, ",[20,132,40],{},", Prisma engines, BullMQ, ffmpeg, heavy sharp pipelines, local filesystem.",[90,135,136,139],{},[15,137,138],{},"Long streams"," or CPU work past edge budgets.",[90,141,142,145],{},[15,143,144],{},"Secret access patterns"," that edge does not mirror (provider-specific).",[82,147,149],{"id":148},"recommended-split-pattern","Recommended split pattern",[11,151,152],{},"Typical flow for auth + LLM + DB:",[154,155,161],"pre",{"className":156,"code":158,"language":159,"meta":160},[157],"language-text","Client → Edge route (JWT check, light rate limit)\n       → internal fetch to \u002Fapi\u002Fnode\u002F… (pinned region)\n       → Node: DB queries + LLM + logging\n","text","",[20,162,158],{"__ignoreMap":160},[11,164,165,166,169],{},"Edge trims latency for validation and routing; ",[15,167,168],{},"stateful"," work stays in Node where toolchains are mature.",[82,171,173],{"id":172},"cold-start-and-timeouts","Cold start and timeouts",[11,175,176,177,180,181,184,185,188,189,192],{},"Edge often shows ",[15,178,179],{},"lower cold start"," for tiny handlers; Node (serverless) may pay container boot + Prisma init. Measure ",[15,182,183],{},"p95 separately"," for ",[20,186,187],{},"\u002Fedge"," vs ",[20,190,191],{},"\u002Fnode"," on the first request after idle—do not merge metrics.",[82,194,196],{"id":195},"pre-deploy-checklist","Pre-deploy checklist",[87,198,201,215,221,227],{"className":199},[200],"contains-task-list",[90,202,205,210,211,214],{"className":203},[204],"task-list-item",[206,207],"input",{"disabled":208,"type":209},true,"checkbox"," Does this route import ",[20,212,213],{},"node:"," built-ins or native addons? → Node.",[90,216,218,220],{"className":217},[204],[206,219],{"disabled":208,"type":209}," Serial heavy subrequests? Consider all Node or batching.",[90,222,224,226],{"className":223},[204],[206,225],{"disabled":208,"type":209}," Edge max duration \u003C LLM p95 latency? → Node or async (queue + callback).",[90,228,230,232],{"className":229},[204],[206,231],{"disabled":208,"type":209}," Need DB-facing WebSockets? → Node or managed relay.",[82,234,236],{"id":235},"typical-error-message-nextjs-vercel-edge","Typical error message (Next.js \u002F Vercel Edge)",[11,238,239,240,243,244,23,246,23,248,250],{},"Importing a ",[15,241,242],{},"Node-only"," module (",[20,245,22],{},[20,247,40],{},[20,249,34],{},", …) into an Edge route often fails at build or runtime with text like (exact wording varies by Next version):",[154,252,255],{"className":253,"code":254,"language":159,"meta":160},[157],"Error: A Node.js API is used (fs) which is not supported in the Edge Runtime.\n",[20,256,254],{"__ignoreMap":160},[11,258,259,260,265,266,269,270,104],{},"Or during bundling, traces such as ",[15,261,262],{},[20,263,264],{},"node:fs"," \u002F ",[15,267,268],{},"“Module not found: Can't resolve 'fs'”"," from a transitive dependency. Next.js documents the class under ",[15,271,272],{},[69,273,276],{"href":274,"rel":275},"https:\u002F\u002Fnextjs.org\u002Fdocs\u002Fmessages\u002Fnode-module-in-edge-runtime",[73],"Node.js Modules in Edge Runtime",[11,278,279,282,283,286,287,289],{},[15,280,281],{},"Fix:"," move the import to a ",[15,284,285],{},"Node route handler"," (or a Nitro server route on a Node preset) and keep edge limited to ",[20,288,55],{}," \u002F crypto \u002F lightweight logic.",[82,291,293],{"id":292},"vercel-edge-limits-that-affect-llm-db-paths","Vercel Edge: limits that affect LLM + DB paths",[11,295,296,297,300,301,304,305,307,308,310,311,317,318,323,324,327,328,331],{},"On ",[15,298,299],{},"Vercel Edge Functions"," you get ",[15,302,303],{},"Web-standard"," APIs (",[20,306,55],{},", crypto, streams) but ",[15,309,17],{}," full Node—aligned with Next.js guidance on ",[15,312,313],{},[69,314,316],{"href":274,"rel":315},[73],"Node.js modules in Edge Runtime",". For numeric ceilings (CPU, wall time, streaming semantics) follow the live ",[69,319,322],{"href":320,"rel":321},"https:\u002F\u002Fvercel.com\u002Fdocs\u002Ffunctions\u002Fedge-functions\u002Flimitations",[73],"Edge limitations"," page: 2025 changelog posts discussed ",[15,325,326],{},"longer streaming durations"," (hundreds of seconds for the stream) while still enforcing ",[15,329,330],{},"time-to-first-byte"," budgets—re-read the current text before sizing LLM timeouts.",[11,333,334,335,338],{},"Vendor positioning: when you need native drivers or sustained CPU, roadmaps increasingly steer teams toward ",[15,336,337],{},"Node \u002F Fluid compute","; edge stays great for cheap routing \u002F auth.",[82,340,342],{"id":341},"nitro-nuxt","Nitro \u002F Nuxt",[11,344,345,346,351,352,355,356,359,360,31,363,23,366,369],{},"In ",[69,347,350],{"href":348,"rel":349},"https:\u002F\u002Fnitro.unjs.io\u002F",[73],"Nitro",", routes are edge-capable only when the deployment preset allows it. A default ",[20,353,354],{},"node-server"," preset is ",[15,357,358],{},"Node","—no implicit edge. If you later expose edge routes, explicitly document which handlers remain ",[15,361,362],{},"server-only",[20,364,365],{},"runtimeConfig",[20,367,368],{},"routeRules",").",[82,371,373],{"id":372},"summary","Summary",[11,375,376,379,380,383],{},[15,377,378],{},"fetch-only, stateless, low CPU"," → edge candidate. ",[15,381,382],{},"DB drivers, slow LLM, filesystem, natives"," → Node. Edge → internal Node is the pragmatic default for many multi-tenant SaaS APIs.",{"title":160,"searchDepth":385,"depth":385,"links":386},2,[387,388,389,390,391,392,393,394,395],{"id":84,"depth":385,"text":85},{"id":121,"depth":385,"text":122},{"id":148,"depth":385,"text":149},{"id":172,"depth":385,"text":173},{"id":195,"depth":385,"text":196},{"id":235,"depth":385,"text":236},{"id":292,"depth":385,"text":293},{"id":341,"depth":385,"text":342},{"id":372,"depth":385,"text":373},"\u002Fblog\u002F17_edge_runtime_vs_node_llm_db_routes_1x.webp","What breaks in edge runtimes with database drivers and LLM calls, and how to split routes once you are already running in production.",false,"md","en",{},"\u002Fen\u002Fblog\u002Fedge-runtime-vs-node-llm-db-routes","2026-05-23",{"title":5,"description":397},"Edge vs Node: LLM and database limits","edge-runtime-vs-node-llm-db-routes","en\u002Fblog\u002Fedge-runtime-vs-node-llm-db-routes",[409],"mvp","-tiFUgg36h2fCjPJGbnz8Rsg9CP0LzlUxCaFlqB4dc4"]