Skip to content

Multi-region Durable Objects

Use multi-region DO routing when each owner (or each geography) should run on a Durable Object colocated with their Postgres read replica. You still deploy one Arivie instance per owner (no shared mode); the Worker only picks which named DO stub receives the request.

Deploy targets — Cloudflare DO card

Base example: examples/with-cloudflare-do/.

Extend wrangler.toml with one DO binding per region (names illustrative):

[[durable_objects.bindings]]
name = "ARIVIE_DO_EU"
class_name = "ArivieDO"
[[durable_objects.bindings]]
name = "ARIVIE_DO_US"
class_name = "ArivieDO"

In src/worker.ts, derive the stub name from request.cf?.colo or an X-Arivie-Region header your gateway sets:

const region = request.headers.get("X-Arivie-Region") ?? "us";
const binding =
region === "eu" ? env.ARIVIE_DO_EU : env.ARIVIE_DO_US;
const id = binding.idFromName(ownerId);
return binding.get(id).fetch(request);

Each DO continues to call getArivieRuntime(env) with region-specific DATABASE_URL secrets. No new example directory is required — patch the canonical CF DO example.

Terminal window
cd arivie && pnpm install
pnpm --filter with-cloudflare-do build
wrangler dev
curl -X POST http://127.0.0.1:8787/api/arivie -H 'X-Arivie-Region: eu' -H 'Content-Type: application/json' -d '{"prompt":"How many customers?"}'