Structure family

Counters

A shared number looks simple until several replicas change it at once. Counter designs differ in which changes they permit and what they must remember so repeated or reordered messages stay safe.

CRDT

G-counter

A grow-only counter for independent increments.

g_counter_kernel

Each replica owns one component and can only raise it. Merge keeps the largest value for every replica, so duplicate and reordered messages do not change the result.

Best for

  • Distributed metrics and tallies that never decrease
  • At-least-once delivery where an increment may be delivered again
Updates
Increment only
Merge rule
Per-replica maximum
Metadata
One integer per replica
Read the G-counter lesson

CRDT

PN-counter

A counter that preserves concurrent additions and corrections.

pn_counter_kernel

A PN-counter pairs two G-counters. One records positive changes and the other records negative changes. Each half merges by per-replica maximum, then the counter subtracts the negative total.

Best for

  • Offline counters that must increase and decrease
  • Corrections that may be delivered more than once
Updates
Increment and decrement
Merge rule
Maximum on both component sets
Metadata
Two integers per replica
Read the PN-counter lesson

DDS

SharedCounter

A signed counter whose operations pass through one sequencer.

counter_kernel

Each replica sends signed deltas to a sequencer. The sequencer assigns one sequence number and broadcasts the numbered operation. Replicas apply each sequence number once.

Best for

  • Shared totals under an ordered collaborative runtime
  • Small summaries where a sequencer already coordinates updates
Updates
Signed integer deltas
Application rule
Apply each sequence number once
Metadata
One integer plus pending operations
Read the SharedCounter lesson