Scrivio Interview library
DesignAdvanced7 min read · updated 13 November 2026

A chat platform keeps all messages in a Cassandra cluster whose disks are at 80 percent. Analysis shows 90 percent of reads touch messages younger than 30 days, but users can scroll back years and can edit or delete old messages.

Design tiering so old messages move to cheaper storage, and explain how reads, edits and deletes work on the cold tier.

Keep the last 60 days of messages in Cassandra in time-bucketed tables, so old buckets are dropped whole instead of deleted row by row. A background job writes older buckets to object storage as compressed packed or columnar files per conversation per period, with an index in a small database, and verifies counts and checksums before dropping a bucket. Reads beyond the hot window go through the same API, which fetches and caches cold files at a higher latency the product accepts, while edits and deletes on cold data go to an overlay table applied at read time, and periodic compaction rewrites cold files to purge deleted content.

Why this question is asked

Chat history is a textbook case of skewed access: almost everyone reads the last few days, a few people scroll back years, and everything must stay correct when someone edits or deletes an old message. With the Cassandra disks at 80 percent, adding nodes forever is the expensive answer. Interviewers ask this design to see whether we can split data by temperature without breaking the product's promises. In this answer, we will set the requirements, design the hot tier, the archive job and the cold storage layout, walk through reads, then handle edits and deletes, and finish with verification and failure handling.

1Requirements and Rough Numbers

Ninety percent of reads touch messages younger than 30 days, so a hot window of about 60 days serves nearly all traffic with margin. Users can scroll back years, so old messages must remain readable through the same API, though a slower first page for very old history is acceptable if the product says so. Users can edit and delete old messages, so the cold tier cannot be write-once and forget. And deletions must eventually remove content physically, because privacy rules apply to old data as much as to new.

If, say, 85 percent of stored data is older than 60 days, moving it out frees most of the cluster's disk and stops its growth from tracking the company's whole history.

2A Hot Tier Built for Cheap Removal

In Cassandra, deleting rows writes tombstones, markers that are read and compacted later, so deleting billions of old messages row by row would make reads slower and compaction heavier. Instead we make old data easy to drop in bulk. One way is a table per period, for example one per month, which we drop as a whole after archiving. Another is a TTL with TimeWindowCompactionStrategy, which groups data written in the same window into the same files so whole files expire together.

SQL
CREATE TABLE messages_2026_09 (
conversation_id uuid,
message_id timeuuid,
author_id uuid,
body text,
edited_at timestamp,
PRIMARY KEY ((conversation_id), message_id)
) WITH CLUSTERING ORDER BY (message_id DESC);
-- after the month is archived and verified:
DROP TABLE messages_2026_09; -- frees the whole month at once, no tombstones

I prefer tables per month here, because dropping is an explicit step we take only after verification. With a TTL, data would expire on a timer whether or not the archive succeeded, so it needs a generous margin between the archive deadline and the expiry.

3The Archive Job and Cold Layout

A background job processes one closed month at a time. For each conversation it reads that month's messages and writes them into compressed files in object storage. To avoid billions of tiny objects, many conversations share one file: messages are grouped by conversation inside the file, in a columnar format such as Parquet or a simple packed format with one block per conversation. An index in a small relational database maps each conversation and month to its file, byte offset and length, message count and checksum.

SQL
CREATE TABLE cold_segment (
conversation_id uuid,
month date,
file_key text, -- s3://chat-archive/2026-09/part-0412.pack
byte_offset bigint,
byte_length int,
message_count int,
checksum bytea,
PRIMARY KEY (conversation_id, month));

The job is resumable: it records which conversations of a month are done, so a crash restarts where it stopped, and writing the same conversation again produces the same segment. Files go to an object storage class with millisecond access, because people do scroll back, and can move to colder classes after several years if reads show they are almost never touched.

4How Reads Work Across Both Tiers

The client keeps calling the same history API with a cursor. The API reads from Cassandra while the cursor is inside the hot window, and when it crosses into older months it switches to the cold path.

Step throughScrolling back past the hot window
ClientHistory APICassandraSegment indexObject storage
GET history, cursor in March 2024
read hot window? cursor is older
find segment for conversation and month
file, offset, length
range read of that segment
compressed messages
apply overlay edits and deletes, cache segment
page of messages and next cursor

8 messages in order. Play them, or step through them one at a time.

Notice that the client never knows about tiers. The first page of a very old month costs an index lookup and an object-storage range read, perhaps 100 to 300 milliseconds, after which the decoded segment sits in a cache and further scrolling is fast. That latency is a product decision, so we write it into the requirements: deep scroll-back may be slower.

5Edits and Deletes on Cold Data

Cold files are not rewritten for each change. Instead, an edit or delete of an old message writes a row to a small overlay table, keyed by conversation, month and message, holding either the new text or a deleted marker. The read path applies the overlay on top of the cold segment, so users see the change immediately.

A periodic compaction job then rewrites the affected segments: it reads the segment, applies the overlay, writes a new file, switches the index entry to the new file, deletes the old file, and clears the overlay rows it applied. Compaction is what makes a deletion physical, so its schedule is set by the erasure deadline. If the bucket keeps object versions, old versions must also expire, otherwise deleted content survives in a previous version.

6Verification and Failure Handling

Before a month's Cassandra table is dropped, the job verifies the archive: message counts per conversation and checksums over message ids and contents must match between Cassandra and the segments. Only a month that passes completely is dropped, and the drop is a separate, logged step. If verification fails, the month stays hot and someone investigates.

Other failures are handled by design. If object storage is slow, cold reads time out with a clear error while hot reads continue. If the index database is down, only deep history is affected, and it should run with a replica. If compaction falls behind, overlays still give correct reads; only physical erasure is delayed, which we monitor against the deadline.

7Follow-up questions

How does this change if regulations require deleted messages to be gone within 30 days?

The overlay already hides deleted messages immediately, but physical removal depends on compaction, so compaction must run at least weekly with an alert if any delete is older than, say, 20 days and not yet compacted. Object versioning must not keep deleted content beyond the deadline, and backups need their own treatment, either short retention or encryption with keys we can destroy. Some teams encrypt each conversation's cold data with its own key, so deleting the key makes the content unreadable at once, but message-level deletes still need compaction.

Why not just add more Cassandra nodes?

It works, but cost grows with the whole history forever, and we keep paying hot-tier prices for data read by a small fraction of requests. Object storage costs a small fraction per GB, and the cluster stays sized for recent traffic.

How would search over old messages work?

Search is a separate index, and the same tiering logic applies to it: recent messages in the main search cluster, older ones either in a cheaper index tier or searchable only per conversation by scanning cold segments, which the product must state.

8Conclusion

In this answer, we designed tiering for chat history: a hot window of about 60 days in Cassandra with time-bucketed tables that can be dropped whole, a resumable job that packs older months into compressed files in object storage with a segment index, a read path that serves cold history through the same API with caching and acceptable latency, an overlay for edits and deletes plus compaction for physical erasure, and verification with counts and checksums before any bucket leaves the hot tier.

What to say in the interviewAbout 80 seconds aloud

Open with

I would keep about 60 days of messages hot in Cassandra, which covers the 90 percent of reads under 30 days with margin, using one table per month, or TTL with time-window compaction, so old data is dropped whole instead of creating billions of tombstones.

Then, if they want more

A background job takes each closed month, writes messages grouped by conversation into compressed packed or Parquet files in object storage, many conversations per file, and records conversation, month, file, offset, length, count and checksum in a small index database. Before dropping a month from Cassandra, it verifies counts and checksums, and the job is resumable per conversation.

Reads go through the same history API: in the hot window it reads Cassandra, beyond it it looks up the index, does a range read from object storage, and caches the segment. Deep scroll-back is slower, maybe a few hundred milliseconds for the first page, and I would put that in the product requirements.

Edits and deletes of cold messages go to an overlay table that the read path applies, and a periodic compaction rewrites segments to purge deleted content, which is also how we meet erasure deadlines, together with expiring old object versions.

About this answer

Last updated
13 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 official documentation for the version you use. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
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 "Design tiering so old messages move to cheaper storage, and explain how reads, edits and...": https://scrivio-interview-library.netlify.app/architecture/storage-and-pipelines/39688beacd/