Structure family

Counters

Alice, Bob, and Carol count birds on separate trails. Their notes reach each other late, out of order, or more than once. If a note carried only a running total, a late note could hide another hiker's birds. The three counters below solve that in three steps: keep a count for each hiker, add a second table for corrections, then let a ranger station number every change.

Three kinds of field record sit beside binoculars: an open notebook, a two-page notebook, and a curled sequence log.
CRDT Complexity Introductory

G-counter

A counter that can only go up.

g_counter_kernel

Each person keeps their own count. When people share their counts, the counter keeps the highest number reported by each person and adds them together. A repeated or late message cannot add the same work twice.

Best for

  • Totals that only increase
  • Offline work and unreliable delivery
Updates
Increment only
How copies combine
Keep each person's highest count
What it remembers
One number per person
Open the G-counter lesson
CRDT Complexity Intermediate

PN-counter

A counter that can go up or down.

pn_counter_kernel

A PN-counter uses two G-counters. One records increases and the other records decreases. The visible total is the increases minus the decreases.

Best for

  • Totals that need corrections
  • Offline work and unreliable delivery
Updates
Increment and decrement
How copies combine
Keep each person's highest count in both tables
What it remembers
Two numbers per person
Open the PN-counter lesson
DDS Complexity Intermediate

SharedCounter

A counter that sends every change through a sequencer.

counter_kernel

This is the first structure that needs the ranger station. Each hiker sends every change there. The station numbers each change and sends the same numbered list to every hiker. Each hiker applies each number once, so a repeated note cannot count twice. Because every change arrives through one list, each hiker keeps only the total, not a count for every hiker.

Best for

  • Apps that already have a sequencer
  • Many writers, where a count for every writer would grow large
Updates
Increment and decrement
How changes apply
Apply each numbered change once, in order
What it remembers
The total, the last applied number, and any changes still waiting
Open the SharedCounter lesson