Book Image

Learning Apache Cassandra

By : Matthew Brown
4 (1)
Book Image

Learning Apache Cassandra

4 (1)
By: Matthew Brown

Overview of this book

Table of Contents (19 chapters)
Learning Apache Cassandra
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Recording discrete analytics observations


Let's say we want to keep very close track of how many times our users' status updates are viewed by someone else. Status updates may be viewed on the MyStatus web site, or by using our mobile app, or via a third-party app using our API. We'll want to track that, as well as which status update was viewed and when. To do this, let's create a table to store analytics observations:

CREATE TABLE "status_update_views" (
  "status_update_username" text,
  "status_update_id" timeuuid,
  "observed_at" timeuuid,
  "client_type" text,
  PRIMARY KEY (
    ("status_update_username", "status_update_id"),
    "observed_at"
  )
);

In this new table, we store a partition for each individual status update, with the full primary key of the status update serving as the partition key for our table. Each time someone views a status update, we'll store a new row in the table, generating a timestamp UUID for the row to populate the observed_at clustering column.

We'll also...