PRO

Effect Fencing Token and Hybrid Clock

Two coordination primitives that keep a distributed write correct when leadership and time both misbehave. A lease manager mints strictly increasing fencing tokens through Ref.updateAndGet, and the protected resource remembers the highest token it has accepted and rejects any lower one, so a leader that was presumed dead during a GC pause or partition has its late write refused by the resource itself, not by a race it might win. Causality is carried by a Hybrid Logical Clock built on the Clock service, whose physical component is clamped so it never regresses, so event ordering survives a wall clock that jumps backward across a time sync. The whole thing is tested deterministically with TestClock across a five-minute backward jump. Solves split brain and clock skew. Pinned to effect 4.0.0-beta.98.

Install
npx shadcn@latest add @compronents/effect-fencing-token-hlc

Installs from ui.aryank.space. Needs a registry token and a one-time @compronents entry in components.json. The docs walk through both.

Visualization
fencing
accepted token
6
stale leader
Effect<void, never>
resource.write(data) // no token check, any writer lands

The old leader was presumed dead during a GC pause, a new leader took over at token 8, and then the old one woke up and wrote anyway. Watch the accepted token roll BACKWARD to 5: the resource just accepted a write from a leader that lost its lease. That is split brain.

Files
Checking access…
Dependencies