Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Learning Apache Cassandra
  • Toc
  • feedback
Learning Apache Cassandra

Learning Apache Cassandra

By : Brown
4.4 (13)
close
Learning Apache Cassandra

Learning Apache Cassandra

4.4 (13)
By: Brown

Overview of this book

If you're an application developer familiar with SQL databases such as MySQL or Postgres, and you want to explore distributed databases such as Cassandra, this is the perfect guide for you. Even if you've never worked with a distributed database before, Cassandra's intuitive programming interface coupled with the step-by-step examples in this book will have you building highly scalable persistence layers for your applications in no time.
Table of Contents (14 chapters)
close
13
Index

Modeling follow relationships


A data model for follow relationships should be able to answer two questions on behalf of a user:

  • Who do I follow?

  • Who follows me?

In Chapter 3, Organizing Related Data, you learned to design our table structures so that all important data access can be accomplished by querying a single partition. For this reason, we're better off considering the above questions separately, and designing the right table schema for each.

Outbound follows

We'll start with the question, "Who do I follow?" We'll want a partition per user, with each partition containing all the other users they follow:

CREATE TABLE "user_outbound_follows" (
  "follower_username" text,
  "followed_username" text,
  PRIMARY KEY ("follower_username", "followed_username")
);

Simple enough, but there's something unusual here: there are only two columns in the table, and they're both part of the primary key. As it turns out, this is a perfectly valid way to construct a table schema; non-key columns are optional...

Unlock full access

Continue reading for free

A Packt free trial gives you instant online access to our library of over 7000 practical eBooks and videos, constantly updated with the latest in tech
bookmark search playlist font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete