Database / Apache Cassandra Intermediate and Advanced interview questions
What are counter columns in Cassandra and what are their limitations?
Counter columns are a special column type designed for distributed, atomic increment/decrement operations, such as tracking view counts or like counts, where many clients may update the same value concurrently.
CREATE TABLE page_views ( page_id text PRIMARY KEY, views counter ); UPDATE page_views SET views = views + 1 WHERE page_id = 'home';
- Unlike normal columns, counters cannot be set to an arbitrary value directly — only incremented or decremented relative to their current value.
- A table containing a counter column can only contain counter columns (besides the primary key) — you cannot mix counters and regular data columns in the same table.
- Counters have no TTL support, since a TTL'd partial increment would be ambiguous to reconcile.
- Because increments are applied as deltas rather than idempotent last-write-wins values, a client retry after a timeout can cause a double-counted increment if the original request actually succeeded server-side.
Counters are convenient for coarse-grained aggregate metrics, but for anything requiring exact correctness (billing, financial balances), most teams avoid relying on retry-prone counter increments and instead model the operation with idempotent writes or external reconciliation.
More Related questions...