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

Preface

The crop of distributed databases that has come to the market in recent years appeals to application developers for several reasons. Their storage capacity is nearly limitless, bounded only by the number of machines you can afford to spin up. Masterless replication makes them resilient to adverse events, handling even a complete machine failure without any noticeable effect on the applications that rely on them. Log-structured storage engines allow these databases to handle high-volume write loads without blinking an eye.

But compared to traditional relational databases, not to mention newer document stores, distributed databases are typically feature-poor and inconvenient to work with. Read and write functionality is frequently confined to simple key-value operations, with more complex operations demanding arcane map-reduce implementations. Happily, Cassandra provides all of the benefits of a fully-distributed data store while also exposing a familiar, user-friendly data model and query interface.

I first encountered Cassandra working on an application that stored our users' extended social graphs across a variety of services. With a hundred or so alpha users in the system, it became clear that, even at relatively modest traction, our storage needs would go beyond what our PostgreSQL database could comfortably handle. After surveying the landscape of horizontally scalable data stores, we decided to migrate to Cassandra because its table-based data structure seemed to provide an easy migration path from the application we had already built.

Our first deployment of Cassandra ported our previous PostgreSQL schema table-for-table. Only after taking the application to production did we come to realize that our expertise designing schemas for a relational world didn't map directly to a distributed store such as Cassandra. While we were happy to be storing tons of data at very high write volumes, it was clear we weren't getting maximum performance out of the database.

The story has a happy ending: after a rough initial launch, we went back to the drawing board and reworked our data model from the ground up to take advantage of Cassandra's strengths. With that new version deployed, Cassandra effortlessly handled our application scaling to hundreds of thousands of users' social graphs.

The goal of this book is to teach you the easy way what we learned the hard way: how to use Cassandra effectively, powerfully, and efficiently. We'll explore Cassandra's ins and outs by designing the persistence layer for a messaging service that allows users to post status updates that are visible to their friends. By the end of the book, you'll be fully prepared to build your own highly scalable, highly available applications.

What this book covers

Chapter 1, Getting Up and Running with Cassandra, introduces the major reasons to choose Cassandra over a traditional relational or document database. It then provides step-by-step instructions on installing Cassandra, creating a keyspace, and interacting with the database using the CQL language and cqlsh tool.

Chapter 2, The First Table, is a walk-through of creating a table, inserting data, and retrieving rows by primary key. Along the way, it discusses how Cassandra tables are structured, and provides a tour of the Cassandra type system.

Chapter 3, Organizing Related Data, introduces more complex table structures that group related data together using compound primary keys.

Chapter 4, Beyond Key-Value Lookup, puts the more robust schema developed in the previous chapter to use, explaining how to query for sorted ranges of rows.

Chapter 5, Establishing Relationships, develops table structures for modeling relationships between rows. The chapter introduces static columns and row deletion.

Chapter 6, Denormalizing Data for Maximum Performance, explains when and why storing multiple copies of the same data can make your application more efficient.

Chapter 7, Expanding Your Data Model, demonstrates the use of lightweight transactions to ensure data integrity. It also introduces schema alteration, row updates, and single-column deletion.

Chapter 8, Collections, Tuples, and User-defined Types, introduces collection columns and explores Cassandra's support for advanced, atomic collection manipulation. It also introduces tuples and user-defined types.

Chapter 9, Aggregating Time-Series Data, covers the common use case of collecting high-volume time-series data and introduces counter columns.

Chapter 10, How Cassandra Distributes Data, explores what happens when you save a row to Cassandra. It considers eventual consistency and teaches you how to use tunable consistency to get the right balance between consistency and fault-tolerance.

Appendix A, Peeking Under the Hood, peels away the abstractions provided by CQL to reveal how Cassandra represents data at the lower column family level.

Appendix B, Authentication and Authorization, introduces ways to control access to your Cassandra cluster and specific data structures within it.

What you need for this book

You will need the following software to work with the examples in this book:

Further instructions on installing these are present in the upcoming chapters.

Who this book is for

This book is for first-time users of Cassandra, as well as anyone who wants a better understanding of Cassandra in order to evaluate it as a solution for their application. Since Cassandra is a standalone database, we don't assume any particular coding language or framework; anyone who builds applications for a living, and who wants those applications to scale, will benefit from reading the book.

Conventions

In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: "We can include other contexts through the use of the include directive."

A block of code is set as follows:

SELECT * FROM "users"
WHERE "username" = 'alice';

Any command-line input or output is written as follows:

$ sudo apt-get install cassandra

New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: "On this page, locate Windows Server 2008/Windows 7 or Later (32-Bit) from the Operating System menu (you might also want to look for 64-bit if you run a 64-bit version of Windows), and choose MSI Installer (2.x) from the version columns."

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail , and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at , and we will do our best to address the problem.