Skip to main content

Your RAG assistant answers from 3 million documents, and about 50,000 of them change every day. Users have started getting answers from old policy versions. Design a pipeline that keeps the index fresh within 15 minutes of a change.

System design · Pro 2

Short answer

Detect changes with events or change data capture where possible, and scheduled scans elsewhere. Process only what changed: hash content, re-chunk and re-embed changed parts, upsert by stable IDs, and remove deleted or replaced chunks. Use a queue with retries, store version and date metadata, monitor index lag, and invalidate caches that hold old answers.

Deeper answer

First find where staleness comes from: slow detection, slow processing, deletes that are never applied, or caches.

Design: sources send change events through webhooks or change data capture. Sources without events get a scheduled scan that compares modified times or content hashes. Each change becomes a message on a queue. Workers fetch the document, parse it, and compare chunk hashes with the stored ones, so only changed chunks are embedded again. Writes are upserts keyed by document ID and chunk ID, which makes retries safe. Deletes and permission changes are events too, and chunks from an old version are removed or marked inactive in the same step. Store version and date as metadata, so retrieval prefers the current version.

Trade-offs: full re-indexing is simple and self-correcting but too slow and costly to run daily at this size, so use incremental updates plus a periodic full reconciliation to catch missed events. What breaks first: bursts, such as a bulk edit of 500,000 documents, so add backpressure and priorities. Monitor index lag, queue depth, failures in a dead-letter queue, and a daily count comparison between source and index.

What a strong answer covers

Answer it out loud in the mock interview about 2.5 min

Follow-ups to expect

Common mistakes

Learn it

Data pipelines for AI

Practice System design questions

More on this topic

Today's AI turns are used

Lessons, roadmaps, videos, practice cards and the code playground stay free with your account, with no limit.