hq-sanity

InSanity

Self-hosted Sanity Content Lake on Cloudflare Workers.
Your data. Your rules. ~$5/mo.

$ curl https://hq-sanity-router.emergenthqnet.workers.dev/

13 Cloudflare Services. One Content Lake.

Every service is wired end-to-end. No stubs. No dead code.

🗄

D1 (SQLite)

Document store with FTS5, composite indexes, GROQ-to-SQL pushdown

📦

R2 Storage

Asset uploads, CAS-backed history snapshots, schema persistence

🔒

Durable Objects

Real-time SSE listeners, scheduled publishing, per-tier rate limiting

📨

Queues

Async webhook delivery, history writes, embedding jobs via CDC bus

⚡

Cache API

SHA-256 keyed response cache with epoch-based invalidation via CDC

🧠

Workers AI

Semantic search embeddings, RAG chat with document context

📊

Analytics Engine

Per-request metrics, cost-weighted billing, slow-query detection

🕐

Cron Triggers

Nightly schema refresh, ANALYZE, CAS orphan GC, retention compactor

👁

Tail Workers

Structured observability logs forwarded from every request

🖼

Image Resizing

On-the-fly transforms via CfProperties — width, height, format, quality

🛡

Turnstile

Bot protection for public endpoints without requiring API tokens

⚙️

GROQ Engine

Full Rust GROQ parser, planner, executor — 151 tests, zero clippy warnings

📡

CDC Bus

Single distribute() call fans out to listeners, queues, cache, embeddings

Architecture


  Sanity Studio (browser)
       │
       ▼
  ┌─────────────────────────────────────────────────────┐
  │          hq-sanity-router (CF Worker)                │
  │                                                      │
  │  ┌──────────┐  ┌───────────┐  ┌──────────────────┐  │
  │  │ GROQ     │  │ Cache API │  │ Auth + Turnstile  │  │
  │  │ Engine   │  │ (SHA-256  │  │ + Rate Limit DO   │  │
  │  │ (Rust)   │  │  keyed)   │  │ (PermissionCell)  │  │
  │  └────┬─────┘  └─────┬─────┘  └──────────────────┘  │
  │       │              │                                │
  │  ┌────▼──────────────▼───────┐  ┌────────────────┐  │
  │  │     D1 (SQLite)           │  │  R2 (Assets +  │  │
  │  │  docs, refs, webhooks,    │  │  CAS History)  │  │
  │  │  embeddings, FTS5         │  │                │  │
  │  └───────────────────────────┘  └────────────────┘  │
  │                                                      │
  │  ┌──────────────── CDC Bus ──────────────────────┐  │
  │  │  distribute() → Listener DO (SSE)             │  │
  │  │               → Events Queue → Consumer       │  │
  │  │               → Cache invalidation            │  │
  │  │               → Auto-embed (Workers AI)       │  │
  │  │               → Schema observe                │  │
  │  └──────────────────────────────────────────────-┘  │
  └─────────────────────────────────────────────────────┘
       │                    │                    │
       ▼                    ▼                    ▼
  ┌──────────┐      ┌──────────────┐     ┌───────────┐
  │ Consumer │      │ Tail Worker  │     │ Analytics │
  │ (Queue)  │      │ (Observ.)    │     │ Engine    │
  └──────────┘      └──────────────┘     └───────────┘

Performance

Internal Worker timing (D1 query + GROQ eval). Network RTT not included.

2ms
Worker startup
<1ms
D1 query (same region)
0ms
Cache HIT
30KB
Wasm bundle

Live Latency Test

Click to fire 10 queries from your browser. Measures total RTT and internal Worker time.

GROQ Playground

Run queries against the live production dataset.

hq-sanity vs Sanity Cloud

Live side-by-side query from your browser. Same GROQ, two backends.

Cost Calculator

Drag the sliders. See the difference.

hq-sanity

$5
Workers + D1 + R2 + Queues (usage-based)

Sanity Cloud

$99
Team plan ($99/mo + overage)
Save 95% / month