Title: D1 read replication is documented but never enabled or used · Issue #337 · voidzero-dev/void · GitHub
Open Graph Title: D1 read replication is documented but never enabled or used · Issue #337 · voidzero-dev/void
X Title: D1 read replication is documented but never enabled or used · Issue #337 · voidzero-dev/void
Description: Summary The docs promise "Database reads are fast everywhere via D1's read replication" (docs/guide/index), but nothing in void enables or uses it: databases are provisioned without read_replication, and void/db never calls withSession()...
Open Graph Description: Summary The docs promise "Database reads are fast everywhere via D1's read replication" (docs/guide/index), but nothing in void enables or uses it: databases are provisioned without read_replicatio...
X Description: Summary The docs promise "Database reads are fast everywhere via D1's read replication" (docs/guide/index), but nothing in void enables or uses it: databases are provisioned without r...
Opengraph URL: https://github.com/voidzero-dev/void/issues/337
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"D1 read replication is documented but never enabled or used","articleBody":"## Summary\n\nThe docs promise \"Database reads are fast everywhere via D1's read replication\" (`docs/guide/index`), but nothing in void enables or uses it: databases are provisioned without `read_replication`, and `void/db` never calls `withSession()`, so every query — including per-request auth lookups — always hits the D1 primary.\n\nDiscovered while investigating production 503s on a void-deployed app: the dispatch worker races `worker.fetch()` against a 10s deadline, and sequential D1 round trips to an APAC-primary database push the p99 tail past it.\n\n## Evidence\n\n- `platform/packages/api/src/provisioning/cloudflare-api.ts` — `createD1Database` posts only `{name}`; no `read_replication` config.\n- `packages/void/src/cli/provision.ts:4465` — `wrangler d1 create \u003cname> --binding ... --update-config` with no `--read-replication` flag; nothing writes `read_replication` into `d1_databases[]` config.\n- `packages/void/src/runtime/db.ts:60` — `db` proxy wraps `drizzle(requireRuntimeBinding('DB'))` on the raw binding. `D1Database.withSession()` / `D1DatabaseSession.getBookmark()` are never exposed.\n- `packages/void/src/runtime/better-auth.ts:9` — `resolveDatabase` passes `env.DB` directly to better-auth, so auth's per-request session+user lookups can't use a replica session either.\n- Repo-wide, `read_replication`/`withSession` appear only in the docs claim; no code or tests reference them.\n\n## Impact\n\nEvery D1 query in every void app pays a round trip to the database's primary region. For APAC-primary databases serving global traffic that's ~800ms+ per hop; auth middleware alone does 2+ sequential hops per request.\n\n## Suggested approach\n\n1. **Enable at provisioning**: `read_replication: { mode: \"auto\" }` on `createD1Database` (platform API path) and `wrangler d1 create --read-replication enabled` / wrangler config emission (CLI path).\n2. **Session API in `void/db`**: expose a per-request D1 session, e.g. `db.withSession(\"first-unconstrained\")` or a request-scoped drizzle instance via `getRuntimeRequestResource` (`env.ts` already has the plumbing). Drizzle's d1 driver only calls `prepare`/`batch`, which `D1DatabaseSession` supports — needs a type widening since `drizzle()` is typed against `D1Database`.\n3. **Auth path**: route `resolveVoidAuthState` / `runVoidAuthMiddleware` session lookups through a D1 session — biggest win, since every request's auth hops would hit the nearest replica with sequential consistency.\n","author":{"url":"https://github.com/Brooooooklyn","@type":"Person","name":"Brooooooklyn"},"datePublished":"2026-09-22T15:44:55Z","url":"https://github.com/voidzero-dev/void/issues/337"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:27377e9e-091b-ac5c-436d-e342541b9d17 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8074:1B6493:1D4237B:27BB414:6AFB9E78 |
| html-safe-nonce | 1a3aa3ddf6ab56e077ef49ac0baeb1d307edc956bde5ef3e7020fa2bdbd6d817 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MDc0OjFCNjQ5MzoxRDQyMzdCOjI3QkI0MTQ6NkFGQjlFNzgiLCJ2aXNpdG9yX2lkIjoiMzkyMzc3NDc3NTAwNzg3ODc3NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | f1a4fd5419a24723d6152c905871c219e93ac62762f17103804f289b0435a2a1 |
| hovercard-subject-tag | issue:5541873667 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/voidzero-dev/void/337/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7a0dc19e0b9683c5af055ce389846678f7790222f9a3413aecc90dfa20cbd303/voidzero-dev/void/issues/337 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7a0dc19e0b9683c5af055ce389846678f7790222f9a3413aecc90dfa20cbd303/voidzero-dev/void/issues/337 |
| og:image:alt | Summary The docs promise "Database reads are fast everywhere via D1's read replication" (docs/guide/index), but nothing in void enables or uses it: databases are provisioned without read_replicatio... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Brooooooklyn |
| hostname | github.com |
| expected-hostname | github.com |
| None | 3cefd19a936819d82cfb5279d50fb56fe79cb9ec30f0f807e04e89b0c58ffae1 |
| turbo-cache-control | no-preview |
| go-import | github.com/voidzero-dev/void git https://github.com/voidzero-dev/void.git |
| octolytics-dimension-user_id | 149750581 |
| octolytics-dimension-user_login | voidzero-dev |
| octolytics-dimension-repository_id | 1164437080 |
| octolytics-dimension-repository_nwo | voidzero-dev/void |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1164437080 |
| octolytics-dimension-repository_network_root_nwo | voidzero-dev/void |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 606800bdb1b81d125fc845bdcc262c9fe063fc8f |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width