Clusters, Nodes and the Ring
One Cassandra server is called a node. Many nodes work together as a cluster, and your application talks to the cluster. A cluster often starts with three nodes and can grow to hundreds.
Cassandra places the nodes of a cluster in a circle called the ring:
+--------+
--> | Node A | ---
/ +--------+ \
+--------+ +--------+
| Node D | | Node B |
+--------+ +--------+
\ +--------+ /
--- | Node C | <--
+--------+
No master node
In many databases, one server is the main server (the master), and the other servers follow it. If the master stops, there is trouble.
Cassandra has no master node. All nodes are equal, and any node can take a read or a write. The node that gets your request is called the coordinator for that request. It sends the work on to the nodes that hold the data.
This is why Cassandra keeps working when a server fails. If Node B stops, the other nodes keep answering requests. There is no master to replace and no downtime.
How data is spread across nodes
Each row has a partition key. You will learn much more about it soon. Cassandra turns the partition key into a number with a hash function (a formula that turns any value into a number). That number decides which node stores the row.
Cassandra also keeps copies of each row on more than one node. This is called replication. Three copies is a common choice, so losing one node does not mean losing data.
INSERT a row with key 'alice'
|
v
hash('alice') = a number
|
v
the number belongs to Node B
(copies go to Node C and Node D too)
That is all the architecture you need for now. Remember two things:
- All nodes are equal, so there is no master that can fail
- The partition key decides where a row is stored, so it is the most important part of every Cassandra table
Answer a short question about masters and nodes below.