Data Lifecycle Design for a Document-Grounded Chat System
System DesignModel answerLast updated
Design expiry enforcement, conversation history serving, and long-term auditing for a RAG chat platform where document and chat retention windows conflict.
Background
Your team is building a document-grounded conversational assistant. Users upload files, ask questions about them, and expect a browsable history of past sessions. Enterprise customers also need read-only audit trails that outlive the normal retention windows. Four storage timelines must coexist without contradiction:
- Uploaded documents and their derived artifacts (embeddings, extracted text, chunk indexes) are deleted 24 hours after creation. No residual data should remain.
- Conversation transcripts are retained and readable for 7 days.
- The sidebar listing a user's past conversations must load in under 10 ms.
- Enterprise customers may require conversation audit access spanning months or years.
What to Design
Walk through how you would architect this system end-to-end. Structure your answer around the three parts below.
Part 1 — Enforcing Deletion Across Every Copy
A document is not truly deleted until every derived representation is gone: raw file bytes, extracted text, vector embeddings, caches, replicas, and backups. Describe how you track all of these under one lifecycle identity and enforce deletion across all of them on schedule.
Cover:
- How expiry metadata is created and propagated.
- How queries are blocked at access time before physical reclamation completes.
- How deletion jobs are retried, verified, and recorded as evidence.
- Why guaranteeing exact-deadline physical erasure is harder than it sounds, and how you communicate that honestly.
Part 2 — Browsable History After Documents Expire
A user opens a four-day-old conversation. The documents it referenced were deleted three days ago. What does the user see, and why? Then explain how the sidebar loads fast.
Cover:
- How you model the conversation list so a single user's recent sessions are readable without scanning full transcripts.
- How the product distinguishes between "can read the transcript" and "can ask follow-up questions grounded in the original documents."
- How caches are scoped and expired consistently with retention rules.
Part 3 — Long-Term Audit Without Contradiction
Enterprise audit retention can span years, but the base retention windows delete content within days. These goals conflict and cannot both be satisfied by default. Describe a cold audit path that resolves this tension explicitly.
Cover:
- Which fields may legally and technically be retained for audit purposes, and which must be absent even from the archive.
- How the audit store is kept immutable, access-controlled, and off the critical read path.
- How you verify that backups and archive pipelines do not silently re-introduce content that was supposed to be deleted.
Constraints and Edge Cases
- A stored answer may quote or paraphrase content from a document that has since been deleted. Your design must take a position on whether that answer text is itself subject to deletion.
- The 10 ms sidebar target is not defined in the requirements: it could mean time-to-first-byte, full render, or something else. Ask before you build.
- The 24-hour clock start is also undefined: upload time, session start, or last activity each produce different expiry moments.
- Audit retention is not a blanket exception. It must be scoped to specific fields that are permitted to persist, not a hidden copy of everything.
Clarifying Questions to Raise
Before designing, identify at least four questions you would ask a product or legal stakeholder. For each, explain what changes in your design depending on the answer.
Hints
Hint 1
Start by listing every physical location where document data can live — raw storage, extracted text tables, vector index shards, embedding caches, CDN or application-level caches, database replicas, and backups. You cannot delete what you have not inventoried. Assign a single lifecycle_id at upload time and propagate it everywhere.
Hint 2
The sidebar's 10 ms target is achievable only if you never read full transcripts to build it. A separate, denormalized conversations-by-user index — storing only title, timestamp, and session ID — scoped per tenant and sorted by recency, is the key structure. Understand what the 10 ms is actually measuring before optimizing.
Hint 3
Audit retention and document deletion are in direct conflict, and the answer is not to quietly archive everything. Force an explicit policy decision: define the exact fields the audit record may contain (e.g., session ID, user ID, action timestamps, redacted query intent) and confirm that document content and verbatim answer text are excluded unless a legal basis exists.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
Clarifying Questions First
Before drawing any boxes, four questions have to be answered because each one changes the design materially:
- When does the 24-hour clock start? Upload time and last-activity time produce different expiry moments. A document touched at hour 23 could reset to another 24 hours under last-activity semantics, which may violate a compliance requirement.
- What counts as physical deletion? Regulators often accept access revocation at the deadline followed by a bounded verified-deletion process (say, 72 hours to scrub replicas and backups). If instant physical erasure is required, several common infrastructure choices — managed vector DBs, object storage with replication, snapshot-based backups — become non-starters or require expensive workarounds.
- Does answer text derived from a deleted document also expire? A stored answer that reproduces a paragraph from the source file is legally ambiguous. The design needs an explicit policy before deciding whether to purge answers or redact them.
- What is the 10 ms boundary measuring? Time-to-first-byte at the API, full JSON payload receipt at the client, or visible render? A 10 ms API response is achievable with a hot index; 10 ms to visible render is a frontend and CDN problem.
Part 1 — Enforcing Deletion Across Every Copy
Inventory and Lifecycle Identity
At upload, generate a lifecycle_id (UUID). Write it into every derived artifact: the raw file record in object storage, the extracted-text rows in a relational store, the vector embeddings in the index (as a metadata field or namespace tag), any application-level caches keyed on document chunks, and the session record linking them. This single identifier is how the deletion job knows what to find.
Store expiry metadata — expires_at, deleted_at, deletion_confirmed_at — in a lifecycle table. This table is the audit trail for the deletion process itself.
Access Gating Before Physical Deletion
At query time, before any retrieval, check whether expires_at is in the past. If it is, return an access-denied response even if physical deletion has not yet completed. This is the hard boundary. Physical reclamation may lag by hours; the access gate does not.
Deletion Pipeline
A scheduled job (or event-driven trigger) fires at or after expires_at and fans out deletion tasks to each store:
- Object storage: delete the raw file and any CDN invalidation.
- Relational store: hard-delete extracted text rows (not soft-delete, which leaves data readable).
- Vector store: this is the trickiest. Many managed vector databases do not support per-record TTL natively. The options are (a) delete by
lifecycle_idfilter if the store supports metadata-filtered deletes, (b) use namespace-level deletion if documents are isolated to a namespace, or (c) drop and rebuild a collection — expensive but complete. Pick based on the store in use; do not assume a row delete cascades to every shard or replica. - Cache layers: expire or evict by cache key prefix tied to
lifecycle_id.
Every deletion step writes a result (success, failed, pending) back to the lifecycle table. A monitoring job flags any lifecycle_id where expires_at is more than N hours in the past and deletion_confirmed_at is null. This is your evidence of completion and your alert for failures.
Honest Treatment of Backups and Replicas
Replicas catch up asynchronously. Snapshot-based backups contain a point-in-time copy of data that may post-date the expiry. If the compliance requirement is strict, document the backup retention window explicitly: backups taken after expires_at must themselves be purged on a defined schedule, and that schedule becomes part of the deletion SLA. Promising exact-to-the-second physical erasure across backups is not realistic; promising access revocation at the deadline plus verified scrubbing within 72 hours usually is.
Part 2 — Browsable History After Document Expiry
Conversation List Index
Full transcripts can be large. Scanning them on every sidebar load is how you get 200 ms latency, not 10 ms. The fix is a separate, denormalized projection: a conversation_summaries table (or equivalent document store) with one row per session containing only user_id, tenant_id, session_id, title, created_at, last_message_at, and expires_at. This table is indexed on (tenant_id, user_id, last_message_at DESC). A paginated query over this index with a 20–50 row limit is a single b-tree scan returning kilobytes — well within 10 ms at the database layer, assuming a warm connection pool.
Cache this response at the user scope with a short TTL (30–60 seconds). When a conversation expires, a deletion job removes the summary row, and the cache naturally invalidates.
Expired-Document Product State
When a user opens a four-day-old conversation, the transcript is still within the 7-day window so it is readable. The documents are gone. The system should display the transcript in full but disable the follow-up input (or display it with an inline notice: "Source documents have expired; new grounded questions are unavailable"). This is not an error state — it is a designed product state. The client checks a documents_available: bool field returned with the session metadata and adjusts the UI accordingly.
If answer text is subject to deletion per the agreed policy, individual messages containing document-derived content get a redaction flag in the transcript response, and the client renders a tombstone in place of the message body.
Part 3 — Long-Term Audit Without Contradiction
The Conflict to Resolve First
An audit archive that stores full conversation transcripts is a copy of data that the base retention policy deletes at day 7. That is a direct contradiction, and it cannot be resolved by architecture alone — it requires a legal or compliance decision. The answer looks like: "Audit records may retain session metadata and action events; they may not retain document content or verbatim transcript text unless a documented legal hold is in place for a specific session."
What the Audit Record Contains
Permitted fields (typical): session_id, user_id, tenant_id, action_type, timestamp, document_lifecycle_id (tombstone, not content), response_latency_ms, model_version, retrieval_hit_count. These fields support compliance investigations without reproducing deleted content.
Prohibited by default: raw document text, embeddings, verbatim user queries, verbatim assistant answers. If a jurisdiction requires full transcript retention, that must be a per-tenant opt-in with a separate legal basis, not a system-wide default.
Cold Storage Path
Audit records are written to an append-only event stream at session close. A nightly job exports records older than 7 days to immutable cold storage (e.g., S3 Object Lock with WORM configuration, or equivalent). This path is entirely off the transactional database. Online queries never touch the archive; investigators use an offline query tool (Athena, BigQuery export, etc.) against the cold store.
Retention lifecycle rules on the cold store enforce the agreed audit window and then delete automatically.
Verifying Archive Correctness
Run a periodic reconciliation job that samples archive records and confirms no prohibited fields are present. Additionally, confirm that snapshot-based backups of the primary database do not feed the archive pipeline — backups and audit exports must be separate paths with separately enforced retention rules. A backup that outlives the 7-day window is not an audit archive; it is an unintended copy of deleted content.
Common Mistakes to Avoid
- Treating soft-delete as equivalent to physical deletion. It is not; the data is still there and readable to anyone with direct DB access.
- Assuming the vector store will clean itself up when a parent row is deleted. It will not unless you explicitly instrument that.
- Letting the audit archive silently become a full copy of everything by defaulting to "retain all fields."
- Optimizing the sidebar by querying the transcript table with a
LIMIT. That still does a full index scan on large datasets. The denormalized summary projection is the right structure.