LWW Register Merge

easy · distributed-systems, crdt, conflict-resolution

LWW Register Merge

A Last-Write-Wins register stores a value with timestamp and node ID.

Merge rule:

  1. Higher timestamp wins.
  2. If timestamps tie, higher node ID wins.
  3. If both timestamp and node ID tie, lexicographically larger value wins.

The final value tie-breaker prevents argument-order-dependent behavior if malformed states appear.

Type

type LWW struct {
    Value string
    Timestamp int64
    NodeID int
}

Function signature

func MergeLWW(a, b LWW) LWW
Run tests to see results
No issues detected
    Join Discord