01. The Single Server Fallacy
Amateur builders deploy to a single server in one region (usually US-East). A user in Lagos, Nigeria or Tokyo, Japan waits 200-500ms for every request to cross undersea fiber-optic cables before even receiving a byte.
The Global Model: Static assets, HTML shells, and lightweight API logic live on the Edge — cached or executing inside data centers miles from the end user, not thousands of miles away.
Latency by Region (Single US-East Server)
| User Location | Round Trip Distance | Typical TTFB | User Experience |
|---|---|---|---|
| New York | ~50 km | ~30ms | Instant |
| London | ~5,500 km | ~100ms | Fast |
| Lagos | ~8,500 km | ~180ms | Acceptable |
| Mumbai | ~13,000 km | ~250ms | Noticeable delay |
| Tokyo | ~11,000 km | ~220ms | Noticeable delay |
| Sydney | ~16,000 km | ~300ms | Frustrating |
With a CDN (Edge Nodes Everywhere)
| User Location | Edge Node Distance | Typical TTFB | User Experience |
|---|---|---|---|
| New York | ~5 km | ~15ms | Instant |
| London | ~3 km | ~12ms | Instant |
| Lagos | ~50 km | ~25ms | Instant |
| Mumbai | ~20 km | ~20ms | Instant |
| Tokyo | ~10 km | ~15ms | Instant |
| Sydney | ~15 km | ~18ms | Instant |
The difference: 300ms → 18ms. A 16x improvement for the furthest users, achieved by distributing your content globally — not by writing faster code.
02. CDN Architecture & Edge Routing
A CDN (Content Delivery Network) is a globally distributed network of servers. When you deploy to Vercel, Netlify, or Cloudflare, your build assets are duplicated across hundreds of PoPs (Points of Presence) worldwide.
How Edge Resolution Works
Edge Computing: Code at the Edge
Modern edge platforms don’t just cache — they execute code at the edge node. This means your server logic runs in Lagos, not just your static files.
| Platform | Edge Runtime | What Runs at the Edge |
|---|---|---|
| Vercel | Edge Functions (V8 isolates) | Middleware, API routes, ISR revalidation |
| Cloudflare | Workers (V8 isolates) | Full request handling, transforms, routing |
| Netlify | Edge Functions (Deno) | Request rewriting, A/B testing, auth checks |
| AWS | Lambda@Edge (Node.js) | Request/response manipulation |
Tell your AI tool: “Create a Vercel Edge Function that runs at the nearest edge node. Implement A/B testing by checking for an ‘ab-bucket’ cookie. If not present, randomly assign bucket A or B and set the cookie. This runs at the edge — no origin round trip.”
When to Use Edge vs. Origin
| Task | Edge | Origin | Why |
|---|---|---|---|
| Serve static HTML/CSS/JS | ✅ | ❌ | No computation needed — just cache |
| Rewrite URLs | ✅ | ❌ | Lightweight, no database access |
| A/B testing | ✅ | ❌ | Cookie-based routing, no DB |
| Rate limiting | ✅ | ✅ | Edge for fast rejection, origin for full logic |
| Authentication checks | ✅ | ✅ | Edge for JWT validation, origin for session lookup |
| Database queries | ❌ | ✅ | Database is in one region — edge can’t reach it fast |
| Payment processing | ❌ | ✅ | Requires secure origin with Stripe webhooks |
| File uploads | ❌ | ✅ | Large payloads shouldn’t traverse edge network |
03. Caching Headers: The Production Playbook
Caching headers control how long CDNs and browsers remember your files. Getting this wrong means stale content or overloaded servers.
The Strategy Matrix
| Content Type | Cache-Control Header | Why |
|---|---|---|
Hashed assets (main.a1b2c3.js) | public, max-age=31536000, immutable | Filename changes when content changes — cache forever |
Fonts (inter-latin.woff2) | public, max-age=31536000, immutable | Fonts rarely change — cache forever |
| Images (hero, thumbnails) | public, max-age=2592000 | Cache 30 days — images change occasionally |
| Dynamic HTML (SSR pages) | public, max-age=0, s-maxage=60, stale-while-revalidate=86400 | Serve stale instantly, refresh in background |
| API responses (public data) | public, max-age=300 | Cache 5 minutes — balance freshness and speed |
| API responses (user data) | private, no-cache | Never cache — always revalidate with server |
| Sensitive data (tokens, PII) | no-store | Never cache, never store |
Stale-While-Revalidate Explained
The result: Users almost always get a cached response (~15ms). The cache refreshes transparently in the background. No flash of stale content, no waiting for origin.
Cache Busting Patterns
How it works: Build tools inject content hashes into filenames. When the file content changes, the hash changes, the filename changes, and the browser treats it as a new file (cache miss).
Example:
main.a1b2c3.js— Browser caches this forever- You change the code → new build produces
main.x9y8z7.js - Browser downloads the new file (cache miss for the old one)
This is why you can set Cache-Control: max-age=31536000 (1 year) on hashed assets — the filename itself is the cache buster.
Cache Purging
When you deploy a new version, you need to purge stale caches:
How to purge cache:
Cloudflare: Go to your Cloudflare dashboard → Caching → Configuration → Purge Everything. Or use their API with a purge request.
Vercel: Cache is automatically purged on every deploy. No manual action needed. If you need to purge specific URLs, use the Vercel dashboard or API.
Manual purge for specific paths: Use the platform’s API to purge specific URLs while keeping other cached content intact.
04. Environment Variables: Build vs. Runtime
When deploying, you must separate variables needed during compilation from variables needed during execution.
The Two Environments
Platform Configuration
Vercel:
- Go to your project in Vercel dashboard
- Settings → Environment Variables
- Add build-time variables (CMS_API_TOKEN)
- Add runtime variables (DATABASE_URL, STRIPE_SECRET_KEY)
- Select which environment each applies to (Production, Preview, Development)
Cloudflare Pages:
- Go to your project in Cloudflare dashboard
- Settings → Environment Variables
- Add your secrets (DATABASE_URL, etc.)
- These are available at runtime, not during build
The Rule
| Variable Type | Prefix | Where It Lives | Example |
|---|---|---|---|
| Public | NEXT_PUBLIC_ or PUBLIC_ | Client bundle (visible to everyone) | PUBLIC_SITE_URL |
| Build | None | Build pipeline only | CMS_API_TOKEN |
| Runtime (Secret) | None | Server environment only | DATABASE_URL, JWT_SECRET |
The test: Grep your built output for the variable name. If it appears in any JS file, it’s leaking to the client.
05. Platform Comparison
| Feature | Vercel | Netlify | Cloudflare Pages | AWS Amplify |
|---|---|---|---|---|
| Edge Runtime | V8 (V8 Isolates) | Deno | V8 (Workers) | Lambda@Edge |
| Framework Support | Next.js (first-class), Astro, SvelteKit | Astro, SvelteKit, 11ty | Any (static or Functions) | Any (via buildpacks) |
| Preview Deployments | ✅ Automatic | ✅ Automatic | ✅ Automatic | ❌ Manual |
| Analytics | Built-in (Web Vitals) | Basic analytics | Full analytics suite | CloudWatch integration |
| Pricing | Generous free tier, usage-based | Generous free tier | Free for most sites | Pay-per-use |
| Best For | Next.js apps, full-stack | Static sites, JAMstack | Global edge, Workers | Enterprise AWS |
| CI/CD | Git push → auto deploy | Git push → auto deploy | Git push → auto deploy | Git push → auto deploy |
| Custom Domains | Free SSL, easy setup | Free SSL, easy setup | Free SSL, easy setup | Route 53 integration |
The Recommendation
Building a Next.js app? → Use Vercel (first-class support, preview deployments, analytics)
Building a static site (Astro, Hugo)? → Use Cloudflare Pages (free, fast, edge Workers available)
Need server-side logic? → Use Vercel or Netlify (both support serverless functions)
Any other case? → Pick by preference — all platforms work for most projects.
06. Preview Deployments
Preview deployments create a unique, shareable URL for every pull request. Stakeholders review the live app before merging to production.
How It Works
- Developer pushes a feature branch
- CI/CD pipeline builds the project
- Deploy to unique URL:
feature-branch-abc123.vercel.app - PR comment: “Preview: https://feature-branch-abc123.vercel.app”
- Designer reviews UI changes
- QA tests on the live preview
- Merge to main → auto-deploys to production ▼ Deploy to unique URL: feature-branch-abc123.vercel.app │ ├──▶ PR comment: “Preview: https://feature-branch-abc123.vercel.app” │ ├──▶ Designer reviews UI changes │ ├──▶ QA tests on the live preview │ └──▶ Merge to main → auto-deploys to production
### Vercel Configuration
**Tell your AI tool:**
"Configure Vercel for preview deployments:
- Auto-comment on PRs with preview URL
- Set preview function timeout to 30 seconds
- Use a separate DATABASE_URL_PREVIEW for preview deployments"
### The Preview Database Pattern
Never point preview deployments at production databases. Use a separate preview database or database branch.
**Tell your AI tool:**
"Add environment variable routing: if VERCEL_GIT_COMMIT_REF is 'main', use DATABASE_URL (production). Otherwise, use DATABASE_URL_PREVIEW (development). This prevents preview deployments from affecting production data."
---
## 07. Rollback Strategies
When a deployment breaks production, the fastest recovery is rolling back to the last known good state.
### Platform Rollbacks
```bash
# Vercel — instant rollback (zero-downtime)
vercel rollback
# Netlify — rollback via dashboard or CLI
netlify api rollbackSiteDeploy --data '{"deploy_id":"PREVIOUS_DEPLOY_ID"}'
# Cloudflare Pages — rollback via dashboard
# Pages → Deployments → find previous → click "Rollback to this deployment"
The Rollback Checklist
- DETECT — Monitoring alerts fire (error rate spike, latency spike)
- ASSESS — Is it user-facing? How many users affected?
- DECIDE — Rollback or hotfix?
- ROLLBACK (fastest, safest):
vercel rollbackin dashboard or CLI — takes ~30 seconds - HOTFIX (if rollback isn’t possible):
git revert HEAD→ push → CI/CD auto-deploys
- ROLLBACK (fastest, safest):
- VERIFY — Check monitoring dashboard, error rate returns to baseline
- RETROSPECTIVE — What caused the issue? How to prevent it next time?
Database Rollback
If a migration caused the issue, you have two options:
Option 1: Rollback the migration If your migration tool supports rollback (Drizzle, Prisma), run the rollback command to undo the last migration.
Option 2: Create a forward-fix migration (safer) Instead of rolling back, create a new migration that undoes the problematic change. This preserves your migration history and is easier to reason about.
Tell your AI tool: “Create a migration that undoes the previous change. If the last migration added a column, this one should drop it. Always write a rollback path for every migration.”
The Rule: Make Rollbacks Easy
If your rollback process takes more than 5 minutes, your deployment architecture is too complex. Simplify until rollback is a single command.
08. Custom Domains & SSL
Domain Setup
Step 1: Add your domain in your platform dashboard (Vercel → Settings → Domains)
Step 2: Configure DNS at your domain registrar:
- Option A (recommended): Add a CNAME record pointing to your platform (e.g.,
playbook CNAME cname.vercel-dns.com) - Option B: Add an A record pointing to your platform’s IP address
Step 3: Wait for DNS propagation (usually 5-30 minutes). Verify with online tools like dnschecker.org.
SSL/TLS Configuration
Vercel/Cloudflare/Netlify: SSL is automatic. You don’t need to configure anything.
Verify SSL is working: Visit your site and check for the padlock icon in the browser. Or run: curl -I https://yourdomain.com and look for Strict-Transport-Security header.
Force HTTPS redirect: Usually automatic. If not, add a redirect rule in your hosting dashboard.
DNS Propagation Timeline
| Action | Typical Time | Worst Case |
|---|---|---|
| Add CNAME record | 5-30 minutes | 48 hours |
| Update existing record | 5-15 minutes | 24 hours |
| SSL certificate issuance | Instant (Let’s Encrypt) | 5 minutes |
| Global propagation | 5-30 minutes | 48 hours |
The senior move: Lower TTL to 300 (5 minutes) 48 hours before making DNS changes. This ensures old records expire quickly.
09. Deployment Checklist
Pre-Deploy
□ All environment variables set in platform dashboard
□ No secrets in client bundle (grep for NEXT_PUBLIC_ with secret values)
□ Build succeeds in clean environment (no local node_modules)
□ Database migrations tested against staging database
□ Preview deployment reviewed and approved
Deploy
□ Push to main triggers CI/CD pipeline
□ Build passes (lint, type check, test, build)
□ Deployment URL accessible and functional
□ SSL certificate active (HTTPS enforced)
□ Custom domain resolves correctly
Post-Deploy
□ Health check endpoint returns 200
□ Monitoring dashboards show normal metrics
□ Error rate within baseline (no spike)
□ Page load performance within budget (< 2.5s LCP)
□ Rollback command tested and ready
Ongoing
□ Monitor for 24 hours after major changes
□ Cache purge triggered if stale content detected
□ SSL auto-renewal verified (Let's Encrypt)
□ Branch protection rules enforced on main
Key Takeaways
| Concept | Mental Model | Senior Insight |
|---|---|---|
| Single Server Fallacy | One location = high latency for global users | CDN reduces TTFB from 300ms to 15ms for distant users |
| CDN | Globally distributed cache + compute | Edge nodes serve static files; origin serves dynamic data |
| Edge Computing | Code executes at the edge, not just caches | Use for A/B testing, URL rewriting, JWT validation — not database queries |
| Caching Headers | Control how long files are remembered | Hashed assets: cache forever. Dynamic HTML: stale-while-revalidate |
| Build vs Runtime | Variables needed at compile time vs execution time | PUBLIC_* in client bundle, secrets in server environment only |
| Preview Deployments | Every PR gets a unique live URL | Never point previews at production databases |
| Rollback | Fastest recovery is reverting to last good state | If rollback takes >5 min, architecture is too complex |
| Custom Domains | CNAME or A record + automatic SSL | Lower TTL before DNS changes, verify with dig/nslookup |