
Git-style commit history for runtime data using WeakMap and FinalizationRegistry
gist.github.comu/kurbsdude — 14 days ago

Using Date.now() to timestamp events across distributed systems is a fundamental flaw for two reasons:
Date.now() will record Worker B processing the event before Server A even sent it. This breaks log causality and silently corrupts Last-Write-Wins databases.Date.now() only offers millisecond precision. If a Node.js event loop processes 50 events in a single millisecond, they all receive the exact same timestamp, permanently destroying their true execution order.The academic solution to this is Vector Clocks, but those are heavy and difficult to implement. Modern distributed databases (like CockroachDB and Yugabyte) use Hybrid Logical Clocks (HLCs) internally, but there hasn't been a clean, drop-in HLC primitive available for app developers in the JS ecosystem.
liepoch is a zero-dependency, isomorphic library that solves the Date.now() problem by packing a 64-bit HLC into a universally sortable string.