Serverless and edge hosting (Vercel, Netlify, Cloudflare)¶
Scope: deploying web apps and APIs to Vercel, Netlify and Cloudflare Workers (including Cloudflare Pages). The rules are platform-neutral where the three platforms agree, and cite each platform's documentation. Framework rules are in Next.js and Web front end, which also covers caching static assets and HTML (WEB-7). Config in the environment and stateless processes (OPS-9) are in general/operations-reliability.md, keeping secrets out of code (SEC-2) is in general/security.md, and database rules are in PostgreSQL.
Entries are sorted by score from 1 to 10 (criteria): 9โ10 start here or strongly recommended, 6โ8 recommended, 1โ5 further reading or conditional.
Adopted references¶
- 8 Workers Best Practices (Cloudflare Docs): configuration, secrets, background work, database connections, observability and code patterns for Workers.
- 7 Production checklist for launch (Vercel Docs): operational excellence, security, reliability, performance and cost checks to go through before launching on Vercel.
- 7 Caching overview (Netlify Docs): cache control headers, cache key variations, the durable cache,
stale-while-revalidateand purging by site or cache tag on Netlify. - 7 Functions overview (Netlify Docs): how Netlify Functions run, with links to their configuration, background and scheduled functions, environment variables and logs.
Key rules¶
Runtimes, regions and limits¶
- 7
HOST-1Run code that queries a regional database or API in the same region as that backend, and keep edge execution for work that doesn't need it, such as redirects, rewrites, headers and geolocation. Set the function region on Vercel and Netlify; on Cloudflare, which runs Workers close to the user by default, use Placement. (Vercel, Configuring regions for Vercel Functions, Netlify, When to set a region, Netlify, Edge Functions use cases, Cloudflare, Placement) - 6
HOST-2Start new projects on each platform's recommended compute: the Node.js runtime on Vercel, and Workers with static assets on Cloudflare. Vercel recommends migrating from its Edge runtime to Node.js, and Cloudflare recommends Workers instead of Pages for new projects. (Vercel, Edge Runtime, Cloudflare, Use Workers Static Assets for new projects) - 6
HOST-3Keep each request well within the platform's duration, CPU, memory and payload limits, and move long or retryable work to background functions, queues or workflows. For example, Netlify stops synchronous functions after 60 seconds, Vercel limits request and response bodies to 4.5 MB, and Workers on the Free plan get 10 ms of CPU time per request. (Vercel, Functions limits, Netlify, Functions default values, Netlify, Background Functions, Cloudflare, Workers limits, Cloudflare, Use Queues and Workflows for background work)
State and data¶
- 8
HOST-4Keep request and user data out of module-level variables and the local file system, and keep durable state in managed storage, such as a database, key-value store or blob store. One instance serves many requests, sometimes at the same time, and can be stopped at any moment, so global state leaks between requests or disappears. (Cloudflare, Do not store request-scoped state in global scope, Vercel, Fluid compute: isolation boundaries and global state, Netlify, How functions work, Cloudflare, Choose a data or storage product) - 7
HOST-5Connect to relational databases through connection pooling built for the platform: Hyperdrive on Cloudflare Workers, and on Vercel a pool created once per instance and registered withattachDatabasePool. Opening a new connection on every invocation adds round trips and can exhaust the database's connection limit. For pooling in front of PostgreSQL itself, seePG-9. (Cloudflare, Use Hyperdrive for external database connections, How Hyperdrive works, Vercel, attachDatabasePool)
Caching¶
- 7
HOST-6Set CDN caching deliberately on function responses: a shared-cache lifetime withs-maxageorCDN-Cache-Control,stale-while-revalidatewhere slightly stale content is acceptable, andprivateorno-storeon per-user responses. On Cloudflare, enable Workers Cache to cache a Worker's own responses, and note thats-maxagethere turns offstale-while-revalidate. (Vercel, Cache-Control headers, Netlify, Supported cache control headers, Cloudflare, Origin Cache Control, Cloudflare, Workers Cache) - 6
HOST-7Tag cached responses with cache tags, and purge or invalidate them by tag when the underlying content changes. Vercel and Cloudflare can also mark tagged entries stale instead of deleting them, which avoids a burst of requests to the origin. (Vercel, Cache tags, Netlify, Purge by cache tag, Cloudflare, Workers Cache: purging the cache)
Configuration and secrets¶
- 8
HOST-8Store credentials only as the platform's secret variables: Vercel Secret environment variables, Netlify variables marked as containing secret values, and Cloudflare secrets. Never put them in plain variables or invercel.json,netlify.tomlor Wrangler files. Secret values can't be read back once saved. (Vercel, Config and Secret environment variables, Netlify, Environment variable secrets policy, Cloudflare, Store secrets with wrangler secret, not in source, Cloudflare, Secrets) - 8
HOST-9Give production its own secrets and data stores, and don't let preview or development deployments use them. Netlify gives a variable the same value in every deploy context unless you set values per context, and a Cloudflare Preview is isolated from production data only when you bind it to separate KV, D1, R2 or Hyperdrive resources. (Vercel, Environment variables: environments, Vercel, Environment variables policy, Netlify, Value per deploy context, Cloudflare, Previews: resources and isolation) - 7
HOST-10Keep platform configuration in files in the repository, such asvercel.json,netlify.tomlor the Wrangler configuration, and treat them as the source of truth instead of changing settings in the dashboard. File settings are versioned with the code, and on Netlify and Cloudflare they override dashboard changes. (Vercel, Project configuration, Netlify, File-based configuration, Cloudflare, Wrangler configuration: source of truth)
Deployments¶
- 7
HOST-11Keep preview deployments private: check that Vercel Deployment Protection or Netlify's private previews cover them, and put Cloudflare Access in front of Workers previews and Pages preview deployments, which are public by default. (Vercel, Deployment Protection, Netlify, Private previews, Cloudflare, Previews: access control, Cloudflare Pages, Preview deployments) - 7
HOST-12Recover from a bad release by rolling back to the previous production deployment, and keep data and schema changes backward compatible so that the previous version still works. A rollback switches the code, not the data: databases and bound resources keep their current state. (Vercel, Instant Rollback, Netlify, Rollbacks, Cloudflare, Rollbacks)
Observability¶
- 7
HOST-13Send logs and traces to an external observability service with a log drain or OpenTelemetry export, because the platforms keep runtime logs only for hours or days. For example, Vercel keeps one day of runtime logs on Pro, Netlify keeps function logs for at least 24 hours, and Workers Logs keeps them for 3 or 7 days, depending on the plan. Log drains need a Vercel Pro or Netlify Enterprise plan. (Vercel, Runtime Logs: limits, Vercel, Drains, Netlify, Function log retention, Netlify, Log Drains, Cloudflare, Workers Logs: limits, Cloudflare, OpenTelemetry export)
How to enforce¶
Tools that check the key rules above automatically, in CI, the IDE or a commit hook. "Partly" means the tool covers only some of what the rule asks.
- 7 Vercel Separate Production Secret Values: an optional team policy. When an owner turns on Require Separate Values, every Secret must have a different value in Production than in Preview, Development and custom environments. Partly checks
HOST-9. - 6 Netlify secret scanning: built into Netlify builds. It fails the build, before the deploy is published, when the value of a variable marked as secret appears in the repository code or the build output. Partly checks
HOST-8.
Tutorials and further reading¶
- 6 Get started - CLI (Cloudflare Docs): set up and deploy a first Worker with Wrangler, the command-line interface.
- 6 Get started with functions (Netlify Docs): create a first Netlify Function in TypeScript or JavaScript and test it locally.
- 6 Getting started with Vercel (Vercel Docs): install the Vercel CLI and deploy a first project.