Book Image

Mastering Apache Cassandra

By : Nishant Neeraj
Book Image

Mastering Apache Cassandra

By: Nishant Neeraj

Overview of this book

<p>Apache Cassandra is the perfect choice for building fault tolerant and scalable databases. Implementing Cassandra will enable you to take advantage of its features which include replication of data across multiple datacenters with lower latency rates. This book details these features that will guide you towards mastering the art of building high performing databases without compromising on performance.</p> <p>Mastering Apache Cassandra aims to give enough knowledge to enable you to program pragmatically and help you understand the limitations of Cassandra. You will also learn how to deploy a production setup and monitor it, understand what happens under the hood, and how to optimize and integrate it with other software.</p> <p>Mastering Apache Cassandra begins with a discussion on understanding Cassandra’s philosophy and design decisions while helping you understand how you can implement it to resolve business issues and run complex applications simultaneously.</p> <p>You will also get to know about how various components of Cassandra work with each other to give a robust distributed system. The different mechanisms that it provides to solve old problems in new ways are not as twisted as they seem; Cassandra is all about simplicity. Learn how to set up a cluster that can face a tornado of data reads and writes without wincing.</p> <p>If you are a beginner, you can use the examples to help you play around with Cassandra and test the water. If you are at an intermediate level, you may prefer to use this guide to help you dive into the architecture. To a DevOp, this book will help you manage and optimize your infrastructure. To a CTO, this book will help you unleash the power of Cassandra and discover the resources that it requires.</p>
Table of Contents (17 chapters)
Mastering Apache Cassandra
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Index

Preface

Back in 2007, Twitter users experienced the fail whale, occasionally captioned with "Too many tweets...". On August 3, 2013, Twitter posted a new record of high tweets rate of 143,199 per second, and we rarely see the fail whale. Many things changed since 2007. People and things connected to the Internet have increased exponentially. Cloud computing and hardware on demand has become cheap and easily available. Distributed computing and the NoSQL paradigm has taken off with a plethora of freely available, robust, proven, and open source projects to store large data sets and then process and visualize the data. Big data has become a cliché. With massive amounts of data that get generated at a very high speed via people or machines, our capability to store and analyze the data has increased. Cassandra is one of the most successful data stores that scales linearly, is easy to deploy and manage, and is blazing fast.

This book is about Cassandra and its ecosystem. The aim of this book is to take you through the basics of Apache Cassandra to understand what goes on under the hood. The book has three broad goals: the first is to help you to make the right design decisions and understand the patterns and anti-patterns, the second is to enable you to manage infrastructure and rainy days, and the third is to introduce you to some of the tools that work with Cassandra to monitor and manage Cassandra and to analyze the big data that you have inside it.

The book does not take a purist approach, rather a practical one. You will come to know proprietary tools, GitHub projects, shell scripts, third-party monitoring tools, and enough references to go beyond this book and dive deeper if you want.

What this book covers

Chapter 1, Quick Start, is about getting excited and gaining instant gratification. If you have no prior experience with Cassandra, you leave this chapter with enough information to get yourself started on the next big project.

Chapter 2, Cassandra Architecture, covers design decisions and Cassandra's internal plumbing. If you have never worked with a distributed system, this chapter has a lot of useful distributed design concepts. This chapter will be helpful for the rest of the book when we look at patterns and infrastructure management. It will also help you to understand the discussion of the Cassandra mailing list and JIRA. It is a theoretical chapter; you may skip it and come back later.

Chapter 3, Design Patterns, discusses various design decisions and their pros and cons. You will learn about Cassandra limitations and capabilities. If you are planning to write a program that uses Cassandra, this is the chapter for you. Do not miss Chapter 9, Introduction to CQL 3 and Cassandra 1.2 for CQL.

Chapter 4, Deploying a Cluster, is a full chapter about how to deploy a cluster correctly. Once you have gone through the chapter, you will realize it is not really hard to deploy a cluster. It is probably one of the simplest distributed systems.

Chapter 5, Performance Tuning, explains how to get the most out of the hardware the cluster is deployed on. Usually you will not need to rotate lots of knobs and the default is just fine.

Chapter 6, Managing a Cluster, is about the daily DevOps drills. For example, scaling up a cluster, shrinking it down, replacing a dead node, and balancing the data load across the cluster.

Chapter 7, Monitoring, talks about the various tools that you can use to monitor Cassandra. If you already have a monitoring system, you would probably want to plug Cassandra health monitoring to it, or you may choose to use dedicated Cassandra monitoring tools.

Chapter 8, Integration, Shows how to integrate Cassandra with other tools. Cassandra is about large data sets, fast writes, and reads terabytes of data. What is the use of data if you can't analyze it? Cassandra can be smoothly integrated with various Hadoop projects, and integrating with tools such as Spark and Twitter Storm is just as easy. This chapter gives you an introduction to get you started with setting up Cassandra and Hadoop setup.

Chapter 9, Introduction to CQL 3 and Cassandra 1.2, fills the version gap. At the time of writing this book, Cassandra's latest version was 1.1.11. The complete book uses that version and the Thrift API to connect to Cassandra. Cassandra 1.2 was released later and Cassandra 2.0 is also expected to be released anytime now. CQL 3 is the preferred way to query Cassandra, and Cassandra 1.2 has some interesting upgrades.

What you need for this book

If you have any development experience, this book should be easy to follow. A beginner level knowledge of Unix commands, Python, and some Java is good to speed up the understanding, but they are not absolute requirements.

In terms of software and hardware, a machine with 1 GB RAM and a dual core processor is the minimum requirement. For all practical purposes, any modern machine (your laptop from 2007 or newer) is good. You should have the following software installed: Python, Java development kit 6 (JDK), Cassandra 1.1.x, and Hadoop 1.1.x. The examples in this book are done in Ubuntu 11.10/13.04 and CentOS 5.5. So, if you have a Linux/Unix/OS X machine, that would be hugely beneficial. You may need to look for a Windows equivalent if it is your environment.

Who this book is for

This book is for anyone who is curious about Cassandra. A beginner can start from Chapter 1, Quick Start, and learn all the way up to advanced topics. If you have an intermediate level of experience, that is, you have worked on a toy project or better with Cassandra, you may skip to Chapter 2, Cassandra Architecture.

A DevOps engineer is probably the best job title who needs to read the book end to end. If you wear multiple hats during the day (very common in startups)—writing code, managing infrastructure, working on analytics, and evangelizing your product— you may find this book extremely useful.

Conventions

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

Code words in text are shown as follows: "Fire up your shell and type in $CASSANDRA_HOME/bin/cassandra -f."

A block of code is set as follows:

[default@unknown] USE crud;
Authenticated to keyspace: crud
[default@crud] CREATE COLUMN FAMILY test_cf
...	WITH                                   
...	DEFAULT_VALIDATION_CLASS = UTF8Type AND
...	KEY_VALIDATION_CLASS = LongType AND    
...	COMPARATOR = UTF8Type;                 

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

[default@unknown] USE crud;
Authenticated to keyspace: crud
[default@crud] CREATE COLUMN FAMILY test_cf
...	WITH                                   
...	DEFAULT_VALIDATION_CLASS = UTF8Type AND
...	KEY_VALIDATION_CLASS = LongType AND    
...	COMPARATOR = UTF8Type;                 

New terms and important words are shown in bold.

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 may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to , and mention the book title via 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 on 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 for all Packt books you have purchased from your account at http://www.packtpub.com. 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. You may also clone authors GitHub page for this book at https://github.com/naishe/mastering_cassandra.

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 would 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 on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright 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

You can contact us at if you are having a problem with any aspect of the book, and we will do our best to address it.