Managing Write Ordering Across Backfill, CDC, and Live Ingestion in a 20TB Migration

Wait 5 sec.

Everyone expects the scary part of a big live migration to be the copy. Ours was 20TB, and the copy turned out to be the boring part. The part that kept me up was a much smaller question: when three different pipelines can all write the same customer attribute, which write is allowed to win?This is what we learned answering that, including two places where I'd now do more than we did.The ProjectMy team ran a customer data platform, the system of record for customer profile data, fed by more than 500 upstream sources. Operationally, each source was a Kafka topic the platform consumed.We were re-architecting the storage at the same time. The old DynamoDB table stored each customer as one big JSON blob, with attributes from many sources packed together and compressed, because a well-populated customer could otherwise approach DynamoDB's 400KB item limit. A consumer wanting one attribute had to read, decompress, and parse everything, and every update rewrote far more than it changed.The new table used an entity–attribute–value (EAV) layout: each attribute is its own item, so consumers read, write, and subscribe to only what they need. That meant reshaping every record in flight, not copying it, under three constraints: production couldn't stop, writes during migration couldn't be lost, and every blob had to be decompressed, flattened, and exploded into many EAV items.When a Migration Grows a Third WriterThe standard recipe is familiar: snapshot, backfill, stream changes with CDC, catch up, cut over. It's good advice. What it doesn't say loudly is that it quietly creates multiple writers for the same record. We ended up with three:Backfill, copying and reshaping history.CDC, carrying every change from the old table.The new platform's real-time ingestion, which became authoritative for a source once that source moved over.With 500+ topics from 80+ systems, sources moved one at a time. There was never a single cutover moment, just a long stretch where ownership differed per source.Capture First, Copy SecondOur first decision was to turn on change capture before taking the snapshot. The path was DynamoDB → Kinesis Data Streams → Lambda → Kafka, with Kafka as a durable buffer (one topic per entity, 30-day retention), and we confirmed streaming was active before starting the export.The order matters. Take the snapshot first and start CDC later, and a write can land in the gap: too new for the snapshot, too early for CDC. That loss is silent. Starting capture early closes the gap.It also opens a subtler one, and this is the part I got wrong in my first mental model. Overlap isn't automatically harmless. Backfilled items carry version 1. A CDC event from just before the snapshot carries a real timestamp, far greater than 1, so if it's replayed after the backfill it replaces the snapshot value with an older state. The table then converges as later events arrive and the buffered history drains, but it's eventually right, not right at every instant. Capture overlap prevents loss; it doesn't remove the need for a boundary.I'll be upfront: we deferred applying CDC until backfill finished, and we didn't have a separate reconciliation or read-gating mechanism that I can point to. If I did it again, I'd add an explicit catch-up watermark so nothing trusts the destination until the backlog has drained.Backfill From an Export, Not the Live TableWe never scanned the production table. We used DynamoDB's native export to S3, a point-in-time copy that consumes none of the live table's read capacity, and an EMR pipeline processed it: decompress, normalize to JSON, flatten into attribute paths, explode into EAV records, write.Every backfilled item got the same floor version, 1. That was deliberate. A stale snapshot value should never look more authoritative just because a worker happened to process it later than a live update. Backfill handled volume; CDC handled freshness.While backfill ran, the CDC processor stayed off and Kafka simply accumulated changes. When backfill finished, the processor drained the backlog and then kept consuming live changes. A buffer gives you retention and decoupling, but it doesn't give the target an ordering rule. AWS is explicit that the Kinesis integration can deliver duplicate or out-of-order records, so the target had to decide for itself.Ownership Was the First Ordering MechanismBefore leaning on versions, we reduced the number of writers that could collide. During backfill, only backfill wrote. After it, CDC applied the backlog and live changes. Then sources moved to the new platform one at a time: for a source not yet cut over, CDC carried its attributes; once it moved, the CDC transform chain filtered that source's attributes out so real-time ingestion was the sole writer.The hard part is the handoff itself. Say a source moves at time T. Some of its CDC records may already be in Kafka, inside a Lambda batch, mid-retry, sitting in a failure queue, or waiting to be redriven. Filtering new CDC output doesn't make those disappear. A complete design needs a policy for events captured before the boundary but processed after it: a per-source cutover timestamp, an epoch, a fencing token. Our implementation filtered in the transform chain, and I wouldn't claim more than that. The lesson I'd pass on is to design the handoff around in-flight work, not just new work.Versioning Handles the Races Ownership Can'tEven with careful ownership, retries and long handoffs leave races. The target needs to answer one question alone: given a stored value and an incoming one, which wins?Last-write-wins using the worker's clock is the tempting answer and the wrong one. If a backfill worker stamps a value that went stale ten minutes ago with now, the stale value looks newer than the update that replaced it. Processing time tells you when a pipeline touched a value, not when it became authoritative. So every write carried a version tied to its origin:WriterVersionWhyBackfillConstant 1Historical data should lose to live changesCDCDynamoDB ApproximateCreationDateTimeTied to the captured source changeReal-time ingestionTimestamp at the authoritative writeAfter handoff, this pipeline originates the valueWrites were conditional: accept only if the version is newer than what's stored. That's why retrying a CDC record hours later is safe; retrying doesn't make it newer.One caveat I'd flag to anyone copying this. Timestamp precision reduces collisions but doesn't give a total order. AWS lets you set the stream's creation timestamp to microsecond precision, which helps, but two writes can still tie, and a strict "newer wins" check will drop the later of two equal-version events. You need an explicit equal-version policy. A fuller ordering key might look like (ownership_epoch, source_rank, event_time, event_id). That's an example of the shape, not something our table used.Source Ranking Is Its Own ProblemMigration writers weren't the only ones competing. Several upstream systems can report the same logical attribute, and the CDC transform used ranked-source metadata to pick the winner. When a ranking was missing, the pipeline logged a failure instead of guessing. That separates two questions: which source is authoritative for an attribute (ranking), and which migration writer may apply a version (ownership plus versioning).What the Pipeline Did Besides Move DataThe transform chain decompressed and normalized payloads, flattened them into attribute paths, applied source ranking, dropped deprecated attributes and sources that had already moved, and, importantly, diffed the old and new images so an update only emitted attributes that actually changed (for lists, only the changed elements). Without that, one update to a big blob would have fanned out into many pointless EAV writes, carrying the old model's write amplification into the new one.Deletes deserve the same discipline, and I want to be honest here too. A delete is an ordered state change: it has to mean both "no value now" and "older values may not come back." In an EAV design that requires either versioned tombstones or separate deletion metadata. I'd treat that as a requirement from day one, not something to discover after a backfilled value resurrects a deleted attribute.Failures Replay Instead of Dropping DataWe assumed batches would fail: missing metadata, event-bus hiccups, oversized batches. Lambda's failure controls for Kinesis did the heavy lifting. Failed batches were bisected on retry so one bad record didn't fail its neighbors repeatedly. Exhausted batches sent metadata to SQS, not payloads, which means the original records still have to exist in the stream; our 14-day Kinesis retention was therefore part of the recovery model, not a guarantee. A redrive Lambda re-read failed ranges with partial-batch responses, and a final dead-letter path caught the rest.Origin-derived versions helped in one specific way: replaying an old CDC event later can't make it newer. They didn't replace retention, idempotency, observability, or careful redrive.What Testing Showed, and What Production NeededShardsConcurrent batchesThroughput through Lambda11256 records/sec12010~2,900 records/sec304~22,000 records/sec308~32,000 records/secThe 120-shard result surprised me: spreading traffic that thin produced small, inefficient batches. I wouldn't generalize it to "30 beats 120"; it's a result for this workload. Production, meanwhile, peaked around 13,000 records/sec in two windows tied to upstream batch jobs and averaged roughly 5,000. The test wasn't there to predict production; it was there to show CDC would never be the bottleneck.The TakeawayOnce backfill, CDC, and native ingestion coexist, migration state is spread across snapshot boundaries, stream offsets, Kafka buffers, Lambda batches, retry queues, ownership metadata, per-record versions, and per-source cutover. That's why I now think of zero-downtime migration as an ordering problem. The target can't care only about which value arrived last. It has to know which value had the authority to win.What worked for us: capture before the snapshot, keep bulk backfill separate from freshness, buffer CDC while the big transform ran, hand ownership over gradually, stamp versions at the origin, and guard every write with a conditional check. What I'd add next time: an explicit catch-up boundary, fencing for in-flight events at handoff, an equal-version tie-break, and deletes that participate in the same ordering.Copying data gets records into the new system. Ordering decides whether the ones that stay are the right ones.