GCounter
A counter that only goes up. Each device owns its own slot; the total is the sum across all devices. On merge each slot keeps whichever value is larger — so the same increment seen from two devices is never double-counted.
Converges to: the total number of increments applied across all replicas, with no replica able to affect another's slot.
Merge rule
Each replica r owns slot r. inc(r, n) raises slot r by n. piece(a, b) takes element-wise max of every slot:
This is why merging doesn't double-count: the same increment, seen from two replicas, merges idempotently.
Code examples
Zero counter and summing across replicas:
Inc produces a delta:
Merge is element-wise max, not sum:
JSON round-trip:
When to use
Use GCounter when you only need to count up — events fired, messages sent, operations completed. For a counter that can also go down, see PNCounter. For a counter with a shared budget that must never be overdrawn, see BoundedCounter.