What are replication strategies (SimpleStrategy vs NetworkTopologyStrategy)?
Compare Cassandra SimpleStrategy vs NetworkTopologyStrategy: how each places replicas, per-datacenter RF, rack awareness, and why production uses network.
Expected Interview Answer
A replication strategy tells Cassandra which nodes hold the replicas of each row: SimpleStrategy places copies on consecutive nodes around the ring, while NetworkTopologyStrategy places them intelligently across racks and datacenters.
SimpleStrategy ignores physical topology and just walks clockwise from the primary owner to pick the next RF nodes, which is fine for a single-rack test cluster but risky in production. NetworkTopologyStrategy is rack- and datacenter-aware: you specify a replication factor per datacenter, and it spreads replicas onto distinct racks within each DC so a rack or DC failure does not take out every copy. Production deployments should always use NetworkTopologyStrategy, even with one datacenter, because it prepares the cluster for growth and fault isolation.
- NetworkTopologyStrategy survives rack and datacenter failures
- Per-datacenter replication factor control
- Enables local reads/writes with LOCAL_QUORUM in multi-DC setups
- SimpleStrategy is easy for quick single-DC testing
- Fault isolation by spreading replicas across racks
AI Mentor Explanation
Imagine storing spare match balls. SimpleStrategy is putting the three spares in the next three lockers in a row, so one flooded corridor can ruin all of them. NetworkTopologyStrategy is deliberately placing one spare in each of three separate pavilions on different sides of the ground, so no single flood, fire, or locked gate can leave the umpires without a usable ball for the game.
Step-by-Step Explanation
Step 1
Choose the strategy at keyspace creation
Specify 'class' as SimpleStrategy or NetworkTopologyStrategy in the replication map.
Step 2
SimpleStrategy placement
It picks the next RF nodes clockwise from the primary owner, ignoring racks and datacenters.
Step 3
NetworkTopologyStrategy placement
It reads the snitch's rack/DC info and spreads replicas across distinct racks per datacenter.
Step 4
Set per-DC replication factor
With NetworkTopologyStrategy you give each datacenter its own RF, e.g. {'dc1': 3, 'dc2': 3}.
Step 5
Query with locality
Use LOCAL_QUORUM so reads/writes stay within the local datacenter for low latency.
What Interviewer Expects
- The core difference between the two strategies
- That NetworkTopologyStrategy is rack- and DC-aware
- Why production should use NetworkTopologyStrategy even single-DC
- How per-datacenter RF is specified
- Awareness of the snitch's role in topology detection
Common Mistakes
- Using SimpleStrategy in a multi-datacenter production cluster
- Thinking the two strategies differ in number of copies rather than placement
- Forgetting that NetworkTopologyStrategy needs a proper snitch
- Ignoring rack awareness and clustering all replicas on one rack
- Not using LOCAL_QUORUM for datacenter-local latency
Best Answer (HR Friendly)
“A replication strategy decides where Cassandra puts the copies of your data. The simple one just uses the next servers in line, while the network-aware one spreads copies across different racks and locations on purpose, so a single failure can't wipe out every copy — which is why production always uses the network-aware option.”
Code Example
-- Simple: fine only for a single-rack dev cluster
CREATE KEYSPACE dev
WITH replication = {
'class': 'SimpleStrategy',
'replication_factor': 3
};
-- Production: rack- and datacenter-aware, RF per DC
CREATE KEYSPACE prod
WITH replication = {
'class': 'NetworkTopologyStrategy',
'us_east': 3,
'eu_west': 3
};Follow-up Questions
- What is a snitch and how does it inform NetworkTopologyStrategy?
- Why is SimpleStrategy discouraged in production?
- How does LOCAL_QUORUM improve latency in multi-DC clusters?
- How do you migrate a keyspace from SimpleStrategy to NetworkTopologyStrategy?
- How does rack awareness prevent correlated replica failures?
MCQ Practice
1. What makes NetworkTopologyStrategy different from SimpleStrategy?
NetworkTopologyStrategy is topology-aware, spreading replicas across distinct racks and datacenters, while SimpleStrategy just walks the ring.
2. Which strategy should a multi-datacenter production cluster use?
NetworkTopologyStrategy lets you set replication factor per datacenter and isolates faults across racks and DCs.
3. How is replication factor specified in NetworkTopologyStrategy?
You provide a replication factor for each named datacenter, e.g. {'dc1': 3, 'dc2': 2}.
Flash Cards
What does SimpleStrategy do? — Places RF replicas on consecutive nodes clockwise from the primary, ignoring racks and datacenters.
What does NetworkTopologyStrategy do? — Places replicas across distinct racks and datacenters, with a replication factor set per DC.
Which strategy for production? — NetworkTopologyStrategy — always, even single-DC, for fault isolation and future growth.
What component detects topology? — The snitch, which reports each node's rack and datacenter to the strategy.
Continue Learning
Related Interview Questions
How do you handle multi-datacenter deployments in Cassandra?
hard
What are replication and the replication factor in Cassandra?
easy
How does Cassandra achieve high availability and fault tolerance?
medium
How do racks and snitches affect replica placement, and what breaks when racks are configured unevenly?
hard