What You Need Before Starting
- Cloudflare Account - Go to cloudflare.com and sign up (free)
- Your Domain Managed by Cloudflare - Your domain's nameservers point to Cloudflare
- Working Vercel Deployment - Your app deployed at
your-app.vercel.app - Cloudflare Business or Enterprise Plan - Load Balancer only works on paid plans ($200+/month)
If you don't have Business plan yet, don't worry - we'll upgrade in Step 1.
CRITICAL: Understand the Cost
Cloudflare Load Balancer Pricing:
- Business Plan: $200/month (includes 1 load balancer + up to 2 pools)
- Enterprise Plan: Custom pricing (unlimited load balancers + pools)
- Cost per additional pool: Included in Business plan
This is the main expense. If you only want to use Vercel without redundancy, keep Vercel Pro ($20/month) - cheaper than load balancer.
Only proceed if you have budget for Cloudflare Business.
Step 1: Verify Your Vercel Deployment Works
Before touching Cloudflare, ensure Vercel is working perfectly.
Test Your Vercel App
Open your browser:
https://your-app.vercel.app
You should see your app loading without errors.
Find Your Exact Vercel URL
- Go to vercel.com dashboard
- Select your project
- Go to Settings → Domains
- You'll see your default domain:
your-app.vercel.app
Copy this exact URL - you'll need it in a few minutes.
Step 2: Add Health Check Endpoint to Vercel
Load Balancer constantly checks if your origin is healthy by hitting an endpoint.
Create Health Endpoint (Next.js App Router)
Create new file: app/api/health/route.js
javascript
Create Health Endpoint (Next.js Pages Router)
Create new file: pages/api/health.js
javascript
Deploy to Vercel
bash
Wait for deployment to complete (1-2 minutes).
Test Your Health Endpoint
In terminal:
bash
Expected response:
json
HTTP Status should be 200 OK
If you get 404 or error, deployment didn't work. Wait a few seconds and try again.
Step 3: Upgrade Cloudflare to Business Plan
Load Balancer only available on Business plan.
Go to Billing
- Open dash.cloudflare.com
- Select your domain in left sidebar
- Go to Billing and Subscriptions
- Click Plan
Upgrade to Business
- You'll see current plan (Free/Pro)
- Click on Business option
- Click Change Plan button
- Add payment method if needed
- Confirm upgrade
⚠️ You'll be charged immediately.
After upgrade completes (takes a few minutes), refresh the dashboard.
Verify Business Plan Activated
- Go to left sidebar menu
- Look for Traffic option (only visible on Business+)
- Under Traffic, you should see Load Balancing
If you don't see it yet, wait 5 minutes and refresh.
Step 4: Create Health Monitor
Health monitors check if your origin is alive.
Go to Load Balancing Section
- Open dash.cloudflare.com
- Select your domain
- Left sidebar → Traffic
- Click Load Balancing
- You'll see tabs: Monitors | Pools | Load Balancers
Create New Monitor
- Click Monitors tab
- Click Create Monitor
Fill In Monitor Settings
Basic Settings:
- Monitor Name:
vercel-health-monitor - Type: Select HTTP
- Port:
443(HTTPS) - Method:
GET - Path:
/api/health - Interval:
60(seconds - check every 60 seconds) - Timeout:
5(seconds - wait max 5 seconds) - Retries:
2(mark unhealthy after 2 failed checks)
Expected Response:
- Expected Code:
200 - Expected Body: Leave blank (just check for 200 status)
Advanced Settings (scroll down):
- Description:
Health check for Vercel deployment - Leave everything else default
- Click Create button
Step 5: Create Origin Pool
Origin pool = your Vercel deployment (one server/group).
Go to Pools Tab
- Still in Load Balancing section
- Click Pools tab
- Click Create Pool button
Fill In Pool Settings
Pool Configuration:
- Pool Name:
vercel-primary - Description:
Primary Vercel deployment
Origins:
- Click Add Origin
- Origin Address: Paste your Vercel URL:
your-app.vercel.app - Origin Name:
vercel-1 - Click Save Origin
Monitor:
- Select:
vercel-health-monitor(the one you just created)
Health Check Regions:
- Leave default (monitors from multiple Cloudflare locations)
- Click Save and Deploy button
You should see status: "Healthy" (might take 30 seconds for first check)
Step 6: Create Load Balancer
Now connect everything together.
Go to Load Balancers Tab
- In Load Balancing section
- Click Load Balancers tab
- Click Create Load Balancer button
Configure Load Balancer
Hostname Configuration:
- Hostname: Enter your desired subdomain
- Example:
app.yourdomain.comORwww.yourdomain.com
- Example:
- Description:
Load balancer with Vercel - TTL:
30(seconds - how long to cache DNS)
Default Pools:
- Choose Pool: Select
vercel-primary(your Vercel pool) - Pool Weight:
1(100% traffic goes here)
Failover Pools (Optional):
- Leave empty for now (add later when you deploy to Cloudflare Pages or Netlify)
Additional Settings:
- Session Affinity:
None(recommended for stateless apps) - Steering Policy:
Round Robin(only matters with multiple pools) - Adaptive Routing: Leave unchecked
- Click Save and Deploy button
Status should show: "Deployed"
Step 7: Update Your DNS Records
Your load balancer is now running but traffic isn't routing to it yet. You need to update DNS.
Go to DNS Section
- Left sidebar → DNS
- You'll see your domain's DNS records
Find or Create Your Main Record
Look for a record named:
@(root domain) ORwwwORapp
Depending on what hostname you chose in Step 6.
If it doesn't exist, create it:
- Click Add Record
- Type: CNAME
- Name: Whatever you chose in Step 6 (app / www)
- Content: Leave empty for now, we'll get it in next part
- Proxy Status: Proxied (orange cloud)
- Click Save
Get Your Load Balancer CNAME
- Go back to Traffic → Load Balancing
- Click Load Balancers tab
- Click your load balancer name
- Copy the CNAME value shown
- Format:
your-lb-id.us.cloudflare.com
- Format:
Update DNS Record
- Back to DNS section
- Find the record you just created
- Click Edit
- Content: Paste the load balancer CNAME
- Proxy Status: Make sure it's Proxied (orange cloud, not gray)
- Click Save
Step 8: Wait for DNS Propagation
DNS changes take time to spread globally.
Verify DNS Updated
Wait 5-10 minutes, then test:
bash
You should see responses coming from your Vercel app.
Test Your Load Balancer URL
- Open browser
- Visit:
https://app.yourdomain.com - Your app should load normally
If it shows Cloudflare error page:
- DNS hasn't propagated yet (wait 10 more minutes)
- Or pool is marked unhealthy (check health check endpoint)
Step 9: Verify Everything Works
Check Pool Status
- Traffic → Load Balancing → Pools
- Find
vercel-primarypool - Should show green checkmark (✔) = Healthy
If red X (✘) = Unhealthy:
- Health endpoint might be failing
- Test:
curl https://your-app.vercel.app/api/health - Should return HTTP 200
Check Load Balancer Status
- Traffic → Load Balancing → Load Balancers
- Find your load balancer
- Should show green checkmark (✔) = Deployed
Test Real Traffic
- Visit
https://app.yourdomain.com - Refresh several times
- App should load every time without errors
Check Analytics
- Traffic → Load Balancing
- You should see traffic metrics
- Shows how many requests are going through
Common Issues & Fixes
Issue: "DNS CNAME not found" or 404 error
Solution:
- Wait 10+ minutes for DNS propagation
- Clear browser cache (Ctrl+Shift+Delete)
- Verify DNS record is Proxied (orange cloud)
Issue: Pool shows "Unhealthy" (red X)
Check your health endpoint:
bash
Should return:
- HTTP 200 status
- JSON response with
"status": "healthy"
If failing:
- Health endpoint code has error
- Redeploy Vercel:
git push origin main - Wait 1-2 minutes for deployment
- Test health endpoint again
Issue: Health check timeout
If health endpoint is slow:
- Go to Traffic → Load Balancing → Monitors
- Click your monitor
- Increase Timeout from 5 to 10 seconds
- Increase Retries from 2 to 3
- Save
Issue: Can't upgrade to Business plan
Reasons:
- Need valid payment method
- Account too new (wait 24 hours)
- Try using credit card instead of digital wallet
Contact Cloudflare support if issues persist.
What Happens Next
You now have:
✔ Vercel app running at your-app.vercel.app
✔ Cloudflare Load Balancer at app.yourdomain.com
✔ Health monitoring every 60 seconds
✔ Automatic failover ready (when you add more origins)
To Add More Origins (Later)
When you deploy to Cloudflare Pages or Netlify:
- Create health endpoint on new platform
- Create new pool in Cloudflare (Pools tab)
- Add new pool to load balancer
- Change to Round Robin or Weighted distribution
- Test failover
Monitoring Going Forward
Daily Checks
- Visit Traffic → Load Balancing
- Verify all pools show green checkmark (✔)
- Check traffic is flowing normally
Set Up Alerts (Optional)
- Go to Notifications (left sidebar)
- Create alert for "Load Balancer Origin Health"
- Get notified if origin goes down
View Logs
- Analytics → Traffic
- See all requests coming through load balancer
- Monitor response times and errors
Security Notes
- All traffic goes through Cloudflare (HTTPS encrypted)
- Cloudflare provides DDoS protection automatically
- Your Vercel URL is hidden from public (not directly accessible anymore)
- Only
app.yourdomain.comis publicly known






