Home

GCounters

GCounters, short for G-Counters, are a type of grow-only conflict-free replicated data type (CRDT) used to implement distributed counters that converge without requiring coordination. They are designed for environments with eventual consistency, where multiple replicas may update independently and later synchronize.

In a GCounters implementation, each replica maintains a vector (an array) of counters, with one entry per

Merging states between replicas is done by taking the componentwise maximum of the two vectors. This merge

Limitations include the inability to perform decrements directly. To model decrements or more complex counting semantics,

Example: with three replicas A, B, and C, a state might be [2,0,0] after A increments twice.

replica.
The
value
at
index
i
represents
the
total
increments
performed
by
replica
i.
The
visible
total
counter
is
the
sum
of
all
vector
entries.
Operations
are
simple:
increment
on
a
replica
i
increases
vector[i]
by
one.
Importantly,
GCounters
are
grow-only:
there
are
no
decrement
operations.
rule
guarantees
convergence:
once
all
replicas
have
received
all
updates,
every
replica
stores
the
same
vector,
and
therefore
the
same
total
sum.
Because
individual
entries
never
decrease,
the
overall
counter
is
monotonic.
GCounters
are
often
composed
with
other
CRDTs,
such
as
PN-Counters,
which
use
a
G-Counter
for
increments
and
a
P-Counter
for
decrements.
GCounters
are
commonly
used
to
track
tallies
in
distributed
databases,
collaborative
applications,
and
systems
where
availability
and
partition
tolerance
are
prioritized
over
strict
synchronization.
If
B
increments
once,
the
states
merge
to
[2,1,0],
yielding
a
total
count
of
3.