LWW Register Merge

easy · distributed-systems, crdt, conflict-resolution

LWW Register Merge

A Last-Write-Wins (LWW) register stores a value with a timestamp and node ID. To merge two registers:

  • The higher timestamp wins.
  • If timestamps are equal, the higher NodeID wins.

Return the merged register.

Types

type LWW struct {
    Value     string
    Timestamp int64
    NodeID    int
}

Function signature

func MergeLWW(a, b LWW) LWW

Example

a = {Value:"x", Timestamp:10, NodeID:1}
b = {Value:"y", Timestamp:10, NodeID:2}
output = b
Run tests to see results
No issues detected