$ ls ./menu

© 2025 ESSA MAMDANI

cd ../blog
10 min read
Web Development

The Definitive Guide: Seamless Migration from Cloudflare to Vercel (Zero Downtime!)

> Unlock unparalleled performance, developer experience, and scalability by migrating your Cloudflare Pages or Workers applications to Vercel with this comprehensive, zero-downtime guide from Essa. Learn how to transition your compute, storage, domains, and configurations, embracing Vercel's open standards and powerful platform.

Audio version coming soon
The Definitive Guide: Seamless Migration from Cloudflare to Vercel (Zero Downtime!)
Verified by Essa Mamdani

Alright, fellow developers, Essa here. You've been building, deploying, and iterating, perhaps leveraging the power of Cloudflare for its CDN, DNS, and serverless Workers. It's a robust platform, no doubt. But what if I told you there's a path to an even more refined developer experience, superior performance for your frontend-heavy applications, and a deployment workflow that feels like magic?

That path, my friends, leads directly to Vercel.

For a long time, the question I've frequently encountered is: "Should I use Cloudflare in front of Vercel?" My answer has always been clear: for the vast majority of applications, absolutely not. Vercel is built from the ground up to be a complete, integrated platform, encompassing a global Edge Network, intelligent caching, serverless functions, and a Git-native deployment pipeline. Introducing another reverse proxy like Cloudflare in front of it often leads to diminished returns – limiting Vercel's traffic visibility, introducing unnecessary latency, and complicating cache management. It's like putting a second, slightly different-shaped hat on top of an already perfectly fitted one.

This isn't about shunning Cloudflare; it's about optimizing your stack for what Vercel excels at. If you've been using Cloudflare Pages or Workers as your primary hosting and compute layer, and you're now eyeing Vercel's integrated DX, blazing-fast deployments, and powerful Next.js (or other framework) optimizations, then this guide is for you. We're going to navigate this migration with precision, ensuring zero downtime and a smooth transition to Vercel's world-class infrastructure.

Let's dive in.


1. Why Vercel? Understanding the Core Advantages

Before we even touch a line of code, let's solidify why this migration is a power move. Vercel isn't just another hosting provider; it's a platform engineered for the modern web, with a laser focus on frontend frameworks, global performance, and developer experience.

  • Integrated Edge Network: Vercel's global CDN is built into the platform. It automatically caches your static assets and delivers dynamic content via serverless functions deployed at the Edge. This means your users get the fastest possible response times, regardless of their geographical location.
  • Git-Native Deployments: Push to your Git repository (GitHub, GitLab, Bitbucket), and Vercel automatically builds, deploys, and provides a preview URL. It's an unparalleled development workflow that dramatically reduces friction.
  • Serverless Functions & API Routes: Seamlessly integrate backend logic with your frontend. Vercel's Serverless Functions (powered by AWS Lambda, Google Cloud Functions, etc.) scale automatically and integrate perfectly with your Next.js API routes or other framework endpoints.
  • Open Standards & Open Source Focus: Vercel champions open source and open standards. This means less vendor lock-in and more flexibility, aligning with modern development philosophies.
  • Optimal Performance for Frameworks: While Cloudflare Pages is great, Vercel's deep integration with frameworks like Next.js, SvelteKit, Astro, and others often yields superior performance optimizations out-of-the-box, especially with features like Image Optimization, Font Optimization, and Incremental Static Regeneration (ISR).

Essa's Pro Tip: Think of Vercel as your entire frontend deployment ecosystem. Its built-in CDN, automatic SSL, and advanced caching are designed to work in harmony, eliminating the need for external services like Cloudflare's CDN in front of it. This simplifies your architecture and often improves performance by removing an unnecessary hop.


2. Initial Project Setup on Vercel

The first step is to get your project onto the Vercel platform. This is incredibly straightforward.

  1. Create a Vercel Account: If you don't have one, sign up at vercel.com. You can sign in with GitHub, GitLab, or Bitbucket.
  2. Import Your Project:
    • From the Vercel dashboard, click "Add New..." -> "Project".
    • Connect your Git provider and select the repository where your Cloudflare Pages or Workers project lives.
    • Vercel will automatically detect your framework (e.g., Next.js, React, Vue, Svelte, plain HTML/CSS) and suggest appropriate build settings.
  3. Deploy: Click "Deploy". Vercel will clone your repository, install dependencies, build your project, and deploy it to a preview URL (e.g., your-project-name-random-id.vercel.app).

Alternatively, you can use the Vercel CLI for a more hands-on approach:

bash
1# Install Vercel CLI globally
2npm i -g vercel
3
4# Navigate to your project directory
5cd my-cloudflare-project
6
7# Initialize a new Vercel project
8vercel init
9
10# Link your local project to a Vercel project (if it's already deployed or you want to create a new one)
11vercel link
12
13# Deploy your project
14vercel

Essa's Pro Tip: For monorepos, Vercel allows you to specify a root directory for your project. This is crucial if your Cloudflare Pages app is just one part of a larger repository. Look for the "Root Directory" option during project import or configure it in vercel.json.


3. Migrating Your Compute: From Workers to Serverless Functions

This is where the core logic of your Cloudflare Workers application gets a new home. While both are "serverless," their environments and APIs differ.

Understanding the Shift

  • Cloudflare Workers: Run on V8 isolates at the Edge, often intercepting requests globally. They use specific Worker APIs (e.g., event.waitUntil, KV namespaces).
  • Vercel Serverless Functions: Run on AWS Lambda (or similar cloud functions) and can be deployed globally to the Edge via Vercel's network. They primarily use Node.js (or other runtimes) and standard HTTP APIs.

Refactoring Worker Logic

Your goal is to translate your Worker's fetch handler logic into a Vercel Serverless Function.

Example: Simple API Endpoint Worker

Let's say you have a Cloudflare Worker handling an API endpoint:

javascript
1// Cloudflare Worker (worker.js)
2addEventListener('fetch', event => {
3  event.respondWith(handleRequest(event.request));
4});
5
6async function handleRequest(request) {
7  const url = new URL(request.url);
8  if (url.pathname === '/api/hello') {
9    return new Response(JSON.stringify({ message: 'Hello from Cloudflare Worker!' }), {
10      headers: { 'Content-Type': 'application/json' },
11    });
12  }
13  return new Response('Not found', { status: 404 });
14}

On Vercel, this would typically become a Node.js Serverless Function, often within an API route if you're using a framework like Next.js:

javascript
1// Vercel Serverless Function (e.g., pages/api/hello.js in Next.js)
2export default function handler(req, res) {
3  if (req.method === 'GET') {
4    res.status(200).json({ message: 'Hello from Vercel Serverless Function!' });
5  } else {
6    res.status(405).json({ message: 'Method Not Allowed' });
7  }
8}

For more complex Workers that perform edge-side logic or manipulate responses, you'll replicate that logic within your Vercel functions, potentially leveraging middleware patterns within your framework or custom Vercel functions.

Essa's Pro Tip: Vercel's Node.js runtime for Serverless Functions gives you access to the entire npm ecosystem. This is a huge advantage for integrating with existing libraries or complex business logic. Remember that Vercel functions have a maximum execution duration (e.g., 10 seconds on Hobby/Pro plans, 60 seconds on Enterprise) and memory limits, similar to Workers.


4. Handling Storage and Databases

Cloudflare offers KV, R2, and D1 for storage. Vercel, while not providing its own native equivalents for all of these directly, integrates seamlessly with a wide array of serverless-first storage solutions.

  • Key-Value Store (Cloudflare KV): For simple key-value storage, consider Vercel's own Vercel KV (powered by Redis), or integrate with Upstash Redis, or even a serverless database like PlanetScale or FaunaDB if you need more structured data.
  • Object Storage (Cloudflare R2): Vercel integrates with Vercel Blob (powered by AWS S3) for object storage. You can also directly use AWS S3, Google Cloud Storage, or other S3-compatible services.
  • SQL Database (Cloudflare D1): Vercel offers Vercel Postgres (powered by Neon) for serverless SQL. Alternatively, you can connect to other serverless databases like PlanetScale (MySQL) or Turso (SQLite/libSQL).

The migration strategy here involves:

  1. Choosing a Vercel-compatible storage solution.
  2. Migrating your data: This often involves writing a script to read data from your Cloudflare storage and insert it into your new Vercel-compatible storage.
  3. Updating your application code: Point your Vercel Serverless Functions to the new storage endpoints and credentials.

Essa's Pro Tip: Leverage Vercel's native integrations where possible (Vercel KV, Vercel Blob, Vercel Postgres). They offer a fantastic developer experience and are optimized for the Vercel platform. For existing data, plan your migration carefully, perhaps using a temporary script to transfer data during a low-traffic window.


5. Converting Build & Deployment Configuration

Vercel is incredibly smart about detecting your project's framework and setting up the correct build commands and output directories. For Cloudflare Pages, your _redirects file or wrangler.toml might contain specific build instructions or routing logic.

Vercel's Automatic Configuration

For most common frameworks, Vercel will automatically:

  • Install dependencies (npm install, yarn install, pnpm install).
  • Run the build command (npm run build, yarn build).
  • Serve from the correct output directory (e.g., dist, .next, public).

Customizing with vercel.json

For more advanced scenarios, especially when migrating redirects or custom headers from Cloudflare Pages _redirects or wrangler.toml, you'll use a vercel.json file at the root of your project.

Example: Redirects

If you had a _redirects file in Cloudflare Pages:

/old-path /new-path 301
/blog/* /articles/:splat 301

In vercel.json, this would look like:

json
1{
2  "redirects": [
3    { "source": "/old-path", "destination": "/new-path", "permanent": true },
4    { "source": "/blog/(.*)", "destination": "/articles/$1", "permanent": true }
5  ]
6}

vercel.json is incredibly powerful for:

  • Rewrites: Changing the URL without redirecting the browser.
  • Headers: Adding custom HTTP headers.
  • Routes: Fine-grained control over how paths are handled.
  • Functions Configuration: Specifying memory, max duration, or regions for serverless functions.
  • Build Settings: Overriding default build commands or output directories.

Essa's Pro Tip: Start with Vercel's automatic detection. Only use vercel.json for configurations that deviate from the defaults or require specific routing logic. This keeps your setup clean and leverages Vercel's intelligence. Always test your redirects and rewrites thoroughly on a preview deployment before pushing to production.


6. Moving Environment Variables and Secrets

Securely managing secrets is paramount. Cloudflare Workers and Pages have their own mechanisms for environment variables. Vercel provides a robust system accessible via the dashboard or CLI.

  1. Identify All Variables: List all environment variables and secrets used by your Cloudflare application (e.g., API keys, database connection strings).

  2. Add to Vercel:

    • Dashboard: Go to your project settings on Vercel, navigate to "Environment Variables," and add them one by one.
    • CLI: Use vercel env add.
    bash
    1# Add a production secret
    2vercel env add API_KEY production
    3
    4# Add a secret for all environments (development, preview, production)
    5vercel env add DB_CONNECTION_STRING

    When running vercel env add, the CLI will prompt you for the value and then ask which environments (development, preview, production) it should apply to.

Essa's Pro Tip: Always separate environment variables by environment (development, preview, production). Never hardcode secrets. Vercel's environment variable management is designed for security and ease of use across your entire deployment pipeline. For local development, Vercel CLI can pull these secrets into a .env file, ensuring consistency.


7. Zero-Downtime Custom Domain Migration

This is the final, critical step to cut over your traffic. The goal is to switch your DNS records from Cloudflare to Vercel without any noticeable downtime for your users.

  1. Add Domain to Vercel:

    • In your Vercel project settings, go to "Domains."
    • Click "Add Domain" and enter your custom domain (e.g., yourdomain.com).
    • Vercel will provide you with the necessary DNS records (typically A records for the root domain and CNAME for subdomains like www).
  2. Update DNS Records in Your Registrar:

    • Log in to your domain registrar (e.g., Namecheap, GoDaddy, Google Domains, or Cloudflare DNS if you're using it solely as a DNS provider).
    • Important: Before changing anything, ensure your Vercel project is fully deployed and accessible via its Vercel preview URL.
    • Locate your domain's DNS settings.
    • For the root domain (yourdomain.com): Change your existing A and AAAA records to point to the IP addresses provided by Vercel.
    • For subdomains (www.yourdomain.com): Change your CNAME record for www to point to cname.vercel-dns.com.
    • Remove Old Cloudflare Records: If Cloudflare was acting as your full proxy (not just DNS), ensure any proxy settings are disabled or remove the domain from Cloudflare's proxy services.
  3. Vercel's Automatic SSL: Once your DNS records propagate and point to Vercel, Vercel will automatically provision and renew an SSL certificate for your domain. This happens seamlessly and doesn't require manual intervention.

Essa's Pro Tip: DNS propagation can take minutes to hours (though often much faster). Start this process during a low-traffic period if possible. You can monitor propagation using tools like dig or online DNS checkers. Vercel's dashboard will show the status of your domain and indicate when it's correctly configured and pointing to Vercel. Do not delete your old Cloudflare DNS records until you've verified your site is live on Vercel.


Wrapping It Up: Embrace the Vercel Advantage

Migrating from Cloudflare to Vercel is a strategic move that aligns your infrastructure with the demands of modern web development. You're not just changing hosts; you're adopting a platform that prioritizes developer velocity, global performance, and a seamless integration between frontend and serverless backend.

By following this guide, you've equipped yourself with the knowledge to smoothly transition your compute logic, storage, configurations, and custom domains, all while maintaining a zero-downtime experience for your users. The journey from Cloudflare Pages or Workers to Vercel is one towards a more streamlined, performant, and enjoyable development workflow.

So go forth, deploy with confidence, and experience the power of Vercel. Your users (and your sanity) will thank you.