How it works
Every demo here is a real, working proof-of-concept on Cloudflare's actual platform. Not slideware. The whole site runs on Cloudflare Pages + Pages Functions; each bounty below is one primitive doing one job at the edge.
Scale-to-zero serverless: idle costs nothing. No Workers Paid plan required; the only recurring cost is the domain. (The Campfire voice is the one paid model, Deepgram Aura-2, and it's pre-baked to static audio so there's $0 per-use spend.)
Turnstile
Invisible verification
How it works
One script tag in your form, one check on your server. No infrastructure to run.
Add it to your site
~10 lines · no infrastructure<script src="https://challenges.cloudflare.com/turnstile/v0/api.js" defer></script>
<div class="cf-turnstile" data-sitekey="YOUR_SITEKEY"></div>const r = await fetch('https://challenges.cloudflare.com/turnstile/v0/siteverify', {
method: 'POST',
body: new URLSearchParams({ secret: env.TURNSTILE_SECRET, response: token }),
}).then((res) => res.json());
if (!r.success) return new Response('Blocked', { status: 403 });Official Cloudflare docs
Workers
AI-crawler control
How it works
Identify AI crawlers at the edge and decide per-caller: allow, charge, or block.
Add it to your site
1 dashboard toggle, or ~15 linesSecurity → Bots → "Block AI bots" / "Pay per crawl"
One toggle. Cloudflare maintains the crawler signatures for you.const ua = request.headers.get('user-agent') || '';
const bot = classifyAiCrawler(ua); // GPTBot, ClaudeBot, CCBot, PerplexityBot…
if (bot?.policy === 'block') return new Response('Forbidden', { status: 403 });
if (bot?.policy === 'license') return new Response('Payment required', { status: 402 });
return fetch(request); // humans pass straight throughOfficial Cloudflare docs
D1
Data residency
How it works
Route each write to the data store in the visitor's own jurisdiction, decided at the edge.
Add it to your site
~20 lines + 2 D1 bindingsconst country = request.cf.country; // free, at the edge
const eu = ['DE', 'FR', 'IE', 'NL' /* …EEA */];
const db = eu.includes(country) ? env.RESIDENCY_EU : env.RESIDENCY_US;
await db.prepare('INSERT INTO records (data) VALUES (?)').bind(payload).run();"d1_databases": [
{ "binding": "RESIDENCY_EU", "database_name": "app-eu" }, // created --jurisdiction eu (guaranteed EU)
{ "binding": "RESIDENCY_US", "database_name": "app-us" } // --location enam (US placement hint)
]Official Cloudflare docs
AI Search (AutoRAG)
Grounded trust assistant
How it works
Point AI Search at your docs; it answers with citations, or refuses when the answer is not there.
Add it to your site
dashboard setup + ~15 linesAI → AI Search → New
Data source: your R2 bucket or uploaded docs
Cloudflare chunks, embeds, and indexes them for you.const res = await env.AI.autorag('your-instance').aiSearch({
query: question,
});
return Response.json({ answer: res.response, citations: res.data });Official Cloudflare docs
Rate Limiting
Rate-limited floods
How it works
A Rate Limiting binding throttles abusive callers at the edge, before they ever reach origin.
Add it to your site
1 binding · a few lines"ratelimits": [
{ "name": "STAMPEDE_LIMITER", "namespace_id": "1001",
"simple": { "limit": 5, "period": 10 } }
]const ip = request.headers.get('CF-Connecting-IP') ?? 'anon';
const { success } = await env.STAMPEDE_LIMITER.limit({ key: ip });
if (!success) return new Response('Slow down', { status: 429 });Official Cloudflare docs
Cache / CDN
Edge caching
How it works
Cache the rendered response at the edge so the first visitor pays the cost once and everyone after is instant.
Add it to your site
~8 lines · no infrastructureconst cache = caches.default;
let res = await cache.match(request); // HIT?
if (!res) {
res = await renderExpensive(); // MISS: pay once
res.headers.set('Cache-Control', 'public, max-age=60');
ctx.waitUntil(cache.put(request, res.clone()));
}
return res;Official Cloudflare docs
D1 (atomic)
Atomic inventory
How it works
A single atomic D1 write guards the stock count, so concurrent buyers can never race it below zero.
Add it to your site
1 SQL statement · no raceconst { meta } = await env.DB.prepare(
'UPDATE stock SET qty = qty - 1 WHERE id = ?1 AND qty > 0'
).bind(productId).run();
const bought = meta.changes === 1; // 0 changes = sold out, no oversellOfficial Cloudflare docs
D1 · Pages Functions
Regulated messaging
How it works
Consent and quiet-hours enforced at send time, with every decision written to an append-only audit trail.
Add it to your site
D1 · gated + fully auditedconst localHour = ((sendHourUtc + r.tz_offset) % 24 + 24) % 24;
let decision;
if (!r.opted_in) decision = 'blocked'; // no consent (TCPA)
else if (localHour < 8 || localHour >= 21) decision = 'suppressed'; // quiet hours
else decision = 'sent';await env.DISPATCH_DB.prepare(
'INSERT INTO dispatch_audit (id, batch_id, recipient_id, decision, reason, created_at) VALUES (?, ?, ?, ?, ?, ?)'
).bind(id, batchId, r.recipient_id, decision, reason, new Date().toISOString()).run();
// rows are only ever inserted, never updated or deletedOfficial Cloudflare docs
Workers AI · pre-baked static
Campfire joke bot
How it works
A joke bot whose voice runs on Cloudflare. Generated once with Workers AI, then served as static audio for $0 per use.
Add it to your site
pre-baked → $0 per useconst r = await env.AI.run('@cf/meta/llama-3.3-70b-instruct-fp8-fast', {
messages: [{ role: 'system', content: COWBOY_PROMPT }, { role: 'user', content: 'Tell me a joke.' }],
});const audio = await env.AI.run('@cf/deepgram/aura-2-en', { text, speaker: 'zeus' });
// baked to /cowboy/jokes/<id>-zeus-<line>.mp3 -> served static, no per-use spendOfficial Cloudflare docs
D1
Defend the Edge leaderboard
How it works
A global leaderboard on D1: every submit is one atomic insert, with hashed-IP rate limiting at the edge.
Add it to your site
D1 · no read-modify-write raceawait env.LEADERBOARD_DB
.prepare('INSERT INTO leaderboard_scores (name, score, ip_hash, ts) VALUES (?, ?, ?, ?)')
.bind(name, score, ipHash, ts).run();const ipHash = await sha256(request.headers.get('CF-Connecting-IP')); // never store raw IP
const recent = await db.prepare('SELECT COUNT(*) c FROM leaderboard_scores WHERE ip_hash=? AND ts>?')
.bind(ipHash, Date.now() - 60_000).first();
if (recent.c >= 8) return json({ ok: false, error: 'rate limited' }, 429);Official Cloudflare docs