Distributed Counter pattern

Whenever there is a need to maintain counters in applications that need to be persisted and distributed, use the Cassandra Counter data type in the column families. The distributed counter value is 64-bit long, supporting only two operations, namely increment and decrement. This is much better than storing the counter values in RDBMS tables, caches, log files, text files, and so on. In the latest version of Cassandra, the performance of the Counter data type has been improved a lot, and many issues have been fixed to allow it to support very powerful use cases.

Motivations/solutions

The need to use counters exists in most applications. If the application and the database lives in just one node, there is no issue and everything ...

Get Cassandra Design Patterns - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.