A nightly extract from a delete-heavy Cassandra queue table slows down, then fails — diagnose it from the log
A Cassandra table ops.pending_jobs holds jobs waiting for workers: PRIMARY KEY ((queue_id), created_at, job_id). Workers read the oldest rows of a queue and DELETE each job once it is done; about 2 million jobs a day pass through the billing queue. A nightly extract reads the whole billing partition to count the backlog for a dashboard. It ran in seconds a month ago; now it takes minutes and fails most nights. The table keeps gc_grace_seconds = 864000. Constraints: explain from the log why the read degrades although the live backlog is small, and fix both the extract and the table design.
WARN [ReadStage-3] ReadCommand.java - Read 412 live rows and 87214 tombstone cells
for query SELECT * FROM ops.pending_jobs WHERE queue_id = 'billing'
LIMIT 5000 (see tombstone_warn_threshold)
ERROR [ReadStage-7] ReadCommand.java - Scanned over 100001 tombstones during query
'SELECT * FROM ops.pending_jobs WHERE queue_id = 'billing' ...'; query aborted
-- extract job
ReadFailureException: Cassandra failure during read query at consistency LOCAL_ONE
(1 responses were required but only 0 replica responded, 1 failed)Diagnose the cause.
Each DELETE writes a tombstone kept for gc_grace_seconds (10 days) and until compaction, so the one billing partition holds millions and every read scans them: a warning past 1,000, an abort past 100,000. Bucket the key by time; read past the last done row.
- Thinking a Cassandra
DELETEfrees the row at once, when it adds a tombstone that every read of the range must skip - Raising
tombstone_failure_thresholdinstead of changing the partition design that piles tombstones up - Setting
gc_grace_secondsto 0 on a table with deletes, which lets a replica that missed a delete bring the row back
- How does a TTL row become a tombstone, and what does the compaction strategy
TimeWindowCompactionStrategychange here? - Why is a queue on Cassandra an anti-pattern, and where would you put this backlog instead?
What the log shows. 412 live rows and 87,214 tombstone cells in one read, then an abort at 100,001: these are the tombstone_warn_threshold (1,000) and tombstone_failure_threshold (100,000) limits from cassandra.yaml. The live backlog is small; the dead one is huge.
Why tombstones pile up. A Cassandra delete inserts a time-stamped marker. The marker cannot be dropped before gc_grace_seconds (864,000 s, ten days, by default) — otherwise a replica that missed the delete would bring the row back during repair. After that period only compaction removes it. At 2 million deletes a day, the billing partition collects about 20 million markers over ten days, and every read of the partition from its start walks through them.
The fix.
CREATE TABLE ops.pending_jobs_v2 (
queue_id text,
day date,
created_at timestamp,
job_id uuid,
PRIMARY KEY ((queue_id, day), created_at, job_id)
);
-- extract: only buckets with live jobs, and only past the last processed row
SELECT count(*) FROM ops.pending_jobs_v2
WHERE queue_id = 'billing' AND day = '2026-11-08' AND created_at > ?;- A day bucket keeps partitions bounded, and the extract never reads old days at all.
- At 2 million deletes a day, though, even a day bucket collects millions of markers. So reads within a bucket start after the last processed
created_at(created_at > ?), and the range of markers before it is not scanned. A smaller bucket, such as an hour, is the other option. - Do not set
gc_grace_secondsto 0 or raise the failure threshold: the first resurrects deleted rows, the second exhausts the heap. - For a backlog dashboard, a counter in the source or CDC is more reliable than scanning the queue. The queue itself belongs in a message broker.