FodyChat

From vendor lock-in to a portable core

We built on Cloudflare Workers, D1, R2, KV and Vectorize. Then we drew ports through the codebase so the product could run anywhere. Here is the honest status.

A diagram of FodyChat's ports (database, kv, vectors, ai, files, runtime) mapping to adapters (D1, Redis, pgvector, OpenAI, S3, Node)

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.

BlockWhat it is forOn Cloudflare todayOff-Cloudflare
RuntimeServes HTTP, runs every endpoint and the admin UIWorkersNode.js (Astro’s Node adapter)
DatabaseThe multi-tenant model: projects, messages, plans, quotasD1 (SQLite)SQLite (better-sqlite3) or Postgres
Object storageFile attachments — images, PDFsR2S3 / MinIO / B2
Key-value storeSessions, rate limits, chat-state mirror, language markersWorkers KVRedis
Vector indexRAG and the semantic answer cacheVectorizepgvector / Qdrant
AIChat, embeddings, vision, transcriptionWorkers AI (default)OpenAI / Anthropic / any OpenAI-compatible endpoint
EmailOperator handoff over emailCloudflare Email WorkersMailgun / SES / Postal webhook
SchedulerRetention sweeps, usage snapshotsWorkers cronnode-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:

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.