Skip to content
AVERITH
← All insights
ArchitectureNote / 0112 min read

Why production RAG becomes a distributed-systems problem

Retrieval quality depends on freshness, fan-out, ranking, permissions, context assembly and the failure behavior between them.

A prototype retrieval-augmented generation system is small enough to hold in your head. Embed some documents, store the vectors, retrieve the top few chunks for a question, and place them in a prompt. The original RAG formulation describes exactly this shape: a retriever supplies non-parametric memory to a generator.1 In a demo, it works remarkably well.

Production changes the problem. The documents change every hour. Different users may see different subsets of them. Several indexes serve different retrieval methods, a reranker runs as its own service, the model sits behind a provider with quotas and outages, and every request has a latency budget. Each of those components can be slow, stale or unavailable independently, and the answer the user receives is a composition of all of them.

That is the defining property of a distributed system: correct behavior depends on coordination between components that fail independently and partially. Once RAG reaches production, its quality stops being a property of the embedding model and becomes a property of the whole system.

Request path / query time

QUERYIDENTITY+ ACLVECTORLEXICALFRESHDELTAFUSE +RERANKCONTEXTMODELCITE +EVALUATEINGESTION / ASYNCHRONOUSINDEX LAGSOURCESCHANGE CAPTUREPARSE + CHUNKEMBEDVERSIONED INDEX
Figure 1 — A production RAG request fans out across independently failing dependencies. The ingestion path that keeps indexes current runs asynchronously, so every index is a lagging replica of its sources.

01 / Fan-out

The request path is a fan-out, and fan-outs are governed by their tail

Mature retrieval rarely means one index. Dense vector search captures semantic similarity but can miss exact identifiers, product codes and rare terms; lexical search such as BM25 handles those well but misses paraphrase. Recently changed documents may live in a smaller delta index until they are merged. A single question therefore becomes several parallel calls whose results must be merged.

Parallel calls make end-to-end latency a function of the slowest participant. Dean and Barroso describe this in The Tail at Scale: when a request depends on many components, rare slowness in any one of them becomes common at the level of the request.2 The arithmetic is simple. If each of three independent retrieval calls exceeds its own 99th-percentile latency 1% of the time, the probability that at least one does is 1 − 0.99³ ≈ 3%. Add a reranker and a model call in sequence, and the request’s tail is dominated by components no single team owns.

  • Give every stage an explicit deadline derived from the end-to-end budget, rather than one global timeout.
  • Decide in advance what happens when a branch misses its deadline: proceed with the remaining candidates, and record that the answer was produced in a degraded mode.
  • Hedge only idempotent, read-only calls, and cap the extra load hedging can create.
  • Measure latency per stage. An average end-to-end number hides which dependency owns the tail.

02 / Freshness

Every index is a lagging replica of its sources

The source of truth for a document is a wiki, a ticketing system, a drive or a database. The index is a derived copy produced by an asynchronous pipeline: capture the change, fetch and parse the document, split it into chunks, compute embeddings and write the result. Each step can lag, fail or partially succeed. Between a change at the source and its arrival in the index, the system serves stale reads.

Deletions are the dangerous case. A document removed from its source, or a paragraph redacted from it, remains retrievable until the pipeline propagates the removal. A system that ingests reliably but deletes unreliably will eventually cite content that no longer exists or should no longer be visible.

Model changes create a second consistency boundary. Vectors produced by one embedding model are not comparable with query vectors produced by another. Changing the embedding model, or even the chunking strategy, means rebuilding the index and switching traffic atomically. Mixing generations inside one index silently degrades retrieval without producing a single error.

  • Store the source identifier, source version and ingestion time on every chunk, and write idempotently using a key such as (document_id, version, chunk_index).
  • Treat deletion and permission changes as first-class events that propagate with the same priority as new content.
  • Measure index lag—the time from source change to retrievability—as a service-level indicator.
  • Build a new index version alongside the old one, evaluate it, then switch an alias. Never re-embed in place.

03 / Permissions

Authorization belongs in retrieval, not in the prompt

In an enterprise setting, two users asking the same question should often receive different answers, because they are entitled to different documents. Permissions are therefore part of retrieval correctness, not a presentation concern.

Filtering after retrieval looks simple and fails in two directions. If the top results are documents the user cannot see, removing them can leave few or no candidates, and retrieval quality collapses for exactly the users with the narrowest access. If filtering is skipped or incomplete, restricted text reaches the prompt. A model cannot be relied on to withhold information it has been given; once content is in context, the access decision has already been made.

Storing access-control metadata in the index solves the filtering problem and introduces a replication problem. The index now holds a copy of the identity system’s decisions, and that copy lags. When access is revoked at the source, the revocation is only effective after it reaches the index.

04 / Ranking

Ranking is a multi-stage decision with a recall ceiling

Results from different retrievers use incompatible scores, so they must be fused before they can be compared. Reciprocal rank fusion is a common, robust choice because it combines rank positions rather than raw scores.3 A cross-encoder reranker then reorders the merged candidates with a more expensive model.

Each stage bounds the next. A reranker can only reorder the candidates it receives, so a relevant passage missed by first-stage retrieval cannot be recovered later. When answer quality drops, teams often tune the prompt or change the generator, while the actual defect sits in candidate generation or in a stale index.

  • Evaluate candidate generation by recall at the depth passed to the reranker, using a labeled set of real queries.
  • Evaluate reranking separately with ranking measures such as precision or nDCG at the context depth.
  • Treat the reranker as a remote dependency with its own deadline, and fall back to fused order when it is unavailable.

05 / Context

Context assembly is resource allocation

The context window is a budget. Assembly decides which passages enter it, in what order, with what surrounding text, and how duplicates and near-duplicates are handled. Those decisions change answers as much as retrieval does.

Position matters. Liu et al. found that language models used relevant information more reliably when it appeared near the beginning or end of a long context than when it was placed in the middle.4 Adding more retrieved text is therefore not a free improvement; it can dilute the passages that matter and increase cost and latency at the same time.

Make assembly deterministic and record its output. When an answer is wrong, the first question is what the model was actually shown. If the assembled context cannot be reproduced, that question cannot be answered.

06 / Failure

Partial failure must have a defined behavior

Distributed systems rarely fail cleanly. A RAG system that has not defined its degraded modes will still have them; they will simply be accidental. The most damaging accident is the silent conversion of a retrieval failure into ungrounded generation: a timeout or an empty result produces no context, and the model answers anyway from its parametric memory, fluently and without citations.

FailureAccidental behaviorDefined behavior
Vector index times outRequest hangs, or answers from partial context without noticeContinue with lexical and delta results; mark the answer as degraded
Reranker unavailableError returned to the userUse fused order and record the fallback
No relevant resultsModel answers from memoryState that no grounded source was found
Stale permissionsRevoked content reaches contextRe-check sensitive sources before assembly
Model provider errorUnbounded retriesRetry within budget, then use the declared fallback model

07 / Observability

Every answer needs a trace

A user report that an answer was wrong is only actionable if the system can reconstruct the request: which index versions served it, which candidates each stage returned with their scores, which documents the permission filter removed, what context was assembled, which model and prompt version generated the response, and whether each citation supports the claim attached to it.

Record this as a structured trace per request. It turns debugging from speculation into inspection, supplies the labeled examples evaluation needs, and makes it possible to replay a request against a new index or model before releasing it.

08 / Practice

What changes in practice

None of this requires exotic infrastructure. It requires treating the RAG pipeline with the same discipline as any other distributed service.

  • Define service-level indicators beyond latency: index lag, retrieval recall on a labeled set, empty-retrieval rate, degraded-answer rate and citation support rate.
  • Version the embedding model, chunking strategy, index, prompt and generator, and record those versions on every trace.
  • Assign each stage a deadline and a documented degraded behavior.
  • Enforce authorization inside retrieval, and propagate revocations and deletions as priority events.
  • Evaluate each stage independently before evaluating the final answer.

The model is one node in this system. The reliability, freshness, security and cost of the answer are properties of everything around it.

References

  1. 1. Lewis, P. et al. (2020). Retrieval-Augmented Generation for Knowledge-Intensive NLP Tasks. arXiv:2005.11401
  2. 2. Dean, J. and Barroso, L. A. (2013). The Tail at Scale. Communications of the ACM, 56(2). doi:10.1145/2408776.2408794
  3. 3. Cormack, G. V., Clarke, C. L. A. and Büttcher, S. (2009). Reciprocal Rank Fusion Outperforms Condorcet and Individual Rank Learning Methods. SIGIR. doi:10.1145/1571941.1572114
  4. 4. Liu, N. F. et al. (2023). Lost in the Middle: How Language Models Use Long Contexts. arXiv:2307.03172

About the author

Author

Aashutosh Kumar

Founder, Averith

Leads Averith’s work on production AI systems. Background in AI and data systems engineering, production-scale engineering environments, and advanced study in AI and data science.