skip to content

When a bulk migration floods a RAG pipeline's embedding queue and live incident edits wait hours to become retrievable, how do you protect live freshness?

level: seniorimportance: should knowfreq 42%

answer

  1. position matters, not size
  2. lanes by origin
  3. reserved share bulk may borrow
  4. tokens, not items
  5. enqueue bulk in pages

basics

~20 s

Live edits waited behind the whole bulk backlog in one shared queue. Tag work by origin, give live edits their own lane with a reserved share of embedding throughput that bulk may borrow when idle, and feed the migration in bounded pages.

solid answer

~50 s

The diagnosis is a shared first-in, first-out queue and throughput limit: in this scenario 240 million bulk tokens at a million tokens a minute put four hours in front of every live edit, however small. Split intake into lanes by origin, with deletes and access changes first, live edits next and bulk last. Reserve a share of embedding throughput for live edits, counted in tokens because chunk sizes vary; at 20% a 2,000-token incident edit is served within seconds. Let bulk borrow the reserved share when no live edit waits, so the migration stretches from 240 to at most 300 minutes rather than stalling. Have the migration enqueue a bounded window instead of its whole backlog, throttle its writes as well, and prove the fix with the live lane's p95 lag staying flat during the run.

go deeper

for a junior

Recall that one shared first-in, first-out queue makes a small edit wait for everything ahead of it, whatever its size.

for a middle

Explain lanes by origin, a reserved token share for live edits, and why the bulk job should enqueue bounded pages rather than its whole backlog.

for a senior

Do the arithmetic for the live wait and for bulk's slower finish, choose borrowing over strict priority, and check parse workers and the write path for the same flood.

for a principal

Own the reservation size as a trade between live freshness and migration duration, and the scheduling rule that keeps large loads away from peak change hours.

## Why live edits end up hours behind In the simplest pipeline every change shares one first-in, first-out embedding queue served against one throughput limit, whether it is a live edit from a webhook or a document from a bulk migration. When a migration enqueues its whole backlog at once, a live edit arriving afterwards waits for all of it. Using this scenario's figures: - the migration queues 600,000 chunks of about 400 tokens each, which is **240 million tokens**; - the embedding throughput is limited to **one million tokens per minute**; - 240,000,000 / 1,000,000 = **240 minutes**, so an edit arriving just after the migration waits about **four hours**. The incident edit needs perhaps 2,000 tokens, a fraction of a second of throughput, yet it becomes retrievable four hours late. In a FIFO queue the size of an item does not matter; its position does. ## Separate lanes, reserved capacity The fix is to stop bulk and live work from sharing one line: 1. **Tag at intake.** Every item carries its lane (`access-and-delete`, `live-edit` or `bulk`) and its source. A migration, a re-crawl or any other job-launched load is bulk; a change event from a connector is live. 2. **Give each lane its own queue.** Deletes and access changes skip embedding entirely and go first. 3. **Reserve a share of embedding throughput for live edits**, measured in tokens because chunk sizes vary. With a 20% reservation live edits get 200,000 tokens per minute, so a 2,000-token edit uses well under a second of that share. 4. **Let bulk borrow idle capacity.** When no live edit is waiting, bulk uses the whole limit; when one arrives, it goes into the next dispatched batch. Bulk then finishes in between 240 minutes (no live traffic) and 240,000,000 / 800,000 = **300 minutes** (live share fully used throughout). 5. **Feed bulk in pages.** The migration job enqueues a bounded window, say the next 10,000 chunks, rather than its whole backlog, so queue depth stays small and the job can be paused. | Design | Live edit wait during migration | Bulk finish | |---|---|---| | One FIFO queue | up to about 4 h | about 240 min | | Strict priority for live | seconds | stalls whenever live work alone fills the limit | | 20% live reservation, bulk borrows idle share | seconds | 240 to 300 min | Strict priority, where bulk never runs while live work waits, can starve the migration on a day when live work alone keeps the limit busy. The guaranteed share plus borrowing is one answer to that; the general starvation remedies are part of the priority-queue pattern. ## The rest of the path The embedding queue is usually the bottleneck, but the same flood can reach other shared resources: - **parse workers**, which a migration of large files can occupy, so live edits need reserved workers too; - **the write path**, since a store absorbing heavy bulk writes may apply them more slowly, which shows up as write-stage lag for live edits; throttle bulk writes as well as bulk embeds; - **the source's own request quota**, where a migration that re-fetches from a live source competes with that source's change notifications, which is a connector concern. If the migration touches documents that live edits also change, which version wins is an ordering question covered with the re-embedding backfill job. ## Proving it works With stage timestamps on every item, compare the live lane's p95 lag before and during the migration: it should stay flat. Track bulk progress separately, as tokens per minute and an estimated finish, so the migration's owner sees what the reservation costs them. Schedule large migrations away from the hours when live sources change most; lanes protect freshness, but a migration running at night needs less protecting. ## What to say in the interview The diagnosis is one sentence: live and bulk work shared a FIFO queue and a throughput limit, so a small live edit inherited the whole backlog's wait. The design is lanes by origin, a reserved token share for live edits that bulk may borrow, deletes ahead of both, and per-lane lag to prove the live lane stayed fresh.

  • Why not give live edits strict priority over all bulk work?
    Strict priority starves bulk whenever live work keeps the limit busy, so a migration planned for five hours can stretch indefinitely. A guaranteed share for live edits that bulk may borrow when idle keeps live lag low and gives bulk a predictable floor. Other starvation remedies, such as ageing, belong to the general priority-queue pattern.
  • Why reserve the live share in tokens rather than in queued items?
    Embedding throughput limits often count tokens, sometimes alongside requests, and chunk sizes vary widely. A share counted in items lets a few very long bulk chunks consume far more of a token limit than intended. Token counts can be computed or closely estimated before each call, so the dispatcher can use them.
  • Live-lane embedding lag stays flat during the migration, yet live edits still show up late in answers. Where else do you look?
    Past the embedding stage, at the write path. A store absorbing a heavy bulk write load may apply writes more slowly, which shows as a growing gap between the write and the change becoming searchable. Throttle bulk writes as well as bulk embeds, and check parse workers for the same contention.

A print shop keeps one press reserved for rush jobs. While no rush job is waiting, that press helps print the big catalogue order; the moment a rush job arrives, it goes on next, after the sheet already printing. The catalogue finishes a little later, and the rush job never waits behind it.

  • A small live edit is fast in any queue because it needs few tokens.
  • More embedding quota alone keeps live edits fresh during any migration.
  • Strict priority for live edits has no downside.
  • Enqueue the whole migration at once; the queue will sort it out.
  • Lanes in the embedding queue protect every stage of the path.