KatInterview

Data Lifecycle Design for a Document-Grounded Chat System

System DesignModel answer
HardModel answerSystem DesignRAGdata-lifecycleretention-policy

Last 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.