Repository navigation
Conversation
CockroachDB POC for the cell architecture. The Postgres dialect now detects CockroachDB from the crdb_version startup parameter and: - migrates a fresh database from one baseline (the final schema plus the seeded authz catalog, dumped from Postgres and transformed by migration/cockroach/transform.py), records every goose version, and locks migrations with a lease row instead of an advisory lock; - writes events without the advisory lock and bounds "settled" events with a fixed 5 s margin (a known gap, documented in event.go); - retries transactions that fail with SQLSTATE 40001. Portable fixes that also run on Postgres: RETURNING on data-modifying CTEs, jsonb_array_elements instead of a typed jsonb_to_recordset column list, and ::TEXT on authz arguments compared to each other. The cloud launcher takes CLOUD_CRDB_DATABASE_URL on a preview and then serves from it directly. vercel.json runs the server in fra1 and iad1 on this branch only, to measure latency from both regions. Storage contract tests on CockroachDB v26.1: 331 of 335 pass. The 4 left are the event cursor margin and one concurrency test. Postgres: all pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0156sXA5XcDpDy6mbvfGCSfu
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Schema-change jobs on a multi-region cluster take seconds each: the statement-by-statement baseline ran over 11 minutes on a simulated 3-region cluster and stalled the preview build. In one transaction the new tables need no jobs and the baseline takes about a minute. Triggers follow the commit (declarative schema changer only). An unfinished baseline (no versions recorded) is dropped and redone; the migration lock moves to the public schema for that. Adds a latency benchmark (build tag crdb_bench) for the sign-in path from each region's gateway. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0156sXA5XcDpDy6mbvfGCSfu
Member
Author
|
Generated by Claude Code |
regional.sql classifies the tables: end-user data (users, credentials, sessions, tokens, consents, events, ...) is REGIONAL BY ROW on a home_region column that defaults to the gateway's region, and a project policy (projects.data_region) overrides it through a BEFORE INSERT trigger. Configuration and catalogs are GLOBAL. regionalize.py turns baseline.sql into a setup that creates every table with its locality in one transaction (about 2.5 minutes on a simulated 3-region cluster, where converting existing tables took about a minute per table). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0156sXA5XcDpDy6mbvfGCSfu
Generated IDs can carry a region code in the first random character of their ULID (ZITADEL_ID_REGION). place_ids.py builds a schema where each per-user table derives its home region from that code, and keeps unique attribute values, hashed, in a GLOBAL table maintained by a trigger. The dialect reads unique lookups from that table when it exists. The latency bench gains an email lookup and per-gateway region codes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0156sXA5XcDpDy6mbvfGCSfu
… sin1 With ZITADEL_CRDB_REGIONS set, the migration makes the database span those regions and applies baseline_regional.sql (place_ids.py output with region placeholders), replacing a single-region schema. IDs take their region code from the Vercel region (ZITADEL_ID_REGIONS). With ZITADEL_CRDB_PROBE set, /api/__crdb_probe runs the sign-in path inside the function and reports its timings, also for users homed in other regions. This deployment pins the server to sin1 to probe from Asia. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0156sXA5XcDpDy6mbvfGCSfu
Checks are joined and looked up by their session or auth attempt, so they take their region from it. The unique index on a session's token ID made every token issue check all regions; the ID is minted, so the index is a plain one on CockroachDB. The migration records the hash of the regional baseline and replaces a schema made from another one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0156sXA5XcDpDy6mbvfGCSfu
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0156sXA5XcDpDy6mbvfGCSfu
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0156sXA5XcDpDy6mbvfGCSfu
A check's home_region follows its session or auth attempt, but CockroachDB cannot derive it from session_id or auth_attempt_id and searched every region. On the regional schema the statements now name the parent's region. Local three-region bench: get session 150 ms -> 2.5 ms. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0156sXA5XcDpDy6mbvfGCSfu
…al, restricted placement - withTransaction re-runs a transaction it opened after a serialization failure on CockroachDB; savepoints leave the retry to the outer one. The retry backoff gets jitter. - authz_assignments take their region from principal_id, which every authorization check reads them by, so the check stays in one region. - The database gets PLACEMENT RESTRICTED: a regional row keeps all its replicas in its home region. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0156sXA5XcDpDy6mbvfGCSfu
CockroachDB Cloud closes crdb_internal to SQL users, which failed the preview migration. Setting the policy again is a no-op. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0156sXA5XcDpDy6mbvfGCSfu
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0156sXA5XcDpDy6mbvfGCSfu
- Turn generic plans off on CockroachDB connections. A generic plan is made without the placeholder values, so it cannot compute a row's home region from its id and reads every region's partition; under plan_cache_mode=auto a statement switches to it after five runs (locally: 196 ms instead of 66 ms for one user's attributes). - Make authz_assignments, authz_membership_edges and resource_scope_index GLOBAL. Every check reads them by columns that do not hold the region, so a check read every region several times (p50 ~770 ms on the preview). The change runs as an in-place step after the baseline, so the existing schema and its data stay. - Tag telemetry with cloud.region from VERCEL_REGION. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0156sXA5XcDpDy6mbvfGCSfu
…tions - resource_scope_index goes back to REGIONAL BY ROW. Every new session and user writes a row there, and as a GLOBAL table each such write waited out the commit (create session 0.2 s -> 0.6 s from iad1). Its reads name the resource, whose id holds the region. - CockroachDB connections end a transaction left idle for 30 s. A function frozen mid-transaction kept its schema lease and stalled the locality change of the last deploy for over ten minutes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0156sXA5XcDpDy6mbvfGCSfu
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
Summary
crdb_versionstartup parameter and then:migration/cockroach/baseline.sql: the final schema plus the seeded authz catalog, generated from a migrated Postgres bygenerate.sh+transform.py), records every goose version, and locks migrations with a lease row instead of an advisory lock;event.go);RETURNINGon data-modifying CTEs,jsonb_array_elementsinstead of a typedjsonb_to_recordsetcolumn list,::TEXTon authz arguments compared to each other.CLOUD_CRDB_DATABASE_URLwhen it is set (branch-scoped only).vercel.jsonruns the server infra1andiad1on this branch to measure latency from both regions.Validation
ZITADEL_TEST_POSTGRES_URL=<local CockroachDB v26.1> go test -tags postgres_integration ./internal/storage/stmttest/: 331 of 335 top-level tests pass. Left: 3 event-cursor tests (the margin above) andTestUserPasswordStatements_HistoryUnderConcurrentChanges.ZITADEL_TEST_POSTGRES_URL=<local Postgres 18> go test -tags postgres_integration ./internal/storage/stmttest/ ./internal/storage/dialect/postgres/...: all pass.go test ./internal/storage/dialect/... ./cmd/cloud-launcher/: pass.Release notes / changeset
Notes
Generated by Claude Code