Book Image

Learning Apache Cassandra - Second Edition

Book Image

Learning Apache Cassandra - Second Edition

Overview of this book

Cassandra is a distributed database that stands out thanks to its robust feature set and intuitive interface, while providing high availability and scalability of a distributed data store. This book will introduce you to the rich feature set offered by Cassandra, and empower you to create and manage a highly scalable, performant and fault-tolerant database layer. The book starts by explaining the new features implemented in Cassandra 3.x and get you set up with Cassandra. Then you’ll walk through data modeling in Cassandra and the rich feature set available to design a flexible schema. Next you’ll learn to create tables with composite partition keys, collections and user-defined types and get to know different methods to avoid denormalization of data. You will then proceed to create user-defined functions and aggregates in Cassandra. Then, you will set up a multi node cluster and see how the dynamics of Cassandra change with it. Finally, you will implement some application-level optimizations using a Java client. By the end of this book, you'll be fully equipped to build powerful, scalable Cassandra database layers for your applications.
Table of Contents (14 chapters)

Chapter 5. Establishing Relationships

At this point, we might declare our MyStatus application a minimum viable product. Users can create accounts and post status updates, and those status updates can be viewed in their authors' timelines. And, of course, since we're storing the data in Cassandra, we don't need to worry about scaling up to plenty of users and status updates.

As our service grows, however, it would be nice for users to be able to view all their friends' status updates in one place. The first step of that, of course, would be to know who a user's friends are. So, we'll build a feature that allows one user to follow another.

We've already seen a good way to use Cassandra to model a specific type of relationship. Compound primary keys are a natural fit for parent-child associations, but a follow relationship is many-to-many: I follow many users, and, hopefully, many users follow me.

In this chapter, we'll build on our knowledge of Cassandra data modeling and introduce new patterns...