Skip to main content
← PROBLEMS / ARCHITECTURE
An end-to-end domain learning journey

Preventing Cassandra
Tombstone Accumulation.

Polling a single Cassandra partition with heavy DELETE or TTL churn forces reads to scan hundreds of thousands of tombstones at the partition head before finding 50 live rows.
Start the journey5 stages
FIRST PRINCIPLES. PRODUCTION SCALE.
The idea to keep with you

If latency budgets leave no room for synchronous retries, never model a FIFO queue in an LSM-tree on one partition; bucket by `(queue_name, hour_bucket, shard_id)`, use `TimeWindowCompactionStrategy` (TWCS) with TTL-only expiration (no explicit `DELETE`s), and bind `UNSET` instead of `null`.

TL;DR30-second simplified summary
▾

Core Mechanics: In an append-only LSM-tree (Cassandra, ScyllaDB, RocksDB), DELETE does not erase data in place—it writes a tombstone marker with a newer timestamp so replicas can reconcile deletions.

Visual & Structural Flow: Depicts 150K Tombstones Blocking LIMIT 50 vs. Time-Bucketed TWCS (Partition: default -> Head: 150K Tombstones -> TWCS Hourly Bucket -> Live Tail); Sharded Hourly Buckets with Zero-Compaction SSTable Drop (UNSET Prepared Insert -> (queue, hour, shard) -> TWCS 1h Windows -> Whole-File Unlink).

Trade-Offs & Production: Two dangerous workarounds make the outage worse: Raising tombstone_failure_threshold to 1,000,000: Only causes JVM heap exhaustion and Stop-the-World GC pauses on coordinator nodes. Eliminate tombstone accumulation at the storage and query layers: Partition Bucketing: Partition by ((queue_name, hour_bucket, shard_id), task_id) with shard_id 0..99.

Failure Modes & Application: Time-bucketed TWCS patterns are standard across high-churn wide-column workloads: IoT & Audit Event Logs: Append-only 7-day or 30-day TTL tables drop aging SSTables with zero read/write amplification.

Full walkthrough · 5 stages
01
STAGE 01 · WHY IT MATTERSL4 · FUNDAMENTALS

Why DELETEs in LSM-trees behave differently from B-Trees.

Why this matters: The mechanism: understand how Why DELETEs in LSM-trees behave differently from B-Trees works from first principles.

Think of Why DELETEs in LSM-trees behave differently from B-Trees as the intuition layer for Preventing Cassandra Tombstone Accumulation: The mechanism: understand how Why DELETEs in LSM-trees behave differently from B-Trees works from first principles.

In an append-only LSM-tree (Cassandra, ScyllaDB, RocksDB), DELETE does not erase data in place—it writes a tombstone marker with a newer timestamp so replicas can reconcile deletions. When you model a job queue with PRIMARY KEY (queue_name, task_id), all 200M daily tasks land in one wide partition sorted by ascending task_id.

02
STAGE 02 · IMPACTL5 · APPLIED DESIGN

100,000+ head-of-partition tombstones and 4.2 s poll stalls.

Why this matters: The problem: see what breaks without 100,000+ head-of-partition tombstones and 4.2 s poll stalls under real concurrency or scale.

Workers always poll WHERE queue_name = 'default' LIMIT 50, starting at the oldest clustering keys where 150,000+ deleted/expired tombstones sit:

  1. TombstoneOverwhelmingException: Once a scan crosses tombstone_failure_threshold = 100,000, Cassandra aborts the query to protect heap.
  2. 4.2 s p99 Latency: Even below 100k, reading and discarding tens of thousands of dead cells saturates CPU and disk.
  3. Implicit Null Tombstones: Binding null on optional columns in INSERT silently generates millions of cell tombstones.
Partition Head Scan

150K Tombstones Blocking LIMIT 50 vs. Time-Bucketed TWCS

Partition: default200M rows/day (100GB)Head: 150K TombstonesTWCS Hourly BucketPage 0Live TaPage 2Page 3

Scanning the head of an unbucketed queue reads 150k tombstones; TWCS hourly buckets drop expired SSTables whole.

Engineering Decision Framework
Problem
How to implement Preventing Cassandra Tombstone Accumulation without hitting unbounded tail latency, state divergence, or operational fragility.
Naive Solution
Use a single unpartitioned path with unbounded retries and synchronous global coordination.
Why It Fails
Global coordination serializes throughput under load, while unbounded retries amplify transient stalls into full outages.
Alternatives
Compare synchronous strict-consistency paths against bounded asynchronous replication, local caching, or partitioned ownership.
Engineering Decision
If latency budgets leave no room for synchronous retries, never model a FIFO queue in an LSM-tree on one partition; bucket by (queue_name, hour_bucket, shard_id), use TimeWindowCompactionStrategy (TWCS) with TTL-only expiration (no explicit DELETEs), and bind UNSET instead of null.
Trade-Offs
Gains predictable p99 latency and fault isolation in exchange for explicit bounding, observability, and slightly higher implementation complexity.
Decision Exercise · Make the Call

When Preventing Cassandra Tombstone Accumulation experiences a sudden 5x traffic spike alongside a slow downstream dependency, which engineering choice best protects system stability?

03
STAGE 03 · NAIVE SOLUTIONL5 · APPLIED DESIGN

Naive fixes (raising thresholds or setting gc_grace_seconds=0).

Why this matters: Scope boundary: identify where this pattern fits best and where simpler or async alternatives win.

Two dangerous workarounds make the outage worse:

  • Raising tombstone_failure_threshold to 1,000,000: Only causes JVM heap exhaustion and Stop-the-World GC pauses on coordinator nodes.
  • Setting gc_grace_seconds = 0 with Explicit DELETEs: If a replica is down when a DELETE occurs, it resurrects zombie tasks upon recovery unless the table is strictly append-only with TTLs.
Request & State Flow

Naive fixes (raising thresholds or setting gc_grace_seconds=0)

Producer ThreadBounded Queue /RingWorker PoolShared State1. Try non-blocking offer / CAS2. Dispatch to idle worker thread3. Execute without holding outerlocks4. Release permit / signalcompletion
04
STAGE 04 · ENTERPRISE SOLUTIONL6 · SCALE & TRADE-OFFS

Enterprise solution: Sharded Time-Buckets + TWCS + UNSET Binds.

Why this matters: Operational control: configure bounds, failure handling, and safe production defaults.

Eliminate tombstone accumulation at the storage and query layers:

  • Partition Bucketing: Partition by ((queue_name, hour_bucket, shard_id), task_id) with shard_id 0..99. Each partition holds ~83,000 rows (~42 MB), well under the 100 MB limit.
  • TWCS + TTL-Only: Configure TimeWindowCompactionStrategy (1 HOUR windows, TTL = 86400s, gc_grace_seconds = 3600). When all cells in an hourly SSTable expire, Cassandra deletes the entire file from disk with zero compaction I/O.
  • Zero Explicit DELETEs / Nulls: Track completion in a separate status or cursor offset (or Kafka/Redis queue), and always use UNSET_VALUE instead of null in prepared INSERTs.
TWCS Storage Lifecycle

Sharded Hourly Buckets with Zero-Compaction SSTable Drop

UNSET Prepared InsertZero null cell tombstones(queue, hour, shard)42MB/partition, <15ms pollTWCS 1h WindowsNo cross-window SSTable…Whole-File UnlinkTTL+gc_grace -> rm…

TWCS isolates each hour into independent SSTables so expired data is unlinked cleanly without tombstone scans.

CREATE TABLE scheduled_tasks (
    queue_name text,
    hour_bucket text,       -- e.g. '2026-11-18T09'
    shard_id int,           -- 0..99 (~42 MB per partition)
    task_id timeuuid,
    payload blob,
    PRIMARY KEY ((queue_name, hour_bucket, shard_id), task_id)
) WITH compaction = {
    'class': 'TimeWindowCompactionStrategy',
    'compaction_window_unit': 'HOURS',
    'compaction_window_size': 1
  }
  AND default_time_to_live = 86400
  AND gc_grace_seconds = 3600;
05
STAGE 05 · SYSTEM DESIGN APPLICATIONSL7 · STAFF / PRINCIPAL

Where TWCS and tombstone hygiene are critical.

Why this matters: Scope boundary: identify where this pattern fits best and where simpler or async alternatives win.

Time-bucketed TWCS patterns are standard across high-churn wide-column workloads:

  • IoT & Audit Event Logs: Append-only 7-day or 30-day TTL tables drop aging SSTables with zero read/write amplification.
  • Queue Anti-Pattern: Production schedulers offload active FIFO dispatching to Kafka/SQS/Redis and use Cassandra/ScyllaDB only for time-bucketed task state history.
Practice · Explain the consequences

Practice: Make the trade-off yourself.

Question 1 of 3
Score: 0/3

Why does mixing explicit `DELETE`s or `null` bind parameters into a TWCS table defeat whole-SSTable expiration?

Recommended Learning Flow