DB update queue & batching
Keeping per-component and whole-pipeline status correct at 10k+ writes a day, without letting status updates become the bottleneck for the pipelines they're tracking.
Problem
Every video our platform generated ran through a pipeline of separate components: asset prep, voice, avatar/lip-sync, encoding, delivery, and more depending on the job. Each component needed to report its own status, and the pipeline as a whole needed an aggregate status that was always consistent with its parts, so a dashboard or a webhook consumer could trust it. The platform was designed to sustain 2,000+ pipeline-based video generations a day for our largest client, Indira IVF — a load that added up to 10,000+ status-update requests a day landing on the same database that also served live reads for dashboards, auth, and other tenants.
Writing every one of those updates straight to MongoDB as it happened was the obvious first approach, and it's also the one that broke down first: under concurrent load, components finishing out of order, and read traffic competing for the same collections, the aggregate status could drift from what the components had actually reported.
Constraints
- Per-component granularity and an accurate pipeline-level rollup had to both be true at the same time, even with components finishing in any order and at different times.
- The write path couldn't compete with live read traffic from other tenants on the same database. This wasn't an isolated system: other services depended on the same MongoDB instance staying responsive.
- Everything had to be async and run in parallel; a serial write path would not keep up with pipeline throughput as client volume grew.
- The platform already ran MongoDB and Redis, and this path didn't justify standing up a separate streaming pipeline just for it.
What I built
The design that held up: pipeline components don't write to MongoDB directly. Status updates land first in Redis — non-persistent, cross-process, cheap to write and read — which decouples the pipeline's execution speed from the database's write speed. A dedicated DB update queue picks updates up from there, and a single consumer process flushes them into MongoDB in batches, maintaining both the per-component records and the aggregate pipeline status as one consistent operation rather than N independent ones racing each other.
Keeping the consumer as a single logical writer for the aggregate rollup — while still accepting writes from many components in parallel upstream — is what actually solved the consistency problem. Reads and writes elsewhere in the platform never had to wait on it.
The trade-off
This is not the first design we shipped. Getting the two invariants — per-component correctness and aggregate correctness — to hold at the same time, with writes arriving out of order and in parallel, took several redesigns and a fair amount of debugging before the staged-queue-plus-single-consumer shape proved out under real load.
The trade I made deliberately: a staged, eventually-consistent write path (Redis → queue → batched flush) instead of a naive "every component writes immediately" path. It's more moving parts to operate, but it's the version that kept the aggregate status trustworthy once concurrency got high, and it kept the primary database's write load bounded and predictable instead of scaling linearly with pipeline throughput.
Two costs I accepted with that trade. Redis's non-persistence means that if it restarted before a batch had flushed, whatever updates were staged there at that instant would be lost rather than recovered from a durable log; in practice the aggregate would likely just skip an intermediate state rather than end up stuck wrong, since other components in the same pipeline keep reporting after the restart, but the specific in-flight update itself wouldn't come back. And the single consumer is a single point of failure in the strict sense, but at 10k+ updates a day, that's an average of roughly seven a minute: raw throughput was never the binding constraint, so a restarted consumer picking back up from the queue is enough to keep the aggregate correct.
Outcome
The queue and consumer stood up to the platform's real production load: 10k+ status-update requests a day, in support of Indira IVF's pipeline running at the volume it was designed for, without the status-tracking path becoming a source of database contention for the rest of the platform.