Quick revision
The short answer
Every processed job is deleted, and each delete leaves a tombstone in the same partition, so reading the head of the queue means scanning past every deleted job before reaching a live one; at 100,000 tombstones Cassandra aborts the read. Using Cassandra as a queue is a known anti-pattern for exactly this reason, and the proper redesign is a real queue such as Kafka, SQS or RabbitMQ. If it must stay in Cassandra, partition jobs by time bucket so old buckets are never read, expire rows with TTL and TWCS instead of deleting them, read from a known position rather than the start, and stop writing nulls, which create tombstones too.
What to remember
In this answer, we saw that deleting each processed job leaves a tombstone at the front of the partition, so the worker's read from the start scans every deleted job until it hits the 100,000 tombstone limit. Queues are an anti-pattern in Cassandra for this reason, and the right home for work items is Kafka, SQS or RabbitMQ. If the queue must stay, time buckets, reading from a known position, TTL with TWCS instead of deletes, and avoiding null writes keep readers away from tombstones.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Every processed job is deleted, and each delete leaves a tombstone in the same partition, so reading the head of the queue means scanning past every deleted job before reaching a live one; at 100,000 tombstones Cassandra aborts the read. Using Cassandra as a queue is a known anti-pattern for exactly this reason, and the proper redesign is a real queue such as Kafka, SQS or RabbitMQ. If it must stay in Cassandra, partition jobs by time bucket so old buckets are never read, expire rows with TTL and TWCS instead of deleting them, read from a known position rather than the start, and stop writing nulls, which create tombstones too.
Why this question is asked
Queues are one of the few workloads where Cassandra's strengths become weaknesses. The table works perfectly on day one, and then reads grow slower every hour until they fail outright, while the table holds only a few hundred live jobs. Interviewers use this case because the explanation requires understanding tombstones and the read path, not just knowing the rule. In this answer, we will reproduce the problem, see exactly why the read scans so many tombstones, explain why queues are an anti-pattern, move the work to a real queue, and then show how to make a Cassandra design survive if moving is not an option.
1Reproducing the Problem
The table and the worker loop look reasonable.
Notice that the whole queue is one partition, emails, and the worker always reads from the beginning of it. After a day of processing, the partition holds a few live jobs at the end and a hundred thousand deleted ones at the start.
2Why the Read Scans Every Tombstone
A delete in Cassandra does not remove the row; it writes a tombstone that shadows it. Tombstones stay until gc_grace_seconds (ten days by default) has passed and compaction removes them. Within a partition, rows and tombstones are sorted by the clustering column, job_id, oldest first.
So the query LIMIT 10 starts at the beginning of the partition and walks forward. The first hundred thousand entries are tombstones of jobs we already processed. Cassandra must read each one to know that it shadows a row, and it must keep them in memory, because a tombstone can affect rows on other replicas during the merge. Only after them does it find ten live rows. Each read gets slower as the pile grows, and at tombstone_failure_threshold, 100,000 by default, Cassandra aborts the query to protect itself.
| Position (job_id order) | Content | Read must |
|---|---|---|
| 1 to 100,000 | Tombstones of processed jobs | Scan and skip each one |
| 100,001 to 100,010 | Live jobs waiting | Return these |
| 100,011 onward | Newer live jobs | Not reached by LIMIT 10 |
3Why Queues Are a Cassandra Anti-Pattern
A queue has exactly the access pattern Cassandra handles worst: every item is written once, read once and deleted soon after, and readers always want the oldest remaining items, which sit right behind the most recent deletes. Cassandra is designed for data that is written and read many times, where deletes are rare. Lowering gc_grace_seconds or raising the failure threshold only delays the problem and adds risk: deleted jobs can reappear if repairs miss the shorter window, and huge tombstone scans can pressure the heap.
A queue also needs things Cassandra does not offer: claiming a job so only one worker gets it, visibility timeouts and retries. Teams that build those on Cassandra usually end up with lightweight transactions on every claim, which is slow under contention.
4Redesign: Use a Real Queue
The right fix is to move work items to a system built for them. Kafka fits high-volume, ordered streams with consumer groups and replay. SQS gives a managed queue with visibility timeouts, retries and dead-letter queues. RabbitMQ gives flexible routing and acknowledgements. In each, consuming a message does not leave anything behind for the next reader to skip.
Cassandra can still keep the job history if we need it, such as a jobs_by_customer table for showing past emails, which is a write-once, read-many pattern it handles well.
5If It Must Stay in Cassandra
Sometimes moving is not possible soon. Then we change the model so readers never walk over tombstones.
Three things change. Jobs are partitioned by a time bucket, so once a bucket is finished the worker moves to the next and never reads the old one again. The worker reads from a known position, job_id > the last one it processed, stored for example in a small progress table, so it skips past processed rows by key without scanning them. And we do not delete processed jobs at all: they expire with a TTL, and TimeWindowCompactionStrategy drops whole SSTables once everything in them has expired, without leaving tombstones for readers to scan.
6Do Not Forget Null Writes
One more source of tombstones often hides in the same service. If the Java code binds null for optional columns, such as an absent error message, every insert writes a cell tombstone. With the DataStax driver 4.x, we leave such values unset rather than binding null, and with Spring Data Cassandra we configure it to skip null properties when inserting, checking the options for the version in use. A table that never deletes can still be full of tombstones if it is written this way.
7Follow-up questions
Would a lower gc_grace_seconds fix it?
It would reduce how long tombstones stay, but readers would still scan all tombstones younger than the new value, and the risk of zombie jobs reappearing grows if repairs do not finish within the shorter window. It treats the symptom while keeping the anti-pattern.
How do we migrate without losing jobs?
Start producing new jobs to the real queue while workers drain the old table, reading it carefully with small page sizes. Once the old table is empty, stop the old workers and drop the table. Because job handling must be idempotent anyway, a job processed twice during the switch is harmless.
8Conclusion
In this answer, we saw that deleting each processed job leaves a tombstone at the front of the partition, so the worker's read from the start scans every deleted job until it hits the 100,000 tombstone limit. Queues are an anti-pattern in Cassandra for this reason, and the right home for work items is Kafka, SQS or RabbitMQ. If the queue must stay, time buckets, reading from a known position, TTL with TWCS instead of deletes, and avoiding null writes keep readers away from tombstones.
Open with
The cause is tombstones. Each processed job is deleted, and a delete in Cassandra writes a tombstone that stays for at least gc_grace_seconds, ten days by default. All jobs are in one partition sorted oldest first, so the worker's query for the next ten jobs starts at the beginning and has to scan past every tombstone of every job processed in the last ten days before it finds a live row.
Then, if they want more
Reads get slower and slower, and at the failure threshold of 100,000 tombstones Cassandra aborts the query. This is the well-known queue anti-pattern: data written once, read once and deleted, with readers always wanting the oldest items right behind the deletes.
My main redesign would be to use a real queue, Kafka, SQS or RabbitMQ, where consuming leaves nothing behind, with idempotent handlers since they are at-least-once.
If it had to stay in Cassandra, I would partition jobs by queue and time bucket so finished buckets are never read again, have workers read from their last processed job_id instead of from the start, and stop deleting: rows expire by TTL and TimeWindowCompactionStrategy drops whole SSTables.
I would also check that the code is not binding nulls, since that creates tombstones even without deletes.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Apache Cassandra documentation, Amazon DynamoDB developer guide
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Reads on a Cassandra table used as a work queue fail with 'Scanned over 100001...": https://scrivio-interview-library.netlify.app/databases/cassandra-and-dynamodb/38fb7cebb3/