Repository navigation
Description
Follow-up to #902 item 4, which says one serving process per store database is supported but not enforced. This is an evaluation on 036e86d; items marked (unverified) were not reproduced.
What happens today with N urlcode serve processes on one host sharing the SQLite files
-
Store invariants hold. Idempotency-Key, intervals, transfers, quotas and the audit backlog are each checked in one
BEGIN IMMEDIATEtransaction. -
Store writes do not scale, and waiting blocks the event loop. Measured on macOS, Node 26.10, WAL and FULL sync:
Processes Commits/s 1 4.4k 2 6.3k 4 6.2k 8 6.7k Single stalls reached 1.4 s, and the 2 s busy timeout answers 503. With a real Linux fsync the total ceiling stays about 250 commits/s whatever N is (unverified). Reads scale.
-
Auth database has no WAL and busy_timeout 0 (
packages/auth/src/auth.ts:63).- A second writer gets "database is locked" at once, and a read during another process's commit fails.
authorize()turns that into a false 401. - This already affects
urlcode-auth create-userbeside a running server.
- A second writer gets "database is locked" at once, and a read during another process's commit fails.
-
Better Auth's rate limit is per process (an in-memory Map), so sign-in 10/min becomes 10·N.
rateLimit.storage: 'database'is atomic, buturlcode-auth migratenever creates its table, so it can't be enabled today. -
Processes on different declarations or releases break invariants.
- An older process keeps writing rows the newer declaration forbids (intervals, transfer
min, keys), and old SQL runs against a migrated schema. - The documented blue/green deploy (docs/OPERATIONS.md) already runs two servers on one database, which contradicts STORE.md.
- An older process keeps writing rows the newer declaration forbids (intervals, transfer
-
Throttle and origin cache are per process.
-
Audit drain is correct (
INSERT OR IGNOREon the id, ack by id, polled every 1 s), so STORE.md's "woken only in the writing process" overstates it. Edge case: a stalled drainer can re-insert an event already pruned past retention (unverified). -
The race tests use threads, not processes, so cross-process locking is never exercised.
Plan
Supported topology: N processes or containers on distinct ports behind a proxy, all on one release, on local disk. node:cluster stays unsupported.
- S auth: open auth.sqlite with
timeout: 2000, WAL and synchronous=FULL; decide whether Better Auth transactions needBEGIN IMMEDIATEor a retry. - S auth:
rateLimit.storage: 'database'by default;urlcode-auth migratecreates the table. - M store: a declaration and schema fence.
- Activation records each collection's declaration fingerprint and the schema version.
- Every write transaction checks both inside
BEGIN IMMEDIATE, and answers 503storage_unavailableon a mismatch.
- S-M refuse unsupported setups at activation:
- a network filesystem (
fs.statfs); - a peer on another host or boot id, detected through a lease/heartbeat table;
- warn that throttle and caches are per process.
- a network filesystem (
- S audit: a single drainer, through a lease.
- M Linux CI harness: 3 child server processes on one database set. It covers:
- the race suites run across processes;
- each audit event exactly once and in order;
- a sign-in burst with no false 401s and a global limit;
- a stale declaration gets 503;
kill -9during writes, then an integrity check.
- S docs: STORE, OPERATIONS (blue/green relies on the fence), CAPACITY, the throttle and cache pages, OBSERVABILITY.
Not planned: SQLite-backed throttle counters. They would put a write transaction on every throttled request, reads included.
Stays unsupported: multiple hosts
- WAL needs the
-shmfile on one kernel, and SQLite says WAL does not work over network filesystems. fcntllocking over NFS, SMB or EFS is unreliable.- Outbox ordering assumes one clock.
Multiple hosts would need a different storage backend and a shared limiter.
Activity
fix(auth): share auth.sqlite across processes: WAL, busy timeout, BEG…
Store: several serving processes on one host — declaration fence, set…
test(store): the multi-process harness checks audit events are stored…
test(store): a Linux multi-process harness in CI, and per-process thr…
One serving process per database: replace the host lease with an OS l…