Concept
Serverless Hosting (Vercel & Netlify)
Traditional hosting requires running virtual servers (like AWS EC2) 24/7, paying for idle time, and managing operating systems.
Serverless Hosting platforms (Vercel, Netlify) abstract this. You deploy raw static files (HTML/CSS) to CDN networks, and compile API route code into transient Serverless Functions (like AWS Lambda). The function only spins up when a request arrives, charging only for active runtime milliseconds.
Edge Runtimes (Cloudflare Workers & Pages)
While Serverless functions run in regional datacenters, Edge Runtimes execute code directly at CDN edge nodes geographically nearest to the user, reducing network transit times:
Client (Paris) ──▶ Edge Node (Paris) ──▶ Instant Response (0ms delay)
(V8 Isolate executes code locally)Differences between Serverless and Edge runtimes:
- Serverless (Node.js): Full access to the Node.js API library. Moderate cold starts (latency when container boots). High memory allocations.
- Edge (V8 Isolates): Very limited API (only fetch, Web APIs). Near-zero cold starts. Extremely fast execution speed. Small memory allocation.
Common Mistakes
1. Expecting Node.js APIs to compile inside Edge runtimes
If you configure a route to run on the Edge (e.g. export const runtime = 'edge') and try to import Node.js core modules (like fs, path, or crypto), compiling will fail. The Edge runtime runs on V8 Isolates and does not support Node modules.
2. Storing data in local filesystems on Serverless platforms
Serverless functions are stateless and ephemeral. Any file written to the local filesystem (like fs.writeFileSync('/tmp/user.txt')) is deleted as soon as the container spins down. Always store data in external databases.
Best Practices
- Match Runtimes: Deploy API endpoints to Serverless Node.js by default if you use complex third-party dependencies. Switch to Edge only for latency-critical tasks like custom header rewrites or geolocation styling.
- Use Edge Middleware: Run lightweight redirection or auth checks in Edge Middleware before requests reach origin servers to optimize load times.
- Set Up Custom Domain SSLs: Take advantage of automatic SSL cert generation provided by Vercel/Netlify/Cloudflare to keep pages secure.
