We built our AI chat on Cloudflare, and for a while that was the only sensible decision. Workers gave us a global edge runtime. D1 gave us SQLite. R2 gave us object storage. KV gave us state. Vectorize gave us embeddings. Workers AI gave us models. One vendor, one bill, zero operations. When you are a small team shipping a widget, that is not a trap. It is a tailwind.
Then we looked at the words on our own pricing page and noticed the trap anyway.
The moment we noticed
We sell a self-host tier. The promise is “your data stays with you, the code is yours forever.” A customer hears that and imagines a Docker image they can run on their own server.
What we actually had to offer was: deploy the same code to your own Cloudflare account, with your own API keys.
That is not self-host. That is a different Cloudflare account.
The realization was uncomfortable. Our product was not locked to Cloudflare the way a SaaS is locked to its own hosting. It was locked the way a recipe is locked to a specific brand of oven. The code could not leave.
So we asked the question every engineer should ask before it becomes an emergency: what, exactly, is actually locked?
What was actually locked
We grepped our own codebase instead of guessing. The answer surprised us in both directions.
Two backends were already free. AI was a switch (AI_PROVIDER: Cloudflare, OpenAI, Anthropic, or any OpenAI-compatible endpoint). File storage was an interface (StorageProvider) with an R2 implementation and an S3 implementation. We had decoupled the expensive, opinionated parts without planning to.
The actual lock was smaller and dumber: the runtime, the database, the key-value store, and the vector index. Four bindings, reached through one env object. The database alone was touched by fifteen files — but the slice of its API we actually used was five methods: prepare, bind, all, first, run, plus batch. No exec, no raw, no dump.
That was the whole wall. Five methods.
The blocks, and what each one is for
A chat is a small list of jobs. Once you name the jobs, the lock-in question answers itself. Here is our list.
| Block | What it is for | On Cloudflare today | Off-Cloudflare |
|---|---|---|---|
| Runtime | Serves HTTP, runs every endpoint and the admin UI | Workers | Node.js (Astro’s Node adapter) |
| Database | The multi-tenant model: projects, messages, plans, quotas | D1 (SQLite) | SQLite (better-sqlite3) or Postgres |
| Object storage | File attachments — images, PDFs | R2 | S3 / MinIO / B2 |
| Key-value store | Sessions, rate limits, chat-state mirror, language markers | Workers KV | Redis |
| Vector index | RAG and the semantic answer cache | Vectorize | pgvector / Qdrant |
| AI | Chat, embeddings, vision, transcription | Workers AI (default) | OpenAI / Anthropic / any OpenAI-compatible endpoint |
| Operator handoff over email | Cloudflare Email Workers | Mailgun / SES / Postal webhook | |
| Scheduler | Retention sweeps, usage snapshots | Workers cron | node-cron |
Notice which column is the odd one out: none of the jobs is “be Cloudflare.” Cloudflare is just the vendor that happens to fill most of the slots today. Each slot has a port; each vendor is an adapter.
The method: ports, not a rewrite
There is a name for what we did next, and it is older than serverless: hexagonal architecture, or “ports and adapters.”
A port is an interface that describes what the code needs. An adapter is the thing that satisfies it. The business logic talks to the port. Cloudflare becomes one adapter among several.
We did not rip Cloudflare out. We drew a line through the codebase so it could leave if it wanted to.
The database port is the best example, because it is embarrassingly small:
interface DbStatement {
bind(...params: any[]): DbStatement;
all<T>(): Promise<{ results?: T[] }>;
first<T>(column?: string): Promise<T | null>;
run(): Promise<{ meta?: any }>;
}
interface Database {
prepare(query: string): DbStatement;
batch(statements: DbStatement[]): Promise<unknown[]>;
}
That is it. D1 is SQLite, so this port does not emulate anything — it is just the five methods we already used. Behind it, an adapter can point at D1, at libSQL or Turso, at better-sqlite3 on a Node server, or at Postgres through a thin shim. Same SQL, same schema.
The same pattern now covers the key-value store (KvStore: get, put, delete, list — currently Cloudflare KV, replaceable by Redis) and the vector index (VectorStore: query, upsert, deleteByIds — currently Vectorize, replaceable by pgvector or Qdrant).
Where this actually stands
We try to document these things honestly, so here is the honest status, not the slide-deck status:
- Done: AI (provider switch) and storage (S3 adapter) were already portable.
- Done: the database, KV, and vector call sites all route through ports now; the raw
env.DB/env.KV/env.VECTORSbindings are gone from the core. - Done: the runtime port — a parallel
@astrojs/nodebuild, node-cron for the sweeps, and the inbound-email webhook stand in for the Workersscheduled()/email()handlers. - The remaining gap: a Docker image is now a
docker compose upaway, but the referenceDockerfilestill needs the database migrations applied and an end-to-end run before we call it “shipping.”
What we get for the trouble
A Docker image that runs on any Linux box: Node, SQLite or Postgres, Redis, pgvector, and an S3-compatible bucket. No Cloudflare inside it.
That is the difference between selling “your own Cloudflare account” and selling “your own server.” The first is a hosting detail. The second is the reason an enterprise customer trusts you with their data.
And we keep the tailwind. We stay on Cloudflare for the SaaS, where it is genuinely cheap and genuinely zero-ops. We just refuse to let it be the only place the product can live.
Vendor lock-in is not a fate. It is a decision you make one binding at a time — or unmake, one port at a time.