Single logo
  • Courses
  • Blog
  • About
Join free on SkoolJoin free on Skool

Learning path · 15 steps

AI System Design: Reliable, Fast and Affordable LLM Apps
  1. 1
    Fallback Models for an LLM App: A Chain That Checks Region and Fit, Flags Degraded Answers and Gets Rehearsed
  2. 2
    Back Pressure for LLM Traffic: Bound the Queue, Give Chat Its Own Lane, Count Tokens, Cancel When the Caller Leaves
  3. 3
    Load Balancing LLM Traffic: Count the Work, Weigh the Prefix Cache, Check Real Health, Drain Before Deploys
  4. 4
    A Message Queue for Document Ingestion: At Least Once, Leases, an Idempotent Consumer and a Dead Letter Queue
  5. 5
    Caching for AI Apps: Four Layers, What Goes in Each Key, and How a Delete Travels
  6. 6
    Semantic Caching: Why a Similarity Threshold Can't Stop Confident Wrong Answers
  7. 7
    LLM Model Routing: Rules, a Classifier or a Cascade, Judged on Cost per Win and Every Topic
  8. 8
    Observability and Tracing for LLM Apps: A Span per Stage, Redaction First, Bad Traces Become Tests
  9. 9
    Cutting p95 and Cost in Half for an LLM App: Read the Bill, Match the Lever, Guard Success
  10. 10
    Guardrails for an LLM Agent: Check What Comes In, What It Wants to Do, and What Goes Out
  11. 11
    Embedding Migration With Zero Downtime: Two Indexes, a Dual-Write Backfill, a Shadow Check and a Flag
  12. 12
    Design a Multi-Tenant RAG Assistant, Part 1: Requirements, Rough Numbers and a Contract
  13. 13
    Design a Multi-Tenant RAG Assistant, Part 2: Tenant Isolation, a Scoped Cache and Walking an Outage
  14. 14
    A 500 MB PDF Takes 50 s to Answer, Get It to 2 s: Measure First, Then Promise Per Path
  15. 15
    A 500 MB PDF From 50 s to 2 s, the Fast Path: Queue, Status, Streaming and an Acceptance Test That Fails
  1. Blog
  2. /
  3. AI Engineering
  4. /
  5. Retrieval and RAG

Learning path: AI System Design: Reliable, Fast and Affordable LLM Apps · Step 11 of 15

Embedding Migration With Zero Downtime: Two Indexes, a Dual-Write Backfill, a Shadow Check and a Flag

300 million chunks on an old embedding model, and a new one with a different dimension. Mixing models in one index drops the right document on top from 0.83 to 0.46 with no error (simulated). Size the job, backfill a second index while writes go to both, shadow-compare 18 of 23 agreeing, and flip a flag that a failed id check can refuse.

Chaand Sheikh

·27 November 2026Retrieval and RAG

What you will learn

  • Explain why vectors from two embedding models must never share one index
  • Size a backfill out loud: time, tokens and storage from chunks, rate and dimensions
  • Run a dual-write backfill and check document ids on both sides before switching
  • Compare old and new fairly with a shadow check, then flip a flag with a way back

Before you start

  • Real Embedding Models: Open or API
  • Vector Databases Hands-On: Chroma and pgvector

Here's the interview question. You've got 300 million chunks embedded with an old model, and you want a newer model with a different dimension. How do you move across with zero downtime, and with a way back?

The thirty-second answer is four steps. Keep the two models apart: two indexes, never one. Size the backfill, then run it while every change goes to both. Compare them fairly on the same questions before any user sees the new one. And flip a flag, keeping the old index ready so going back is one more flip. Numbers below are either for illustration or from a small simulation on synthetic documents, and each one says which.

Moving a library without closing it

A big library is moving to a new shelving system, and it can't close for even one day. So you leave the old room alone, and readers keep borrowing from it. You set up a new room next door, and staff carry books across a few shelves at a time. A new book arrives meanwhile, so a copy goes to each room. A book that's thrown out leaves both. Before opening, testers visit both rooms with the same list. Then you change the sign on the door, and keep the old room in order for a while, because if something goes wrong you just change the sign back.

Two models in one index

The shortcut that breaks it: "Why two indexes? Replace the vectors in place, a batch at a time." Halfway through, one index holds vectors from two models. A vector only means something next to vectors from its own model.

== 1. mixing two spaces (no error!) ==     (simulated)
v1 query on v1 index: 0.83
v2 query on v1 index: 0.67
half v2 vectors in v1 index: 0.46

That's the share of questions with the right document on top. With the old model on both sides it's 0.83. With half the stored vectors swapped to the new model, it falls to 0.46. And nobody got an error. If the new model has a different dimension you'll probably get a loud failure, and that's the lucky case. With the same dimension nothing stops you, and answers just get worse.

How long, and how much

Interviewers like it when you size the job out loud. This is arithmetic for illustration: 300 million chunks, 200 tokens each, 1,000 chunks a second, 768 and 1,024 dimensions. Not from a run, not a benchmark, and no price quoted.

WhatFormulaFor illustration
Timechunks / embedding rate300M / 1,000 per s = about 83 hours, roughly 3.5 days
Costtokens x price per token300M x 200 = 60 billion tokens, times your own provider's price
Storageboth indexes side by sideabout 2.15 TB of raw vectors, before index overhead

One more line: you pay for each chunk once, plus every change that arrives while the backfill runs.

Backfill while the writes keep coming

Dual-write backfill Every update and delete Old index (v1) keeps serving New index (v2) starts empty Users backfill in batches Simulated, 24 docs: left 16, then 15 (update + delete), then 7, then 0
The dual write keeps the new index current; the backfill copies what was there before.

The old index keeps serving, and the new one starts empty. From now on every update and every delete goes to both. That's a dual write. Meanwhile, workers copy older documents across in batches.

== 2. dual write + backfill (simulated) ==
after batch 1, left: 16
update + delete arrived, left: 15
backfill, left: 7
backfill, left: 0
sync: {'missing': [], 'extra': [], 'stale': []}

Sixteen becomes fifteen because the deleted document never needs copying. The total is 24 embeddings for 23 documents, because the update got embedded twice. Before you trust it, compare document ids on both sides, looking for anything missing, extra or out of date. Here all three lists are empty.

Comparing A and B fairly

The same questions go to both indexes, and each index gets a query embedded by its own model, while users still get the old answer. That's a shadow check.

== 3. shadow evaluation ==     (simulated)
questions: 23, agree: 18
recall@1 v1: 0.83
recall@1 v2: 0.87

The two indexes agree on the top document for 18 of 23 questions. The old one scores 0.83 and the new one 0.87. That gap is one question out of 23. It doesn't prove the new model is better; it only says it isn't obviously broken. So read the five where the top answer changed. For scoring retrieval more fully, see Retrieval Evals.

The flag, and the delete that skipped

The switch itself is one flag. Flip it and users move across; flip it back and they're on the old index, with nothing to embed again. That only works if you keep writing to the old index after the flip, or it's out of date the moment you go back.

Now the failure test. We simulated a bug where deletes skip the new index:

== 5. delete skips v2 (simulated bug) ==
deleted: invoice
sync: {'missing': [], 'extra': ['invoice'], 'stale': []}
cutover refused
forced cutover returns: ['invoice']

The id comparison finds one extra, so the flip is refused. Force it anyway, ask where to find a payment receipt, and back comes the deleted invoice. So the flip has to depend on that check, because a deleted document coming back can be a privacy problem, not just a wrong answer.

The follow-ups

These three are design answers; they weren't simulated.

  • What about cached results? They came from the old model, and a semantic cache even stores old query vectors. Put the embedding version in the cache key, and expect a cold cache after the flip. See Caching for AI Apps and Semantic Caching.
  • Can the backfill slow down users? Yes, if it shares a quota with search. Give it its own limit and throttle it.
  • How long do you keep the old index? Decide up front, and keep writing to it until then, knowing you're paying for two.
LevelWhat it sounds like
Weak"Embed everything again and switch over."
GoodThe models can't mix; two indexes, a backfill and a flag.
StrongAlso shows the formula, keeps deletes in step, blocks the flip on an id check, and doesn't oversell a small gap.

Recap

StepRemember
Keep them apartMixed models: 0.83 to 0.46, and no error (simulated)
Size itTime = chunks / rate; cost = tokens x price; storage for both
BackfillDual write, copy in batches, compare ids on both sides
Compare and flipShadow check, read the changed answers, flag with a way back

Try it yourself

Pick a document store you know. Estimate its chunks, tokens per chunk and an embedding rate, and work out the backfill time and the raw vector storage for both indexes.

Tried the exercise? Share your answer or ask a question.

The StudyEasy AI Community is free to join, with the lesson files, notebooks and code.

Join free on Skool

Keep going in the learning path AI System Design: Reliable, Fast and Affordable LLM Apps · step 11 of 15

Previous
Guardrails for an LLM Agent: Check What Comes In, What It Wants to Do, and What Goes Out
Next post
Design a Multi-Tenant RAG Assistant, Part 1: Requirements, Rough Numbers and a Contract

Related course on Udemy

Machine Learning Engineer: From First Model to ML Engineer

Learn machine learning in Python, then ship it: data analysis, regression, classification, tuning, deployment and MLOps.View on Udemy ↗: Machine Learning Engineer: From First Model to ML Engineer (paid course, opens in a new tab)

Related posts

The RAG Pipeline Explained: 7 Stages From Documents to a Cited Answer

Ingest, chunk, embed, store, retrieve, rerank and generate, in one Python file. Follow one question through a 26-chunk employee handbook to an answer that cites its source.

Similarity Search: Finding the Closest Vectors with NumPy and NearestNeighbors

Ask one question of a whole collection of vectors: which items are closest to this one? Normalise, score every row with one matrix multiply, keep the top k or everything above a threshold, and check it with NearestNeighbors.

Why RAG Exists: The Problem It Solves, Compared With Pasting Everything and Fine-Tuning

A smart model has never read your company's files, and they change every month. Three ways to give it the facts: paste everything, fine-tune, or retrieve only the right pieces. Follow a refund-policy question through all three and see why RAG wins when documents change.

Real Embedding Models: an Open Model or a Provider API, Then Search, Duplicates and Recommendations

Swap a toy embedder for a model that learned. Two roads (all-MiniLM-L6-v2 on your machine, or OpenAI's API with your key), three sizes (384, 1,536 and 3,072 numbers), one rule, and three use cases built on the same rank function, with real scores.

On this page

  • Moving a library without closing it
  • Two models in one index
  • How long, and how much
  • Backfill while the writes keep coming
  • Comparing A and B fairly
  • The flag, and the delete that skipped
  • The follow-ups
  • Recap
  • Try it yourself
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool

Related course on Udemy

Machine Learning Engineer: From First Model to ML Engineer

Learn machine learning in Python, then ship it: data analysis, regression, classification, tuning, deployment and MLOps.View on Udemy ↗: Machine Learning Engineer: From First Model to ML Engineer (paid course, opens in a new tab)

Single logo

Empowering Education, One Course at a Time

About
About usContact usFAQs
Legal
Terms of ServicePrivacy Policy

© 2026 StudyEasy Organization. All rights reserved.