Counter column concepts

A counter is a special column used to store an integer that is changed in increments.

Counters are useful for many data models. Some examples:

  • Keeping track of the number of web page views received on a company website

  • Keeping track of the number of games played online or the number of players who have joined an online game

The table shown below uses id as the primary key and keeps track of the popularity of a cyclist based on thumbs up or thumbs down clicks in the popularity field of a counter table.


Tracking count in a distributed database presents an interesting challenge. At any given moment in CQL, the counter value could be stored in the memtable, commit log, or one or more SSTables. Replication between nodes can cause consistency issues in certain edge cases.

Because counters are implemented differently from other columns, counter columns can only be created in dedicated tables. A counter column must have the counter data type. This data type cannot be assigned to a column that serves as the primary key or partition key. To implement a counter column, create a table that only includes the primary key (one or more columns) and one or more counter columns.

Many counter-related settings can be set in the cassandra.yaml file.

Related information:

Was this helpful?

Give Feedback

How can we improve the documentation?

© 2024 DataStax | Privacy policy | Terms of use

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: +1 (650) 389-6000,