Method, checks and code
Four sync designs read the same 61 recorded states of a live public feed, so every difference in their final tables comes from the design.
In plain words
Most data teams copy tables out of systems they do not own: an app's database, a vendor's API, a public feed. The copy runs on a schedule. The source does not sit still. Records are corrected, deleted, and sometimes re-published under a new id. The question is which way of copying keeps the table right, and what it costs.
The study uses a public source that does all of this in the open: the US Geological Survey's earthquake service. Magnitudes and locations are revised for hours or days after an event. Some events turn out to be noise and are deleted. An event first published by a regional network is often re-published under the national network's id.
- Sync
- The job that copies a source into a table on a schedule.
- Full reload
- Read everything, replace the table.
- Partition
- A slice of the table loaded together, here by the event's origin time.
- Watermark
- The newest update time a sync has read. The next run asks for anything newer.
- Change feed
- A sync that reads every change, deletions included. Here it is a query: records updated since the last run, deletions included, with replaced ids folded in. Change data capture from a database's write log is the log-based kind.
- Backfill
- Re-running the runs an outage or failure skipped.
- Re-key
- The source re-publishes an event under a new id and lists the old id as an alias.
The source and the recording
The window is every event with an origin time in the 31 days before the recording, about 10,196 live events. The search query a sync uses serves only the current state of each event, so a recorder read the whole window with it, deleted events included, every 4 minutes, 61 times over four hours. Each read is both the truth at that moment and the source every design reads at that moment, through one adapter that applies the service's own query rules. The next read failed when the network dropped, so the record ends there. A query for one event id with includesuperseded=true also returns earlier versions of that event, one event at a time, about 10,000 single-event queries for the window. The designs do not use it.
The four designs
- Full reload. Reads the whole window and replaces the table. Stands in for a nightly snapshot load.
- Time partitions. Each run loads the events whose origin time falls in its 4-minute slot, after a 30-minute wait for late events, and overwrites that slot. It never re-reads a slot. Stands in for a partitioned batch load that copies each slice once.
- Incremental by updated time. Reads events updated after its watermark and upserts them by id. Stands in for the incremental mode of most extract-and-load tools.
- Change feed. Reads events updated after its watermark minus 30 minutes, deletions included. It upserts by id, deletes deleted events and drops rows under any alias of an event it reads. A query-based change feed. Log-based capture from a database's write log fails in other ways, not tested here.
A row contract runs first in every design. An event must have an id, an origin time, an update time, a known status and coordinates, or it goes to a quarantine table with its reason. A field the contract does not know is logged, and the load goes on.
Scoring
After every run each table is compared with the source as recorded at that read, row by row. A row is stale when a tracked field differs: magnitude, magnitude type, status, origin time, location, depth or event type. An event is missing when the table holds it under no id. A row is under an old id when its id is now an alias of a live event, and doubled when the new id is also present. A row is deleted-kept when the source deleted it. Data read is the size of what the service would send for each design's query, from each event's measured size.
The pipeline
The pipeline is a Dagster project with DuckDB as the warehouse. Dagster ran in-process at about 106 MB of memory, against about 305 MB for Prefect with its local server. Each design is one asset per source read. Each load is one transaction, followed by six checks with owners. The checks report after the load commits: a failed ERROR-severity check marks the load as failing a check but does not hold the table back. The ownership file lists what each check does now and what its owner intends. A sensor launches a run every 4 minutes for live use, and a backfill re-runs the partitions an outage skipped. The same assets ran live against the service (4 of 4 runs succeeded) and in the replay. Live, under its scheduler with a code server and one process per step, the whole process tree peaked at 1,177 MB.
From the pipeline code, lines 67 to 85:
@dg.asset(name=key, partitions_def=TICKS, required_resource_keys={"source", "warehouse"},
retry_policy=dg.RetryPolicy(max_retries=3, delay=RETRY_DELAY, backoff=dg.Backoff.EXPONENTIAL),
check_specs=[dg.AssetCheckSpec(name=c, asset=key) for c in CHECKS],
description=f"Earthquake events loaded by the {design.name.replace('_', ' ')} design.")
def _asset(context: dg.AssetExecutionContext):
src, wh = context.resources.source, context.resources.warehouse
pk = context.partition_key
attempt = context.retry_number + 1
if src.fails(design.name, pk, attempt):
raise TransientSourceError(f"planted read failure: {design.name} tick {pk} attempt {attempt}")
db = None
try:
view = src.view(pk) # live, this reads the service
db = wh.connect(design.name)
stats = _load(db, src, view, pk)
except TRANSIENT:
raise # the retry policy retries these: the service or the network may heal
except Exception as exc: # anything else is a bug or bad data: fail now, never retry
raise dg.Failure(description=f"{design.name} tick {pk}: {exc!r}"[:500], allow_retries=False) from excOwners and access are declared in the ownership file, and a test fails if any table or check lacks an owner. The data platform engineer owns retries, schedules, backfills and the count and freshness checks. The analytics engineer who owns the feed owns the row contract, the quarantine and the old-id check. Analysts read the published schema only.
The calls the pipeline makes
At a software company this is the sync of an app's database or a vendor's API into the warehouse, where orders are refunded, accounts merged and records deleted. Six calls decide whether the counts built on it are right.
- Read deletions. The change feed asks the service for deleted events too and deletes them. The alternative, reading only live rows by updated time, never sees a deletion. Getting it wrong keeps every deleted event counted.
- Fold changed ids. When an event arrives, drop any row held under one of its old ids. The alternative, upsert by id alone, counts the event twice. The incremental design ended with 4 doubled.
- Look back 30 minutes. Each run re-reads a short span before its watermark, for rows a live service shows late. No row arrived with an update time older than one already seen, and a lookback of none ended 0 wrong too. Two hours read 3.1 times the data of 30 minutes and ended 0 wrong against 0.
- Retry only what can heal. Network and service errors are retried three times with backoff. Anything else fails at once. Retrying everything would also retry a code error, which never heals, three times before it fails.
- Quarantine, do not fail. Records that break the row contract go to a quarantine table with their reason, and the load goes on. In the replay, about 29 records in each read have no origin time, magnitude or status. Failing on them would stop the table at every run. Loading them would break every count by status.
- Backfill by watermark, not by slice. After the outage the cursor designs ran once from the watermark they held. Time partitions re-read the slices it skipped and ended 77 wrong, because revisions to older slices never come back.
How the cost is computed
The price is a declared US$6.25 per terabyte read (range US$1 to US$25), applied to the bytes each run reads from the source as the service sends them, about 714 bytes a row, at a run every 4 minutes, 131,400 runs a year. Building a change feed is a declared 2 engineer-weeks at US$4,000 a week (range 1 to 4 weeks). The size line is the table size where one year of full re-copies costs as much as building the change feed: about 14 million rows at the declared values, 1.7 to 171 million across the declared ranges. At the line a full re-copy moves about 9.7 GB every 4 minutes. An hourly schedule moves the line 15 times higher, a nightly one 360 times, and a columnar copy a few times smaller than the service's rows moves it up by the same factor. The declared inputs are in one file.
Faults met
Real, in the data: revisions, deletions, re-keys, late events and records that break the contract. Planted: read failures at a seeded rate (one first attempt in ten, three in ten of the retries after a failure), and one outage, every read for one hour skipped in a second arm. Both were declared before the runs.
Predictions, declared before the runs
2 of 7 held.
- Missed. At the last tick of the no-outage arm, incremental by updated time has 5 or more wrong rows and the change feed has 2 or fewer. Observed: incremental 4, change feed 0 wrong rows.
- Held. At the last tick of the no-outage arm, time partitions has the most wrong rows of the four designs, and at least 50. Observed: Change feed 0, Full reload 0, Incremental by updated time 4, Time partitions 105 wrong rows.
- Missed. Over the no-outage arm, the full reload reads at least 100 times the bytes the change feed reads. Observed: 54 times counting the first full load every design made, 424 times after it.
- Missed. With a 0-minute lookback the change feed ends the no-outage arm with at least 1 more wrong row than with the 30-minute lookback. Observed: no lookback 0, 30-minute lookback 0 wrong rows.
- Missed. The alias check fires on every (design, tick) state that holds a duplicate; the count reconciliation fires on fewer than half of the time-partition design's wrong states. Observed: the old-id check fired on 55 of 55 tables with a doubled event, and on 125 of 125 right tables; the row count fired on 59 of 60 wrong time-partition tables.
- Missed. Outage arm, right after the backfill: the full reload has 0 wrong rows; each cursor design is within 2 wrong rows of its no-outage arm at the same tick; time partitions has at least as many wrong rows as its no-outage arm at that tick. Observed: Change feed 0 after the backfill, 0 without the outage; Full reload 0 after the backfill, 0 without the outage; Incremental by updated time 3 after the backfill, 3 without the outage; Time partitions 77 after the backfill, 79 without the outage.
- Held. Schema drift: the lenient loader leaves at least 3,000 of the 10,000 push events with a wrong or missing commit count without failing; the versioned contract leaves none silently wrong. Observed: lenient 4,054 wrong or empty, versioned 0 wrong.
The main limit
The designs read recorded copies of the source, not the service itself, so the replay cannot see a delay under one read between an update and the service showing it.
The four hours held no deletion, though the service's record lists 175 deleted events in 31 days. A second recording of 94 reads, added after the results, held none either (results). The version history query could extend the replay to the whole window, but it serves each version at its update time, which the change feed always reads, so it could size the other designs' errors and cannot make the change feed miss. A week of live runs beside a full reload could, and has not run. In the replay about 29 records a read went to quarantine. Live, no run sent more than one.
The read failures and the outage are planted; the earthquake data is real. This Dagster project stands in for a production Dagster or Airflow deployment, and DuckDB for a cloud warehouse. A publish gate on a staged table is not built. The CI workflow runs the tests on every push to the code's own repository, and its first run passed. Run time is not reported, since every design ran on one machine against one recording.
The price and the build are declared values. The build prices this query-based change feed, not log-based capture. The price is a warehouse's rate for data scanned, applied here to what the service sends. At the line, run time or the load on the source may set it before the price does. Left out: the change feed's own reads (0.24% of a full reload's), its upkeep, and any range on the weekly rate.
Three counts describe the source, not the designs, and were added after the results: the deletion record, declared in a change record with one claim corrected, how long after an event the service last updated it, and how many new events arrived more than 30 minutes late. Slice loads that re-read their last 1, 3 and 7 days were added after the results too, each declared before it ran in a second and a third change record, and are on the results page. A second recording was added after the results as well, declared before it started in a fourth change record.
Rebuild it
Commands to rebuild every numberThe Dagster pipelineThe four designsThe row contractScoring and checksSchema drift loadersTestsAll resultsPredictions as declaredPrice assumptionsThe 1-day re-readThe second change recordThe 3- and 7-day re-readsThe third change recordThe second recording's replayThe fourth change record