What are replication and the replication factor in Cassandra?
Understand Cassandra replication and the replication factor: how many copies of data are kept, per-keyspace config, and how RF works with consistency levels.
Expected Interview Answer
Replication in Cassandra means storing multiple copies of every row on different nodes, and the replication factor (RF) is the number of copies the cluster keeps for a keyspace.
The replication factor is set per keyspace, so an RF of 3 means each row lives on three distinct nodes chosen by the replication strategy walking the ring from the primary owner. Higher RF improves fault tolerance and read availability because more nodes can serve the data, but it costs more storage and write bandwidth. RF works together with the consistency level (like QUORUM) to decide how many replicas must acknowledge an operation before it is considered successful.
- Data survives node or disk failures
- Higher read availability across nodes
- Tunable durability per keyspace
- Supports multi-datacenter resilience
- Works with consistency levels to balance speed and safety
AI Mentor Explanation
Think of a team keeping several identical copies of the match scorebook in different dressing rooms. If one book is lost or a room is locked, the score is still safe because two more copies exist elsewhere. The replication factor is simply how many scorebooks you keep: RF of three means three dressing rooms each hold a full copy, so no single mishap wipes out the record of the innings.
Step-by-Step Explanation
Step 1
Define the keyspace
Replication is configured per keyspace, together with the replication strategy.
Step 2
Set the replication factor
Choose how many copies of each row the cluster keeps, e.g. RF = 3.
Step 3
Pick replica nodes
The strategy walks the ring from the primary owner to select RF distinct nodes for the copies.
Step 4
Write to replicas
A write is sent to all replicas; the consistency level decides how many must acknowledge.
Step 5
Read with consistency
Reads contact enough replicas to satisfy the consistency level, using read repair to fix stale copies.
What Interviewer Expects
- Definition of replication and replication factor
- That RF is set per keyspace, not per cluster
- The trade-off between durability and storage/write cost
- How RF interacts with consistency levels like QUORUM
- Understanding that copies live on distinct nodes
Common Mistakes
- Confusing replication factor with consistency level
- Thinking RF is set globally instead of per keyspace
- Assuming higher RF has no storage or write cost
- Believing all replicas must always acknowledge every write
- Placing all replicas on the same physical node or rack
Best Answer (HR Friendly)
“Replication means Cassandra keeps several copies of the same data on different servers so nothing is lost if one fails. The replication factor is simply how many copies it keeps — three is common — which trades a bit of extra storage for much stronger protection against outages.”
Code Example
CREATE KEYSPACE shop
WITH replication = {
'class': 'SimpleStrategy',
'replication_factor': 3
};
-- Every row in 'shop' is stored on 3 distinct nodes.
-- Reads/writes then use a consistency level, e.g. QUORUM,
-- which needs 2 of the 3 replicas to respond.Follow-up Questions
- How does the replication factor interact with the consistency level?
- What consistency level gives strong consistency at RF 3?
- Can you change the replication factor of an existing keyspace?
- What happens if RF is greater than the number of nodes?
- Why should replicas be spread across racks and datacenters?
MCQ Practice
1. What does a replication factor of 3 mean?
RF 3 means the cluster keeps three copies of every row, each on a different node, for fault tolerance.
2. Where is the replication factor configured?
The replication factor is defined per keyspace as part of its replication settings.
3. Which pairing achieves strong consistency with RF = 3?
QUORUM (2 of 3) on both reads and writes overlaps replicas, guaranteeing the latest value is seen.
Flash Cards
What is the replication factor? — The number of copies of each row the cluster keeps for a keyspace.
Where is RF set? — Per keyspace, in its replication configuration.
Does higher RF cost anything? — Yes — more storage and more write traffic in exchange for better durability and availability.
How does RF relate to consistency level? — RF sets how many copies exist; the consistency level sets how many must respond per operation.