Meet Tidewell Parcels
Tidewell Parcels is an invented courier with six depots (Pune, Nagpur, Nashik, Indore, Surat and Bhopal) and a small data team. Every time a parcel is picked up, arrives at a depot, leaves it, goes out for delivery, fails a delivery attempt or is delivered, a handheld scanner sends one line to a file. Operations wants one thing from those lines: how many parcels were delivered each day, by depot, and how long a parcel sits between arriving and being delivered. A pipeline is the code that turns the scanner lines into that answer, every day, without a person copying files by hand.
This track follows one pipeline through eight chapters: how data moves, how it is stored, how it is modelled, how SQL reshapes it, how a scheduler runs it, how a stream differs from a batch, how to know it is correct, and what makes it fast and safe. The company, its depots and every row are invented. The data was generated by a script with a fixed random seed: 20,000 parcels created over about a month from 1 September 2026, and 125,803 scan lines for them. Every number in the chapters comes from running code on that data with Python 3.14.2 and DuckDB 1.5.6 on one Windows laptop. Times are from that machine and will differ on yours; counts will not, because the data is fixed.
The scan file was made messy on purpose, because real feeds are. Of the 125,803 lines, 1,491 are repeats of an earlier line (a scanner that resent a batch), 300 have no depot, and 150 have a timestamp that is not a time. These faults are the reason the pipeline is more than a loop that adds up numbers.
The shape of a pipeline
Whatever the tools, a pipeline has the same parts in the same order. Data starts at a source: a file, a database, an API, a stream of events. It is ingested: copied somewhere the data team controls. It is stored in some layout. It is transformed: cleaned, joined, reshaped. And it is served to a person, a dashboard or another system. Each arrow between those parts is a place where something can go wrong, and each part can be run by a different tool.
A pipeline is not one big program. It is a set of small steps with clear inputs and outputs, so that a failure can be located and a single step can be run again. That idea returns in every chapter: the unit of work is small, it reads something defined, it writes something defined, and running it twice must be safe.
For Tidewell the source is the scanner file, ingest is saving a day's copy untouched, storage is a folder of files or a database table, the transform is the cleaning and counting, and serving is the daily table that operations reads. Naming the five parts for your own pipeline is a good first exercise: if one of them has no owner or no name, that is usually where the first outage will be.
Two words describe the order of the middle parts. In ETL the data is extracted, transformed on the way, and only the result is loaded. In ELT the raw data is loaded first and transformed inside the database or warehouse afterwards. Neither is better in the abstract. The next two sections build both for Tidewell and compare them on the same file.
The scan feed
Each scan line has six fields: an event id, a parcel id, a depot id, an event type, a timestamp and a scanner id. A separate file lists the 20,000 parcels with their origin and destination depot, service level (standard or express) and weight.
event_id,parcel_id,depot_id,event_type,event_ts,scanner_id
E0002258,P000361,D04,delivered,2026-09-25 15:48:48,S08
E0082958,P013341,D05,arrived,2026-09-12 04:06:21,S14
The first design question for any pipeline is its grain: what does one row stand for? Here a row is one scan event, and event_id is meant to name it uniquely. The 1,491 repeats break that promise. Before anything is added up, the pipeline has to decide what a repeat means: the same event reported twice, which should count once. Counting rows instead of distinct events would add 1,491 phantom scans to the totals, a mistake nobody would notice from the result alone because the numbers would still look plausible.
ETL: transform first, load the result
The first version is plain Python: read the file line by line, skip repeats, skip lines that cannot be used, and count delivered events per day.
ETL (python): read 125803 rows, dropped 1491 duplicates, 149 bad timestamps, 293 missing depots; 32 days; 0.24 s
first three days: [('2026-09-01', 68), ('2026-09-02', 480), ('2026-09-03', 692)] total delivered: 19941
The program kept a set of the event ids it had already seen to drop repeats. It dropped 149 bad timestamps and 293 missing depots rather than 150 and 300, because those faults were also applied to some lines that were repeats, and a repeat is dropped before its other faults are looked at. The order of the checks changes which counter a bad line lands in. That is a small example of a general point: the counts a pipeline reports about its own rejects depend on the order of its steps, so the order has to be fixed and written down.
The order changes more than the counters, as a later check showed. Thirteen event ids appear twice, once as a good line and once as a bad one. The program keeps whichever copy it meets first. For eight of the thirteen the good copy came first and the bad repeat was dropped; for the other five the bad copy came first, and the whole event was lost although a good copy existed. Rejecting bad lines first and removing repeats second would keep all thirteen and give 123,875 clean events instead of 123,870. The chapters keep the simpler rule, first copy wins, so that every figure can be reproduced, and chapter 7 comes back to what it costs.
The result is 19,941 delivered parcels over 32 days, out of 20,000 parcels. The missing 59 are explained in chapter 4. ETL's strength is that only clean, small data leaves the transform step. Its weakness is also plain: whatever the transform threw away is gone. If someone later asks how many scans had no depot, the answer is no longer in any table, only in a log line, if anyone kept it.
ELT: load first, transform in the database
The second version loads the raw file into DuckDB untouched, with every column as text, and then does the cleaning in SQL.
raw loaded: 125803 rows in 0.08 s
ELT (duckdb sql): 32 days; 0.04 s; first three days: [('2026-09-01', 68), ('2026-09-02', 480), ('2026-09-03', 692)] total delivered: 19941
rows in the raw table that the transform rejected: 450
raw rows with unparseable timestamp (still queryable): 150
ETL and ELT give the same daily counts: True
The SQL does the same three things: keep one row per event id, turn the text timestamp into a real timestamp with a conversion that returns NULL instead of an error when the text is not a time, and drop lines with no depot. The answer is identical, which is the first thing to check whenever one version of a pipeline replaces another. The raw table still holds the 450 rejected lines, so a person can ask what they were. Counting them straight from the raw table gives 150 bad timestamps and 300 missing depots, because here nothing has been removed yet and the repeats are still present.
One detail from this run is worth remembering. The depot field was empty in the file, and DuckDB read an empty field as NULL, not as an empty string. A first version of the filter compared the depot with an empty string, and quietly kept the NULLs out of its count of rejects. Empty, NULL and the text "NULL" are three different things in different tools, and a quality rule written for one will not see the others.
Why does ELT dominate in warehouse setups? Storage is cheap compared with the cost of redoing a lost source, the warehouse engine is fast at SQL, and keeping the raw copy makes a changed rule easy: fix the SQL and run it again over the same raw table. ETL still makes sense when data must be reduced or masked before it may be stored at all, for example when a field should never reach the warehouse.
Batch and streaming
Both versions above are batch: they take a bounded pile of data, process it, and finish. The scanner file for yesterday is a batch. A batch pipeline is simple to reason about, since its input has a start and an end, and it can be run again on the same input. Its cost is latency: operations learns about a delivery when the next batch runs, not when it happens.
A stream processes events as they arrive, one at a time or in small groups, and never finishes. It answers faster questions ("which parcels have not been scanned for six hours?") but adds work that a batch avoids: events arrive late and out of order, the process must remember where it was after a crash, and a repeated event must not be counted twice. Many systems sit in between with micro-batches: a small batch every minute. Chapter 6 covers streams in detail. For now the useful rule is to pick the slowest schedule the business can accept, since each step towards real time adds failure modes.
Where the raw data lands
Ingest is the least glamorous step and the one that most often decides whether the rest can be trusted. The rule most teams settle on is simple: the first copy is raw and never edited. The scanner file for a day is saved as it arrived, under a name that carries its date, in a place that later steps can read but not change. Everything downstream is derived from it and can be rebuilt from it.
For Tidewell the landing area would hold one file per day, such as scans/2026-09-08.csv. Two habits make that safe. The first is to write the file under a temporary name and rename it when it is complete, so that a step that starts while the copy is still running does not read half a file. The second is to treat a second arrival of the same day as a replacement, not an addition: if the scanners resend 8 September, the file for 8 September is replaced, and the transform runs again for that day only. Chapter 5 returns to this when a scheduler reruns a day.
Raw data also needs a record of where it came from. A line in a log that says "loaded scans/2026-09-08.csv, 14,102 lines, 09:05" costs nothing and answers the first question anyone asks when a number looks wrong: which file did this come from, and was it complete?
What "done" means: counting every row
A pipeline that drops rows must be able to say how many and why. For the scan file the full accounting is:
raw lines 125,803
repeats 1,491
rejected (no depot or bad timestamp, after repeats removed) 442
accepted 123,870
The three parts add back up to the raw count: 123,870 + 1,491 + 442 = 125,803. A check that makes this sum a rule is cheap and catches a surprising number of bugs. If the parts do not add up, rows have gone missing somewhere between steps: a join that dropped unmatched rows, a filter written with the wrong comparison, a step that failed halfway and was not noticed. If they do add up, then a change in any one part is a real signal, such as a jump in rejects from 442 to 4,000, and it can be investigated before the report goes out.
Accounting also protects against the quiet failure. A run that crashes is loud: the scheduler marks it red. A run that "succeeds" while reading an empty file, because the scanners were offline, produces a report of zero deliveries and turns green. The only defence is a rule about the data itself, such as "a day with fewer than half the usual number of scans is not a result, it is a question". Chapter 7 turns these rules into checks.
Three questions for any pipeline
Before writing a line of a new pipeline, ask these:
- What is one row? The grain decides what counting means. If nobody can state it, totals will drift.
- What happens if it runs twice? Schedulers retry, people press the button again, a failed run is repeated. A step that doubles its output when repeated is a bug waiting for the first retry. Chapter 4 shows how to make loads safe to repeat.
- What happens when the data is late, wrong or missing? Scanners resend, clocks drift, fields come empty. A pipeline that assumes clean input works only until the first bad day.
These three questions are more useful than any tool name, and they are the questions a reviewer of someone else's pipeline asks first.
Mistakes that recur
- Counting rows when the unit is an event. Repeats inflate every total. Fix the grain and remove repeats by the event id.
- Throwing away raw data. If the raw lines are not kept, a changed rule cannot be applied to the past.
- Cleaning rules that depend on step order, undocumented. Reject counts then differ between runs of different code, and nobody can say which is right.
- Mixing up empty, NULL and the word "NULL". Check how each tool reads a missing value.
- Trusting that two versions agree. When a pipeline is rewritten, compare the new output with the old on the same input, as above.
- Choosing real time because it sounds modern. A daily report does not need a stream.
Carry forward, in short: a pipeline moves data from a source to a person through ingest, storage, transform and serve; ETL transforms before loading and ELT loads raw data and transforms it in the warehouse; both gave 19,941 delivered parcels from the same 125,803 lines; batch is simpler and streaming is faster; and the questions to ask are what one row is, what happens on a rerun, and what happens when data is wrong. The next chapter looks at the first of those choices from the storage side: what format the scan lines should be kept in.