Apache Cassandra

Snitch Types & Topology Awareness

Understand how snitches inform Cassandra about network topology to optimize replica placement and request routing.

Cassandra needs to know which machine is where. Not the IP address — which datacentre and which rack.

A snitch is like a company org chart that tells the mailroom which building and floor each employee sits on, so internal mail can be routed efficiently and backup copies of documents can be deliberately stored in different buildings rather than accidentally all ending up on the same floor.

Key Concepts

1
The component that answers is the snitch, and it feeds two decisions: where NetworkTopologyStrategy puts replicas, and which replica a coordinator prefers to read from.
NetworkTopologyStrategy
2
Why racks matter. Three replicas of a row give you nothing if all three are on the same rack, sharing a switch and a power feed. One failure takes all three.
3
With correct rack information, NetworkTopologyStrategy spreads the replicas across racks, so a rack failure costs one replica and a quorum still answers.
NetworkTopologyStrategy
4
The snitches you should know.SimpleSnitch — everything is one datacentre, one rack. Development only.
SimpleSnitch
5
GossipingPropertyFileSnitch — the production recommendation. Each node states its own datacentre and rack in a local file:
GossipingPropertyFileSnitch
6
    # cassandra-rackdc.properties
    dc=mumbai
    rack=rack1
7
That declaration then spreads to every node by gossip. Each machine holds one fact about itself rather than a full map of the cluster, so adding a node does not mean editing a file on all the others.
8
Ec2Snitch and Ec2MultiRegionSnitch — read AWS instance metadata and derive the datacentre from the region and the rack from the availability zone. GoogleCloudSnitch does the same on GCP.
Ec2SnitchEc2MultiRegionSnitchGoogleCloudSnitch
9
The failure mode is silence. Get the snitch wrong and nothing errors. Every node reports the default rack, NetworkTopologyStrategy has no reason to spread anything, and all three replicas land on one rack.
NetworkTopologyStrategy
10
You still have replication factor 3. You still see three copies. You have none of the fault tolerance you believe you have, and you find out during the rack failure.
11
So verify it rather than assuming: nodetool status shows each node's datacentre and rack, and every node should show the rack you expect.
nodetool status
12
Changing it later is disruptive. The snitch determines replica placement, so changing datacentre or rack names changes where data should live — and every affected row has to be streamed to its new home, with repair afterwards. Decide the naming before the cluster carries data.
13
The routing job. The snitch also lets the coordinator prefer a nearby replica, which is what keeps a read inside the local datacentre instead of crossing an ocean for no reason.
14
What the interviewer is probing.1. "What does a snitch do?" Probing: the purpose. Stalls: "Monitors nodes." Moves up: it tells Cassandra which datacentre and rack each node is in, which drives replica placement and request routing.
15
2. "Which snitch for a cloud deployment?" Probing: the practical choice. Stalls: "SimpleSnitch." Moves up: GossipingPropertyFileSnitch is the general recommendation, with cloud-specific snitches mapping regions and zones automatically.
16
3. "What happens if the snitch is wrong?" Probing: the consequence. Stalls: "Nothing." Moves up: replicas can be placed in the same failure domain, so a rack or zone failure takes every copy.
17
4. "Can you change the snitch on a live cluster?" Probing: the operational detail. Stalls: "Freely." Moves up: only with care — a topology change requires a full repair, since replica placement changes.