Skip to main content

Cassandra Read & Write Path Internals

Module Duration: 6-7 hours Learning Style: Low-level internals + Performance analysis + Hands-on tracing Outcome: Understand exactly how every read and write flows through Cassandra, predict performance, debug issues

Why Internals Matter

Understanding the read/write paths lets you:
  • Predict query performance before running
  • Design optimal schemas that match Cassandra’s strengths
  • Debug production slowness - know exactly where time is spent
  • Tune effectively - configure JVM, compaction, caching based on workload
  • Interview at top companies - explain distributed database internals
This isn’t just theory. We’ll trace actual queries, measure latency at each stage, and optimize based on what we learn.

Part 1: Write Path Deep Dive

Overview: Why Writes are Fast

Cassandra’s Core Principle: Writes are optimized above all else. Why?

The Complete Write Journey

Let’s trace a write from client to disk:
Stage 1: Coordinator Selection (0.1ms)
Stage 2: Determine Replicas (0.1ms)
Stage 3: Send Mutation to Replicas (Network latency)
Stage 4: Each Replica Processes Write (0.5-2ms) Now let’s go deep into what happens on each replica:

Step 4a: Append to CommitLog (Durability)

CommitLog Characteristics:
Measuring CommitLog Impact:

Step 4b: Write to MemTable (In-Memory Index)

MemTable Data Structure:
Write Conflicts Resolution:
Stage 5: Acknowledgment & Consistency Level (0.1ms)
Consistency Level Impact on Latency:
Stage 6: Hinted Handoff (Failure Handling)

Write Path Timeline (Typical)

Measuring Write Path Performance

Using Tracing:
Using nodetool proxyhistograms:

Part 2: Read Path Deep Dive

Overview: Why Reads are Complex

The Challenge:

The Complete Read Journey

Stage 1: Coordinator & Consistency Level (0.1ms)
Stage 2: Replica Read Path Now the deep dive into how a single replica reads data:

Step 2a: Check Row Cache (Optional)

Row Cache Trade-offs:

Step 2b: Check Key Cache

Step 2c: Query MemTable

Step 2d: Query Each SSTable

This is where reads get expensive:
Bloom Filter Explained:
SSTable Read Cost:

Step 2e: Merge Results

Tombstone Handling:
Stage 3: Read Repair (CL >= QUORUM)

Read Path Timeline


Part 3: Practical Optimization

Exercise 1: Measuring Read Performance

Setup:
Measure baseline:
Optimization 1: Compact SSTables:
Optimization 2: Enable Row Cache:

Exercise 2: Tombstone Debugging

Symptom: Read query slow despite small result set
Diagnosis:
Root Cause:
Solutions:

Summary

βœ… Write Path Mastered:
  • Sequential CommitLog append (fast)
  • In-memory MemTable write (fast)
  • Last-write-wins conflict resolution
  • Hinted handoff for availability
  • Typical latency: 2-5ms
βœ… Read Path Mastered:
  • Multi-level caching (row, key, OS page)
  • Bloom filters avoid disk I/O
  • SSTable merge complexity
  • Tombstone impact
  • Typical latency: 5-50ms
βœ… Optimization Techniques:
  • Compaction reduces SSTables β†’ Faster reads
  • Caching for hot data β†’ Sub-millisecond reads
  • TTL avoids tombstones β†’ Predictable performance
  • Proper data modeling β†’ Single-partition reads

What’s Next?

Module 5: Cluster Operations

Master gossip protocol, repair, multi-DC replication, and cluster management