Apache Cassandra

Counters

Understand Cassandra's specialized counter column type for distributed increment/decrement operations.

Cassandra provides a special counter column type designed specifically for use cases requiring distributed, atomic increment and decrement operations — such as view counts, like counts, or aggregate metrics — without requiring a read-modify-write cycle at the application level.

A counter column is like several people simultaneously adding tally marks to a shared scoreboard from different locations, with someone reliably summing all the tally marks whenever anyone checks the current score — but if a marker isn't sure their mark was recorded and adds it again just in case, the score can drift slightly high.

Key Concepts

1
Counters have unique restrictions compared to regular columns: a table containing a counter column can only contain counter columns (besides the primary key) — you cannot mix counters with regular data columns in the same table. Counters also don't support setting an arbitrary value directly; you can only increment or decrement them by a delta.
only
2
Internally, counters historically had a reputation for correctness challenges (particularly around potential over/under-counting during replica or coordinator failures with retries), which drove significant re-engineering in later Cassandra versions to improve idempotency and accuracy. Modern Cassandra versions have substantially improved counter reliability, but they still fundamentally behave differently from normal columns: retried counter writes are not naturally idempotent the way a normal upsert is (retrying an increment can apply it twice), so applications must be cautious about retry logic on counter writes, especially across unreliable networks.
3
Because of these constraints and historical caveats, counters should be used specifically for aggregate numeric tracking use cases, not as a general-purpose numeric column replacement.