CYDERCODER // PLAYBOOK
SYS.STATUS: OK 00%
> INITIALIZING...
Install this playbook for offline access
You're offline — reading cached content
WHO THIS IS FOR

Built for every stage of the builder journey

Beginners

Clear path from zero to deployed product in one afternoon. Exact AI prompts to copy. Explains the why, not just the how — all the way to production with a custom domain.

  • Build your first website end-to-end
  • Deploy with Vercel, set up Google Search Console
  • Understand what React is doing behind the scenes

Senior Devs

A reference manual for AI architecture decisions. RAG chunking, MCP, multi-agent systems, CDN caching, deployment strategies — without the fluff.

  • RAG chunking strategies, MCP protocol architecture
  • Typography scale, color theory, motion design systems
  • CDN caching, edge functions, deployment strategies
Portrait Lock Active
Please rotate your device back to Portrait orientation to read the playbook content.
Back to Dashboard

Deployment & Edge Infrastructure: Global Distribution

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 LocationRound Trip DistanceTypical TTFBUser Experience
New York~50 km~30msInstant
London~5,500 km~100msFast
Lagos~8,500 km~180msAcceptable
Mumbai~13,000 km~250msNoticeable delay
Tokyo~11,000 km~220msNoticeable delay
Sydney~16,000 km~300msFrustrating

With a CDN (Edge Nodes Everywhere)

User LocationEdge Node DistanceTypical TTFBUser Experience
New York~5 km~15msInstant
London~3 km~12msInstant
Lagos~50 km~25msInstant
Mumbai~20 km~20msInstant
Tokyo~10 km~15msInstant
Sydney~15 km~18msInstant

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

Step 1DNS
DNS Anycast Routing
DNS resolves to the NEAREST edge node (Lagos PoP, not US-East origin)
Step 2Edge
Edge Cache Check
Lagos PoP checks its local cache. HIT (~15ms): serve cached. MISS (~120ms): forward to origin.
Step 3Origin
Origin Server
Fetches from database, renders HTML, returns to Lagos PoP. PoP caches for future requests.

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.

PlatformEdge RuntimeWhat Runs at the Edge
VercelEdge Functions (V8 isolates)Middleware, API routes, ISR revalidation
CloudflareWorkers (V8 isolates)Full request handling, transforms, routing
NetlifyEdge Functions (Deno)Request rewriting, A/B testing, auth checks
AWSLambda@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

TaskEdgeOriginWhy
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 TypeCache-Control HeaderWhy
Hashed assets (main.a1b2c3.js)public, max-age=31536000, immutableFilename changes when content changes — cache forever
Fonts (inter-latin.woff2)public, max-age=31536000, immutableFonts rarely change — cache forever
Images (hero, thumbnails)public, max-age=2592000Cache 30 days — images change occasionally
Dynamic HTML (SSR pages)public, max-age=0, s-maxage=60, stale-while-revalidate=86400Serve stale instantly, refresh in background
API responses (public data)public, max-age=300Cache 5 minutes — balance freshness and speed
API responses (user data)private, no-cacheNever cache — always revalidate with server
Sensitive data (tokens, PII)no-storeNever cache, never store

Stale-While-Revalidate Explained

Stale-While-Revalidate Flow
Request
User requests page
Cache Check
Is cached copy under 60s old?
HIT
Serve stale instantly (~15ms)
Fetch fresh copy in background
MISS
Fetch from origin (~120ms)
Serve + cache for 60s

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

Build vs Runtime Variables
Build
PUBLIC_* variables
CMS API tokens
Analytics IDs
Output: Static HTML + JS
Runtime
DATABASE_URL
STRIPE_SECRET_KEY
JWT_SECRET
REDIS_URL

Platform Configuration

Vercel:

  1. Go to your project in Vercel dashboard
  2. Settings → Environment Variables
  3. Add build-time variables (CMS_API_TOKEN)
  4. Add runtime variables (DATABASE_URL, STRIPE_SECRET_KEY)
  5. Select which environment each applies to (Production, Preview, Development)

Cloudflare Pages:

  1. Go to your project in Cloudflare dashboard
  2. Settings → Environment Variables
  3. Add your secrets (DATABASE_URL, etc.)
  4. These are available at runtime, not during build

The Rule

Variable TypePrefixWhere It LivesExample
PublicNEXT_PUBLIC_ or PUBLIC_Client bundle (visible to everyone)PUBLIC_SITE_URL
BuildNoneBuild pipeline onlyCMS_API_TOKEN
Runtime (Secret)NoneServer environment onlyDATABASE_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

FeatureVercelNetlifyCloudflare PagesAWS Amplify
Edge RuntimeV8 (V8 Isolates)DenoV8 (Workers)Lambda@Edge
Framework SupportNext.js (first-class), Astro, SvelteKitAstro, SvelteKit, 11tyAny (static or Functions)Any (via buildpacks)
Preview Deployments✅ Automatic✅ Automatic✅ Automatic❌ Manual
AnalyticsBuilt-in (Web Vitals)Basic analyticsFull analytics suiteCloudWatch integration
PricingGenerous free tier, usage-basedGenerous free tierFree for most sitesPay-per-use
Best ForNext.js apps, full-stackStatic sites, JAMstackGlobal edge, WorkersEnterprise AWS
CI/CDGit push → auto deployGit push → auto deployGit push → auto deployGit push → auto deploy
Custom DomainsFree SSL, easy setupFree SSL, easy setupFree SSL, easy setupRoute 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

  1. Developer pushes a feature branch
  2. CI/CD pipeline builds the project
  3. Deploy to unique URL: feature-branch-abc123.vercel.app
  4. PR comment: “Preview: https://feature-branch-abc123.vercel.app”
  5. Designer reviews UI changes
  6. QA tests on the live preview
  7. 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

  1. DETECT — Monitoring alerts fire (error rate spike, latency spike)
  2. ASSESS — Is it user-facing? How many users affected?
  3. DECIDE — Rollback or hotfix?
    • ROLLBACK (fastest, safest): vercel rollback in dashboard or CLI — takes ~30 seconds
    • HOTFIX (if rollback isn’t possible): git revert HEAD → push → CI/CD auto-deploys
  4. VERIFY — Check monitoring dashboard, error rate returns to baseline
  5. 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

ActionTypical TimeWorst Case
Add CNAME record5-30 minutes48 hours
Update existing record5-15 minutes24 hours
SSL certificate issuanceInstant (Let’s Encrypt)5 minutes
Global propagation5-30 minutes48 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

ConceptMental ModelSenior Insight
Single Server FallacyOne location = high latency for global usersCDN reduces TTFB from 300ms to 15ms for distant users
CDNGlobally distributed cache + computeEdge nodes serve static files; origin serves dynamic data
Edge ComputingCode executes at the edge, not just cachesUse for A/B testing, URL rewriting, JWT validation — not database queries
Caching HeadersControl how long files are rememberedHashed assets: cache forever. Dynamic HTML: stale-while-revalidate
Build vs RuntimeVariables needed at compile time vs execution timePUBLIC_* in client bundle, secrets in server environment only
Preview DeploymentsEvery PR gets a unique live URLNever point previews at production databases
RollbackFastest recovery is reverting to last good stateIf rollback takes >5 min, architecture is too complex
Custom DomainsCNAME or A record + automatic SSLLower TTL before DNS changes, verify with dig/nslookup