Introduction to Apache Cassandra
Apache Cassandra is a NoSQL database. NoSQL means it does not work like the classic table-and-join databases such as MySQL. Cassandra is built to store a very large amount of data on many servers at the same time. It keeps working even when some of those servers stop.
Cassandra was first built at Facebook. Today it is a free, open-source Apache project, and large companies like Netflix and Apple use it.
Some things will still look familiar. Data lives in tables, with rows and columns. You talk to Cassandra with a language called CQL (Cassandra Query Language), and CQL looks a lot like SQL:
SELECT name, department FROM employees WHERE id = 5;
Output:
name | department
------+------------
Emma | IT
(1 rows)
Don't worry about the details yet. You will write your first query in a couple of lessons.
What makes Cassandra different?
Cassandra makes very different choices from a relational database like MySQL:
| Relational (MySQL) | Cassandra | |
|---|---|---|
| Runs on | Usually one server | A group of many servers |
| To grow | Buy a bigger server | Add more servers |
| If a server stops | The database may stop | The other servers keep working |
| Joins and foreign keys | Yes | No |
| Best at | Complex queries | Fast reads and writes of huge data |
When should you use Cassandra?
Cassandra is a good choice when:
- You have a lot of data, more than one server can hold
- Your app must never go down, because there is no single server whose failure stops everything
- You write a lot of data, for example messages, logs or sensor readings
- Your users are all over the world, because Cassandra can keep copies of the data in many countries
It is the wrong choice when you need joins between tables or complex reports. A relational database is better for those.
Keep one idea in mind for the whole course. In Cassandra, you design each table around the queries you will run, not around the shape of your data. You will see this idea again and again.
Your first query is below, and it is already written for you. Hit Submit to see it run, then answer a short question.