Expand description
Clustered single-writer ownership via a Postgres lease row per stream.
One row per active stream — (stream_key, owner_replica_id, epoch, expires_at). try_acquire is INSERT … ON CONFLICT … WHERE expired-or-ours
(so it both claims a free stream and reaps an expired one — the shared poll
loop is the reaper/takeover, spec §3.3); the owner extends expires_at via
heartbeat/renew; renew failing is how a replica learns its lease was
stolen. Expiry uses the Postgres clock (now() + make_interval) so it is
immune to per-replica clock skew. owns answers from an in-memory mirror of
held leases (cheap, for the poll hot path); the UNIQUE(stream_key, seq)
store constraint plus the epoch fencing token are the two-writer backstops.
Structs§
- Leased
Ownership - Clustered
Ownership: a Postgres lease per stream (spec §3.3).