Skip to content

Diogo TravassosData leadership · Analytics · Decision-making

Public dataSynthetic faults

Data quality scorecard · table layers

In a self-test on 54 days of public trip data landed four times a day as raw, cleaned and modeled Delta tables, the scorecard's checks caught 6 of 7 planted faults at the raw layer, 5 at the cleaned layer and 3 at the modeled layer; no layer caught 1, a batch that arrived a day late.

The same checks ran every morning on what each layer had received since the morning before. The raw layer, which keeps every batch as delivered, saw every fault but the late one. The cleaned layer keeps one row per trip, so a batch delivered twice vanished into it. The modeled table has one row per day and no trip ID or distance in metres, so three of the seven checks cannot run there, and it published both unit faults' wrong miles without a flag. The late batch carried clean rows: with no batch outstanding, raw and cleaned were complete only up to 30 hours back, missing one 6-hour window of February 17 (13,644 trips), and the modeled table published that day short for a day, then restated it. Day volume missed it narrowly: the short day was 0.6955 times its 14-day median against a 0.6 bound.

Key figures
Faults caught at the raw layer6 of 7every batch as delivered; it missed only the late batch with clean rowsAt the cleaned layer5 of 7one row per trip absorbed the replayed batch, so no check there could see itAt the modeled layer3 of 73 of the 7 checks cannot run on a daily table; both unit faults changed its published miles unflaggedPredictions held7 of 7written down with bands before any run, but most follow from how each layer is defined or were known from the warehouse cost part's run on the same files

Main limitation One author wrote the layers, batches, faults and predictions: 7 faults on 54 days of a public trip sample, with the batches simulated on one machine. The catches describe these checks on these faults, and many follow from how each layer is defined.

Which layer caught which fault

Each fault replays February on its own copy of the three tables, from the clean run's state after the checks on the morning of February 1. A fault counts as caught at a layer when a check there flags one of its planted days on any morning up to the clock (06:00 on February 24), and the clean run's same check at the same layer did not flag that day.

Each fault: the checks that caught it at each layer, the two checks that compare layers, and the modeled table at the clock against the clean run's
FaultRawCleanedModeledAcross layersModeled table
Missing day
None of February 23's four batches arrives.
FreshnessFreshnessFreshnessMissedWrong on February 23
Missing fares
30% of February 22's fares arrive blank.
Missing-fare limit, missing-fare anomalyMissing-fare limit, missing-fare anomalyMissing-fare limit, missing-fare anomalyMissedWrong on February 22
Kilometres as miles
Every February 22 distance in miles arrives multiplied by 1.609344.
Units checkUnits checkMissed (the units check cannot run here)MissedWrong on February 22
Replayed batch
February 22's 06:00 to 11:59 batch is delivered again, unchanged, under a new batch ID, 20 minutes after the first.
Duplicate content, duplicate trip IDsMissed (one row per trip absorbed it)Missed (nothing changed here)MissedSame as the clean run
Late batch
February 17's 18:00 to 23:59 batch arrives a day late, after February 18's last batch. Its rows are fine.
MissedMissedMissedMissedSame as the clean run at the end; February 17 published short for a day
Late batch with missing fares
The same late batch, with 30% of its fares blank.
Missing-fare limit, missing-fare anomalyMissing-fare limit, missing-fare anomalyMissing-fare limit, missing-fare anomalyMissedWrong on February 17
Faulty backfill
February 2 to 8 are delivered again at 04:00 on February 24, same trips, with every distance in miles multiplied by 1.609344.
Duplicate content, duplicate trip IDs, units checkUnits checkMissed (the units check cannot run here)MissedWrong on February 2 to 8

Three patterns. First, what the cleaned layer removes, no check above it can see: the replayed batch carried trips already loaded, so the one-row-per-trip merge kept one copy of each: the cleaned table held the same trips with the same values as the clean run's (only the load time and batch ID on those rows changed), and the modeled table came out identical. Only the duplicate checks on the raw layer flagged it. That is the cleaned layer working as designed, and also the reason a replay is invisible from there.

Second, what the modeled layer drops, it cannot check. The daily table keeps trips, fares and sums of miles and seconds, not the trip ID or the distance in metres, so the duplicate and units checks cannot run there; they are reported as "cannot run", not as passed. Both unit faults reached the published miles: February 22 for the unit change, February 2 to 8 for the backfill, which rewrote 189,293 cleaned rows two hours before the clock. The units check on the raw and cleaned layers caught both.

Third, the faults every layer caught were the ones the daily table still shows. Blank fares move the published missing-fare share: 30.3% on February 22 against 0.5% in the clean run, and 13.3% on February 17 when the late batch carried them, against 0.6%. A missing day stops every layer's clock, so freshness caught it everywhere.

The two checks that compare layers, distinct trip IDs in raw against cleaned rows and modeled trips, and cleaned rows against modeled trips, caught none of the seven. Each layer is built from the one below, so a fault either reaches every layer, and the counts still agree, or is absorbed by the cleaned layer's key, which the raw count also deduplicates.

A backfill re-sends trips already loaded, so the duplicate trip ID check on the raw layer flags every backfill, faulty or not; the units check is the one that saw this backfill was wrong. Duplicate content flagged four of its seven days at raw, and February 4 and 5 as well, which it also flagged on the clean run, so those two do not count.

How fresh each layer was

Freshness is measured two ways after every batch and every build. Batches behind counts delivered batches a layer does not reflect yet, which a pipeline can see about itself. Windows behind counts the 6-hour windows of event time the feed had delivered by then that the layer does not hold completely, measured against the full clean feed, which a pipeline does not have. A hole means the layer holds rows of a window newer than the last one it holds completely.

With February 17's last batch a day late, raw and cleaned fell behind in event time while no batch was outstanding; the modeled table fell 8 windows behind, twice its clean-run worst of 4.

Windows behind the full feed (6 hours of event time each), after each batch or build.

Raw and cleaned (identical)ModeledModeled, clean run

Windows behind after each event, February 17 to 19, with the late batchRaw and cleaned climb from 0 to 5 windows behind while the late batch is missing, then drop to 0 when it lands; the modeled table peaks at 8 windows behind, against 4 for the clean run, and is back to 0 after the next build.0246807:00Feb 1713:0019:0005:00Feb 1807:0013:0019:0001:00Feb 1901:0005:00ModeledRaw and cleanedFebruary 17, 07:00, February 17's 00:00 batch lands: raw and cleaned 0 windows behind, modeled 1; clean run modeled 1February 17, 13:00, February 17's 06:00 batch lands: raw and cleaned 0 windows behind, modeled 2; clean run modeled 2February 17, 19:00, February 17's 12:00 batch lands: raw and cleaned 0 windows behind, modeled 3; clean run modeled 3February 18, 05:00, the daily build of the modeled table runs: raw and cleaned 1 window behind, modeled 4; clean run modeled 0February 18, 07:00, February 18's 00:00 batch lands: raw and cleaned 2 windows behind, modeled 5; clean run modeled 1February 18, 13:00, February 18's 06:00 batch lands: raw and cleaned 3 windows behind, modeled 6; clean run modeled 2February 18, 19:00, February 18's 12:00 batch lands: raw and cleaned 4 windows behind, modeled 7; clean run modeled 3February 19, 01:00, February 18's 18:00 batch lands: raw and cleaned 5 windows behind, modeled 8; clean run modeled 4February 19, 01:00, February 17's 18:00 batch lands: raw and cleaned 0 windows behind, modeled 8; clean run modeled 4February 19, 05:00, the daily build of the modeled table runs: raw and cleaned 0 windows behind, modeled 0; clean run modeled 0
Show the data
Each batch and build, February 17 to 19, with the late batch
WhenEventRaw and cleaned, batches behindRaw and cleaned, windows behindHoleModeled, batches behindModeled, windows behindClean run, modeled windows behind
February 17, 07:00February 17, 00:00 to 05:59 batch lands00No111
February 17, 13:00February 17, 06:00 to 11:59 batch lands00No222
February 17, 19:00February 17, 12:00 to 17:59 batch lands00No333
February 18, 05:00Daily build of the modeled table01No040
February 18, 07:00February 18, 00:00 to 05:59 batch lands02Yes151
February 18, 13:00February 18, 06:00 to 11:59 batch lands03Yes262
February 18, 19:00February 18, 12:00 to 17:59 batch lands04Yes373
February 19, 01:00February 18, 18:00 to 23:59 batch lands05Yes484
February 19, 01:00February 17, 18:00 to 23:59 batch lands00No584
February 19, 05:00Daily build of the modeled table00No000

On the clean feed, over February's 115 batches and builds, raw and cleaned were 0 batches and 0 windows behind every time. The modeled table, built once a day at 05:00, was 0 to 4 batches behind, up to 24 hours of event time, which is what a daily build means.

With the late batch, nothing in the pipeline looked behind. Raw and cleaned took every batch delivered, so they stayed 0 batches behind, yet once February 18's batches began to arrive they held them while missing the last window of February 17: a hole on 4 events. At worst they were complete only up to 5 windows (30 hours of event time) back, while the rows they lacked were one 6-hour window, 13,644 trips. The modeled table was at worst 8 windows (48 hours) behind, against 4 on the clean run.

One trace, from the records. At 19:00 on February 17 the 12:00 to 17:59 batch landed: raw and cleaned held every window due, and the modeled table was 3 batches behind, as every evening. At 01:00 on February 18 the 18:00 to 23:59 batch did not arrive. The 05:00 build published February 17 with 18,479 trips. At 06:00 no check at any layer flagged February 17: the newest load was 11 hours old, inside the 12-hour freshness limit, and 18,479 trips were 0.6955 times the median of the 14 days before (26,568.5), above the 0.6 bound by about 2,538 trips. Through February 18 raw and cleaned took every batch on time while their gap grew. At 01:00 on February 19 the late batch landed right after February 18's last one, and both layers were complete again. The 05:00 build restated February 17 at 32,123 trips, and no check on any morning flagged February 17.

The miss sits near the bound. Day volume would have flagged February 17 had it held 2,538 fewer trips, so whether a late batch is caught this way depends on which window arrives late and on the 0.6 bound, which this round took unchanged from the warehouse cost part. Anyone who read February 17 from the published table on February 18 saw a day short by the late window's trips, and no check said so.

What I predicted, and what held

Seven predictions, each with a band, were committed with the design before any table was built from the feed. 7 of 7 held; none missed, none untestable. Most were safe bets, for the reasons below.

  1. Held. Faults caught, of 7: raw 6 [band 6], cleaned 5 [5], modeled 3 [2 to 3]. Measured: Raw 6, cleaned 5, modeled 3.
  2. Held. The late batch with clean rows is caught at no layer. Measured: No check flagged February 17 at any layer.
  3. Held. The replayed batch is caught only at raw, by the duplicate trip ID check, and the modeled table equals the clean run's. Measured: Caught only at raw; the modeled table matched. The duplicate content check flagged it at raw too, which the prediction did not name.
  4. Held. Both unit faults are caught at raw and cleaned by the units check, missed at modeled, and both change the modeled table's miles. Measured: All four parts as stated.
  5. Held. The two checks across layers catch 0 of 7 [0]. Measured: 0.
  6. Held. Freshness: on the clean feed raw and cleaned 0 batches behind, modeled 0 to 4 [0 to 4]; with the late batch, raw and cleaned show a hole, 4 to 5 windows behind at worst [4 to 5], with 0 batches behind; the modeled table publishes February 17 short at the February 18 build and restates it at the February 19 build. Measured: Clean: 0 and 0 to 4. Late: a hole on 4 events, worst 5 windows, 0 batches behind; published short, then restated.
  7. Held. Clean false alarms on the February mornings: duplicate content flags the same dates at raw and cleaned [5 to 15 of the 23 February dates]; the modeled layer flags no clean date [0]. Measured: 12 of 23 at raw, the same 12 at cleaned, 0 at modeled.

That score says less than it seems. Predictions 2 to 5 follow almost directly from how the layers and the checks are defined: a key that keeps one row per trip has to absorb a replay, and a daily table without a distance column cannot run a units check. Their holding shows the code does what the design says. Other outcomes were known before the run, because the warehouse cost part had already run the same checks on the same 54 files: there the duplicate content check flagged the same 12 clean February dates (prediction 7), flagged the same four days of the faulty backfill and the same two clean ones, and caught rows sent twice, so its flag on the replayed batch could be expected. Prediction 6's band follows from the batch schedule. The outcomes that could have failed on the data were the modeled count in prediction 1 (would the late batch's blank fares still move a whole day's share past the limit?) and the margin in prediction 2: the short day stayed above the 0.6 bound, narrowly.

What the checks flag on clean data

On the clean feed the duplicate content check flagged 12 of the 23 February dates at the raw layer and the same 12 at the cleaned layer (21 dates over the whole run). It compares every field except the trip ID, and at about 26,000 trips a day a few different trips share every field it compares. The units check flagged 1 date over the whole run, a trip with no distance. The modeled layer flagged nothing on clean data, and the two checks across layers flagged nothing either. Clean flags were subtracted when counting catches, by the rule written down before the run; they are why the duplicate content check counted on only four of the backfill's seven days. Both checks were sized on a month of 300 trips a day: at real volume the duplicate content rule needs the start time in its key, and the units rule needs to treat a missing distance apart.

Where to run each check

  1. Duplicate checks belong on the raw layer. The cleaned layer's key absorbs a replayed batch, so raw is the only place it shows. A backfill trips them as well, so read them beside a value check such as units before calling a backfill bad.
  2. Row-level value checks run on raw and cleaned. The units check caught both unit faults there and cannot run on a daily table, which still published the wrong miles. A check that needs a column or a key must run on a layer that still has it, and a layer where it cannot run should say "cannot run".
  3. Checks on daily numbers also run on the modeled table. The missing-fare checks and freshness caught the blank fares and the missing day at every layer, the modeled table included, and the modeled table is what readers see.
  4. Freshness by newest load time cannot see a late batch while other batches keep arriving. Add a completeness check per event-time window: for each window that should have arrived, compare the rows it holds with what that window usually holds. Here the late window was 13,644 of February 17's 32,123 trips, and the clean windows ranged from 1,461 to 14,297 trips, so the expected count must be per window of the day, not one figure. This round did not test such a check.
  5. Counts across layers caught nothing here. These faults either passed through every layer or were absorbed by the key. They are for faults in the pipeline itself, a layer left half built or a restore that went too far back, which the pipeline recovery part tested.

In plain words

Many data teams land their data in layers: the raw data as it arrived, a cleaned copy with one row per record, and the modeled tables a dashboard reads. Data checks have to run somewhere, and each layer sees different things. I replayed the same public trips four times a day into three such layers, ran the scorecard's checks on every layer every morning, and planted seven faults to see which layer caught which, and how far behind each layer was after every batch.

Raw layer
Every batch as delivered, never changed. Often called bronze.
Cleaned layer
One row per trip, the latest delivery wins. Often called silver.
Modeled layer
One row per day, the numbers a dashboard reads. Often called gold.
Batch
The trips of one 6-hour window of a day, delivered together.
Event time
When a trip started, as opposed to when its batch arrived.
Open table format
A way to store a table as plain files plus a log of every change, so any tool that reads the format sees whole batches only. Delta and Iceberg are two.
Replay
A batch delivered a second time, as after an outage.
Backfill
Old days delivered again, to restate them.

Limits

Use this at your company

To place the checks of a pipeline of your own the same way, paste this prompt into an AI assistant that can query your warehouse.

This method comes from Diogo Travassos's study "Data quality scorecard: table layers" (https://diogotravassos.dev/data-quality-scorecard/table-layers.html). If you can open links, read it first: it works the method through end to end and shows the checks that caught mistakes. The steps below stand on their own if you can't.

Help me find out at which layer of our pipeline each of our data checks should run, and how far behind each layer can fall without any check noticing.

Data you need from me: the raw landing table with a load time and batch ID on every row, the cleaned table keyed on a row ID, the published daily table, our data checks, the schedule our batches arrive on, and at least a month of load history.

Method:
1. On a copy of the history, rebuild the three layers batch by batch in arrival order: raw keeps every batch as delivered, cleaned keeps one row per key (the latest load wins), and the published table is rebuilt on its usual schedule from the cleaned rows it has.
2. Run every check on every layer each morning, over what that layer received since the morning before. Where a check cannot run on a layer (the key or the column it needs is gone), record that, never a pass.
3. After every batch and every build, record how far behind each layer is: in batches it has not reflected yet, and in hours of event time it holds completely, measured against the full history.
4. Replay the last month again with planted faults: a missing day, a day of blank values, a unit change, a batch delivered twice, a batch that arrives a day late with clean rows, the same late batch with blank values, a backfill with bad values. Write down, before running, at which layers you expect each fault to be caught.

Checks before trusting the answer:
- Run every check on the clean history first, and count a planted fault as caught at a layer only on a day the clean run's same check at that layer did not flag.
- Replay the clean month a second time from the same starting state; rows, flags and freshness must repeat.
- Read every layer with a second reader at the end and confirm row counts and sums match.

Report back: a table of fault by layer with the check that caught it or "missed", which checks cannot run on which layer, the largest gap in event time each layer showed with no batch outstanding, which faults changed the published table without any check firing there, and the limits: how much data, how many batches, and that the batches were replayed, not live.

In your report, say which study you followed and link it: https://diogotravassos.dev/data-quality-scorecard/table-layers.html

Method and checks

Data

City of Chicago, Transportation Network Providers Trips: every trip that started in the first 15-minute slot of every second hour, January 1 to February 23, 2023, the same 54 daily files as the warehouse cost part (1,402,214 trips), each checked against its SHA-256 in that part's data notes before use. Trip IDs are replaced by a hash, no location finer than the community area is kept, and the distance in metres is miles times 1609.344.

Batches and layers

Each trip day is cut into four batches by start time, 00:00 to 05:59, 06:00 to 11:59, 12:00 to 17:59 and 18:00 to 23:59, and each lands one hour after its window closes: 216 batches for the clean feed. The raw layer appends every batch as one commit, partitioned by load date. The cleaned layer reduces each batch to one row per trip ID and merges it on the trip ID, limited to the trip-date partitions the batch touches; the latest load wins. The modeled layer is built once a day at 05:00: every trip date with a cleaned row written since the last build is recomputed and replaced in one commit. Every commit carries its batch ID or build time. DuckDB computes every step on one thread and reads every layer through its Delta extension.

Checks

The scorecard's version 2 checks, as ported to SQL in the warehouse cost part, with the same thresholds: freshness (newest load or build more than 12 hours old), the 5% missing-fare limit, day volume (under 0.6 times the median of the 14 days before), duplicate trip IDs, duplicate content, the units check and the missing-fare anomaly rule. Every morning at 06:00 each layer is checked over what it received since the morning before: raw rows loaded, cleaned rows written, modeled rows built. Across layers, over the trip dates loaded since the morning before: distinct trip IDs in raw against cleaned rows and modeled trips, and cleaned rows against modeled trips. A test confirms that on the raw layer every check flags exactly what the warehouse cost part's own check code flags on the same rows.

Why Delta

Delta and Iceberg are both open table formats that DuckDB reads. Delta is used because the pipeline recovery part already wrote its layers as Delta tables with the same open-source Python package, so the study adds nothing to install; a local Iceberg table needs a catalog for every commit, one more moving part on a laptop. What this round uses, an atomic commit per batch, metadata on each commit, partitions, a merge on a key, a replace of chosen partitions, is common to both, and the question does not depend on which is used.

Runs and machine

One clean run of all 216 batches; seven fault runs, each replaying February on its own copy of the tables from the clean run's state after the checks on the morning of February 1; one repeat of the clean February from the same state. The repeat matched the clean run on all 644 records of checks and freshness, on the cleaned table row for row, and on the modeled table's counts. At the clock every layer of every run was also read with the deltalake package's own reader; row counts and sums matched DuckDB's in every case. Tools: DuckDB 1.5.6, deltalake 1.6.6, pyarrow 26.0.0, Python 3.12.3. Machine: AMD Ryzen 7 5800 8-Core Processor, 16 threads, 35 GB, Linux under Windows, shared with other work.

Each layer of the clean run at the clock
LayerRowsCommitsData filesData
Raw1,402,21421621675.4 MB
Cleaned1,402,21421621675.4 MB
Modeled5454540.16 MB
Decided before the runs, and what changed

The layers, batches, checks, freshness measures, faults, catch rule, predictions and headline rule were committed before any table was built from the feed. The code was developed on small synthetic tables and on the clean January 1 to 5 only, so no outcome of this run was seen before it. Several were known in advance all the same, from the warehouse cost part's run of the same checks on the same files (see the predictions).

Four things changed after the measured run began. First, a speed change: after the clean run, the first three fault runs and part of the fourth, the freshness bookkeeping was made to recount only the dates each batch carries instead of every window. The measure is the same; the repeat ran on the new code and matched the clean run, which ran on the old, event by event. The repeat replays the clean feed only, in order, so it never tests the bookkeeping on batches that arrive out of order; for those (the late batch and the backfill) the equivalence rests on a unit test of out-of-order deliveries and on a full recount, both added after the results: the raw and cleaned tables read at the version each February delivery of the late batch, late batch with missing fares and backfill runs wrote, every window counted, matched the recorded windows behind, complete-through windows and holes at all 283 deliveries (batches behind is covered by the unit test only). The hash of the code is recorded for every stretch of every run. Second, Change 1 to the protocol, made after the results: the protocol asked the repeat's modeled table to match exactly, and its sums differed on 6 dates by at most 7.3e-10, from the order in which the sums were added. The repeat is now judged on sums within 0.01, the tolerance the protocol already set for comparing fault runs with the clean run, and the exact largest difference is reported beside it. Read strictly, the protocol as first written calls this a method failure. Third, descriptive figures computed after the results: the late window's trips, the short day against its 14-day median, the published missing-fare shares, and the cleaned rows that differ from the clean run, saved with the records so the summary rebuilds from them. Fourth, the out-of-order test and recount above (fresh-recount.json).