Skip to main content

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:
Cassandra’s Peer-to-Peer Solution:

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):
Consistent Hashing Solution:
Real Numbers:

Virtual Nodes (Vnodes) - The Modern Approach

Problem with Single Token Per Node:
Vnodes Solution (Default Since Cassandra 1.2):
Vnode Distribution Example:
Streaming on Node Addition:
Configuring Vnodes:

Data Distribution & Replication

Replication Factor Deep Dive

Replication Factor (RF): Number of copies of each data partition. Common Configurations:
How Replication Works:

Replication Strategies

1. SimpleStrategy (Single Datacenter):
2. NetworkTopologyStrategy (Production):
Defining Datacenter & Rack:

Snitch - Topology Awareness

What is a Snitch? Cassandra component that determines network topology (DC and rack of each node). Common Snitches:
  1. SimpleSnitch (Default, single DC):
  1. GossipingPropertyFileSnitch (Most common):
  1. Ec2Snitch (AWS):
  1. GoogleCloudSnitch (GCP):
Why Snitches Matter:

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:
CommitLog Structure:
CommitLog Configuration:
Sync Modes Comparison:

MemTable - In-Memory Write Buffer

Purpose: Fast writes + batching for efficient disk I/O. Structure:
Write to MemTable:
MemTable Configuration:
Flush Triggers:

SSTable - Immutable On-Disk Storage

Key Property: Immutable - Never modified after written. Why Immutable?
SSTable File Components:
  1. Data.db - Actual data:
  1. Index.db - Partition Index:
  1. Summary.db - Partition Summary (in-memory):
  1. Filter.db - Bloom Filter:
  1. Statistics.db - Metadata:
Read from SSTable:

Compaction Strategies

Why Compaction is Needed

The Problem:
The Solution: Compaction

Size-Tiered Compaction Strategy (STCS)

Default strategy, optimized for writes. How It Works:
Configuration:
Pros:
  • Fast writes (no immediate compaction)
  • Simple algorithm
  • Good for write-heavy workloads
Cons:
  • Reads can be slow (many SSTables)
  • Space amplification (need 2x space during compaction)
  • Compaction storms (sudden burst of I/O)
Best For:
  • Write-heavy workloads
  • Time-series data (recent data read more)
  • Immutable data

Leveled Compaction Strategy (LCS)

Optimized for reads. How It Works:
Configuration:
Pros:
  • Fast, predictable reads (90% reads touch ≤ 1 SSTable)
  • Less space amplification (10% extra vs 50% for STCS)
  • No compaction storms
Cons:
  • More compaction I/O (compacts more frequently)
  • Slower writes (more background compaction)
Best For:
  • Read-heavy workloads
  • Mixed read/write (balanced)
  • Limited disk space

Time Window Compaction Strategy (TWCS)

Optimized for time-series data. How It Works:
Configuration:
Pros:
  • Perfect for time-series + TTL
  • Efficient expiration (delete entire SSTables)
  • Predictable disk usage
  • No tombstone accumulation
Cons:
  • Only works for time-series patterns
  • Requires careful time window sizing
Best For:
  • Time-series data (IoT, logs, metrics)
  • Data with TTL
  • Append-only workloads

Choosing a Compaction Strategy

Decision Tree:
Performance Comparison (Typical benchmarks):

Practical Exercises

Exercise 1: Analyze Ring Topology

Setup a 3-node cluster and explore:
Task: Insert data and verify distribution:

Exercise 2: Observe Compaction

Monitor compaction in action:
Task: Compare strategies:

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.