Cassandra Architecture & Storage Internals
Module Duration: 5-6 hours
Learning Style: Architecture + Storage Engine + Hands-on Analysis
Outcome: Understand exactly how Cassandra stores and retrieves data at the lowest level
Why Architecture Matters
Most Cassandra tutorials show you CQL queries. This module goes deeper - understanding the architecture lets you:- Predict performance - Know why certain queries are fast/slow
- Design better schemas - Model data to match Cassandra’s strengths
- Debug production issues - Understand what’s happening under the hood
- Optimize clusters - Make informed tuning decisions
- Interview confidently - Explain trade-offs, not just features
We’ll explore the actual on-disk storage format, memory structures, and how data flows through the system. Bring your curiosity!
The Ring Topology Deep Dive
Why a Ring? (Historical Context)
The Problem with Master-Slave:Consistent Hashing Explained
The Core Problem: How do you distribute data evenly across N nodes, and minimize data movement when nodes are added/removed? Naive Approach (Hash Modulo):Virtual Nodes (Vnodes) - The Modern Approach
Problem with Single Token Per Node:Data Distribution & Replication
Replication Factor Deep Dive
Replication Factor (RF): Number of copies of each data partition. Common Configurations:Replication Strategies
1. SimpleStrategy (Single Datacenter):Snitch - Topology Awareness
What is a Snitch? Cassandra component that determines network topology (DC and rack of each node). Common Snitches:- SimpleSnitch (Default, single DC):
- GossipingPropertyFileSnitch (Most common):
- Ec2Snitch (AWS):
- GoogleCloudSnitch (GCP):
Storage Engine Internals
On-Disk Storage Structure
Cassandra Storage Hierarchy:CommitLog - Durability Guarantee
Purpose: Ensure no write is lost, even on node crash. How It Works:MemTable - In-Memory Write Buffer
Purpose: Fast writes + batching for efficient disk I/O. Structure:SSTable - Immutable On-Disk Storage
Key Property: Immutable - Never modified after written. Why Immutable?- Data.db - Actual data:
- Index.db - Partition Index:
- Summary.db - Partition Summary (in-memory):
- Filter.db - Bloom Filter:
- Statistics.db - Metadata:
Compaction Strategies
Why Compaction is Needed
The Problem:Size-Tiered Compaction Strategy (STCS)
Default strategy, optimized for writes. How It Works:- Fast writes (no immediate compaction)
- Simple algorithm
- Good for write-heavy workloads
- Reads can be slow (many SSTables)
- Space amplification (need 2x space during compaction)
- Compaction storms (sudden burst of I/O)
- Write-heavy workloads
- Time-series data (recent data read more)
- Immutable data
Leveled Compaction Strategy (LCS)
Optimized for reads. How It Works:- Fast, predictable reads (90% reads touch ≤ 1 SSTable)
- Less space amplification (10% extra vs 50% for STCS)
- No compaction storms
- More compaction I/O (compacts more frequently)
- Slower writes (more background compaction)
- Read-heavy workloads
- Mixed read/write (balanced)
- Limited disk space
Time Window Compaction Strategy (TWCS)
Optimized for time-series data. How It Works:- Perfect for time-series + TTL
- Efficient expiration (delete entire SSTables)
- Predictable disk usage
- No tombstone accumulation
- Only works for time-series patterns
- Requires careful time window sizing
- Time-series data (IoT, logs, metrics)
- Data with TTL
- Append-only workloads
Choosing a Compaction Strategy
Decision Tree:Practical Exercises
Exercise 1: Analyze Ring Topology
Setup a 3-node cluster and explore:Exercise 2: Observe Compaction
Monitor compaction in action:Key Takeaways
Ring Topology = Peer-to-Peer
No master node. Every node is equal. Consistent hashing distributes data evenly. Vnodes automate token management.
Immutable SSTables
Append-only writes (fast). Never modified after creation. Compaction merges and cleans up periodically.
LSM Tree Trade-offs
Fast writes (MemTable + CommitLog). Slower reads (multiple SSTables). Compaction bridges the gap.
Compaction Strategy Matters
STCS for writes, LCS for reads, TWCS for time-series. Choose based on workload, not defaults.
What’s Next?
Now that you understand the architecture, let’s learn how to model data to match Cassandra’s strengths.Module 3: Data Modeling for Cassandra
Master query-driven data modeling, partition keys, clustering columns, and denormalization patterns
Pro Tip: Revisit this module when troubleshooting production issues. Understanding the internals helps diagnose: “Why is this query slow?” → Check: Bloom filters, compaction strategy, SSTables per read.