MongoDB and HBase have this built-in (like most other databases that guarantee consistency).
One pretty simple trick with Cassandra is to have a specific string for a user number, and then insert a unique unique identifier (like a random UUID) with an empty value in it every time a user is added. At regular intervals, count the number of columns and put them in a total counter - deleting the columns you just counted.
At any time, your total user count is therefore [total counter] + [the number of columns in your user count row]. You can get them essentially with two readings, and if you have line cache enabled, it will be fast.
source share