Agent-readable docs index: /docs/llms.txt. Full docs in one file: /docs/llms-full.txt. Download /docs/docs.zip to grep all markdown files locally.

Global Edge Network & Sub-10ms Redirects

Traditional link shorteners run on centralized cloud regions (such as AWS us-east-1). When a visitor in Tokyo or São Paulo clicks a short link, their request travels across submarine cables to a single data center and back — incurring 200–400ms of latency before the redirect even begins.
Shaf was designed from the ground up to solve this fundamental architectural flaw.

The Problem with Centralized Shorteners

Rendering diagram...
Every hop in a centralized architecture adds latency that users feel as hesitation before landing on the destination page — a particularly damaging experience on mobile campaigns where attention spans are measured in milliseconds.

The Shaf Edge Architecture

Shaf runs as a serverless application deployed across Cloudflare's Anycast network covering 300+ data centers globally.
Rendering diagram...
StepComponentLatency
DNS resolutionAnycast routing to nearest PoP~1–5ms
KV cache lookupWorkers KV read~1–2ms
D1 fallback (cache miss)Edge SQLite query~3–5ms
Device routing evaluationUser-Agent parsing< 1ms
Analytics writeNon-blocking, off critical path0ms
Total~5–10ms

Hybrid Storage: D1 + Workers KV

A common trade-off in distributed systems is consistency versus latency. Shaf uses a two-tier approach:
Cloudflare D1 (Authoritative Store)
An edge-native relational SQL database built on SQLite. D1 guarantees:
  • Transactional integrity for link CRUD operations
  • Strict schema validation via Drizzle ORM
  • Immediate consistency for team and billing operations
  • Full SQL querying for complex analytics aggregations
Workers KV (Read-Through Cache)
A globally replicated key-value store optimized for ultra-high read throughput:
  • Link lookups resolve in under 2ms from local cache
  • Automatically invalidated on any link edit or deletion
  • Handles billions of reads per month with consistent low latency
  • Eliminates D1 query cost for frequently accessed links
When a link is accessed for the first time after creation or update, the Worker reads from D1 and writes the result into KV. All subsequent requests hit KV directly — transparent to the visitor.

Non-Blocking Analytics

Tracking clicks must never slow down the visitor's redirect experience.
In Shaf, analytics data is emitted asynchronously using Cloudflare Analytics Engine:
// The redirect fires immediately — analytics are non-blocking ctx.waitUntil( env.ANALYTICS.writeDataPoint({ blobs: [country, city, device, browser, referrer], doubles: [1], indexes: [slug] }) ) return new Response(null, { status: 302, headers: { Location: destinationUrl } })
The ctx.waitUntil() API queues the analytics write off the critical request path — the HTTP redirect response is returned to the visitor instantly, while telemetry is committed in the background.

Why This Matters for Marketing Campaigns

SEO & Core Web Vitals
Google's Core Web Vitals (especially LCP) penalize slow initial navigations. A sub-10ms redirect is effectively invisible to browser performance metrics.
Mobile Campaign Performance
Mobile users on cellular networks experience the full benefit of edge proximity — a redirecting link is resolved at the nearest tower PoP rather than routing intercontinentally.
Zero Cold Starts
Unlike Lambda or Container-based shorteners, Cloudflare Workers have zero cold start latency. The first request after deployment is just as fast as the millionth.