PRACTITIONERCHAPTER 12

Pipelines and data modelling: the analytics engineer's job

Turn a raw table you do not control into a model people can trust: declare the grain, say what every column means, test the assumptions, and decide where a source defect gets fixed

45 MINDATA AND MLUPDATED 2026-11-21
PREDICT

You build a payout table from the 2014 system's extract. The primary key payout_id passes both a unique test and a not-null test, on every run. What have you learned?

An analyst answers a question. A data engineer makes sure data arrives. Between them sits the work this chapter covers: taking raw tables from a system you do not own and building modelled ones with a stated grain, columns that mean what they say, and tests that fail loudly when they stop being true. The title that grew up around it is analytics engineer, and why data roles exist places it between the data engineer and the analyst. In a small company one person does all three jobs, so the skill matters more than the title.

The technique of moving data, with schedulers, loaders and warehouses, belongs to the Data Engineering course, which is not written yet. This chapter teaches the analytics engineer’s angle: the model, its tests, and the argument about who fixes what.

The model: layers between the source and the question

A raw extract is shaped by the system that wrote it. Its names are historical, its statuses carry meanings nobody wrote down, and its amounts may be in the wrong unit. A report built directly on it inherits every one of those quirks, and every analyst who queries it has to rediscover them. The fix is a small number of layers, each with one job.

Layer What it does What it must not do
Source The raw table, copied in unchanged and never edited Be queried by analysts directly
Staging One model per source table: rename, cast types, convert units, one row in for one row out Join, filter or apply business rules
Intermediate Joins and rules that more than one model needs, such as deriving a state Be a place for a one-off report
Mart One model per business entity or process, at a stated grain, for people to query Change meaning between releases without notice

dbt, the tool most analytics engineering is done in, recommends a similar split between staging, intermediate and mart models; the names matter less than the discipline. Each layer can be tested on its own, and a wrong number can be traced to the layer that made it. Keeping the raw copy untouched means you can rebuild everything after a mistake, which is the property the section on re-runs depends on.

The layers also explain the title. The analytics engineer owns the middle of this stack as a product: it has users, a definition of done, a change process and tests. An analyst who writes a clever query is producing an answer. An analytics engineer who writes a model is producing something that other people’s queries will stand on. The standard is higher, and so is the cost of a quiet mistake.

Grain: what one row stands for

Ralph Kimball’s dimensional modelling begins with the grain: the business definition of what one row of a table represents. His four steps are to choose the business process, declare the grain, identify the dimensions, and identify the facts. The order is the point. If you decide the columns first, the grain is whatever the columns happen to give you, and two people will disagree about it when a total looks wrong.

For a payout, the grain is easy to say: one row per payout, meaning one instruction to pay one account an amount. Say it in the model’s description, and then test it. The test is a unique check on the key, but the declaration is the part that protects you. A mixed grain is the commonest way to produce a double-counted total. If you join payouts to the batches they came in and then sum the batch fee, every payout in the batch repeats it. The modelling and normalisation chapter shows the same hazard from the database side: a fact stored in two places drifts, and a value copied onto many rows is summed many times.

A payout also changes over time. It is created, queued, released, paid or failed, and sometimes reversed. Kimball describes three kinds of fact table: one row per transaction event, one row per period, and one row per process that accumulates milestones as it moves. A payout fits the third, the accumulating snapshot: one row per payout, with a timestamp for each milestone filled in as it is reached. That shape answers the questions people ask, such as how long payouts take and how many are waiting, without making every analyst reconstruct a state from a pile of events.

What a column must mean

Naming a column is a promise. A model’s value is that two people who select status get the same thing, and that the thing is what the name says. Four checks catch most broken promises.

Units. The 2014 system stores amount in naira with two decimal places. The ledger and the rest of the platform use integer kobo, because floating-point money drifts, as the money in software chapter shows. Staging converts it once, with a rounding rule you have read and written down, and calls the column amount_kobo so the unit is in the name. Convert in one place. Two conversions in two models are two chances to disagree by a kobo.

Time. A timestamp without a zone is a guess. Say whether created_at is Lagos time or UTC, and whether it is the moment the instruction was received or the moment it was written. The reconciliation chapter’s lesson on timing applies: a payout booked at 23:30 can belong to the next day on the other side.

Nulls. A null can mean not yet, not applicable, or unknown, and they are three different facts. Decide which each nullable column means and write it in the description. A null bank_ref is the interesting one in this chapter, as the next section shows.

Status. A status column is where meaning hides. Most systems write a status for the system’s own convenience, such as the step a job reached, and downstream readers assume it describes the customer’s reality. The two diverge exactly when something goes wrong, which is when you most need the number.

The PROCESSED problem

Northmere’s system writes one of three values to status: PROCESSED, FAILED and REVERSED. PROCESSED is written when the batch step finishes with the row. A separate settlement job later sends the payout to the bank’s payment rails and, on success, writes the bank’s reference into bank_ref. So a PROCESSED row with a bank_ref has been paid. A PROCESSED row without one has not, and it can be in one of several conditions: queued for a release date, held for lack of funds in the employer’s account, or stuck. The status does not say which.

The method is to find the truth in another column or another system, and to prove it. In the illustrative October extract there are 412,600 rows marked PROCESSED. Of these, 31,400 have no bank_ref, which is 7.6%. At an average of ₦120,000 a payout, that is about ₦3.77bn counted as paid in any report that trusts the status. You cannot decide what those rows are from the extract alone. Silvia, who leads the team that runs the system, can say how long a payout waits legitimately. Suppose she says three days. Then you can define a model state:

payout_state Rule Meaning
paid status is PROCESSED and bank_ref is present Reached the bank’s rails
queued status is PROCESSED, no bank_ref, status written within three days Waiting, as designed
stuck status is PROCESSED, no bank_ref, older than three days Needs a person
failed status is FAILED The system gave up
reversed status is REVERSED Paid, then returned

Two things make this a model rather than a patch. The rule is written in one place, a model other models read. And the three-day window is a named assumption with an owner, tested, rather than a number buried in a report. A reader sees stuck, asks what it means, and finds the definition.

Tests: assumptions written as queries

A dbt data test is a query that returns the rows that break an assumption. dbt reports the test as failing when it returns rows and passing when it returns none. That framing is the skill: you write each test as a search for the bad case.

dbt ships four generic tests. unique and not_null protect the grain. accepted_values checks that a column holds only a listed set of values, and relationships checks that every row in one table has a parent in another, such as every payout having an employer. They are cheap and you attach them to columns in a YAML file. Use them everywhere, and do not mistake them for the whole job.

The tests that pay for themselves are the ones that encode what you learned about the source.

  • accepted_values on the source status. If the 2014 system ever writes a fourth value, such as HELD, the pipeline stops and tells you, instead of letting the row fall through your rule as something it was not designed for.
  • A singular test on the state rule. A short SQL file that returns any paid row with no bank reference, or any row that matches two states. It guards the rule against the next person who edits it.
  • A freshness check. dbt can compare the newest value of a timestamp column in a source to the clock and warn, then error, past thresholds you set with warn_after and error_after. A pipeline that quietly stops loading is more dangerous than one that fails, because the dashboard keeps showing yesterday’s number with today’s date.
  • A reconciliation test. The sum of paid amounts for a day should equal the bank’s credits for that day, after the timing items you can name. The reconciliation chapter teaches the matching; the analytics engineer’s contribution is to make the check run on every build, so a gap appears as a failed test instead of a surprise at quarter end.
  • A volume check. Row counts within a plausible range of the same weekday last week. It catches the half-loaded extract that is complete in shape and wrong in size.

Give each test a severity. A failure that makes a number wrong should stop the build and keep the old data in place. A failure that only needs a person to look, such as a handful of stuck payouts, should warn and notify. If every test blocks, the team learns to disable tests, and if none does, the tests are decoration.

Tests also cost something. They run on every build, they need maintaining, and a noisy one trains people to ignore it. Test what would hurt if it were wrong, not every column because you can.

Fix it in the pipeline or at the source

The PROCESSED problem has an owner who is not you. Silvia’s team can change what the system writes. You can only change what you read. There are three honest answers, and each is right in some circumstance.

Fix it in the pipeline. Derive the true meaning in your model, as above. It is fast, it is under your control, and it protects today’s report. Its cost is that you now maintain a workaround, and the rule can drift from the system’s real behaviour without anyone telling you. It is the right answer when the report is due and the source owner cannot move.

Ask the source team to fix it. A system that writes an honest status helps every consumer, not only you, and the workaround disappears. The cost is time: the 2014 system is changed through a release process, and the change competes with that team’s own work. Waiting alone leaves the report wrong in the meantime.

Flag and publish. Ship the report with a clear warning that the status is unreliable. It is honest and instant. It also leaves every reader to do the arithmetic you could have done, and a caveat in a footnote does not stop a treasury forecast being built on the green line.

Most experienced teams do the first and second together, in order: derive now, with the rule written down and tested, and raise a request with the owner that names the defect, the evidence and the number. The request is easier to grant when it arrives with a count and a naira figure, and when you say you will delete your workaround once the source is fixed. Whichever route you choose, the conversation with the source team is part of the job, not a favour. This is the same bargain the asking the right question chapter describes at the other end of the pipe: you are making the other person’s decision easy.

Pipelines you can run twice

Models are rebuilt on a schedule, and the schedule fails. A job dies halfway, a source is late, a rule changes and last month needs recomputing. The property that saves you is that re-running is safe. Maxime Beauchemin’s essay on functional data engineering argues for tasks that are deterministic and idempotent, writing their output by overwriting a whole partition, such as one day, rather than by inserting and updating rows. Run it twice and you get the same table. Find a bug in the rule, fix it, rerun the affected days, and the history corrects itself.

The opposite habit, appending rows and patching them later, makes a bad run permanent. The test is blunt: could you drop the model’s table tonight and rebuild it from the raw copy by morning? If not, something in the pipeline holds state that nobody wrote down.

Rules that pick the current state of a payout from many rows use window functions, such as ranking a payout’s events by time and keeping the first. Aggregation, windows and CTEs covers the pattern and its cost. When the marts grow large and are read by aggregation, the layout of the store matters; columnar and analytics explains why the same query is fast in one layout and slow in another.

Where practitioners disagree

Dimensional modelling or one wide table. Kimball’s star schemas keep facts and descriptions separate, so a description is stored once. Many teams now build wide tables that join everything in advance, because storage is cheap and analysts prefer one place to query. Stars win when definitions must be shared across many questions. Wide tables win when a few dashboards need speed and simplicity. Many teams keep a star underneath and publish a wide view on top.

Model early or model late. Some teams model each source on arrival so the first analyst finds clean tables. Others query raw data until a pattern repeats, and model only what earns it. Modelling early costs upkeep on tables nobody uses. Modelling late means the first answers are slow and the first definitions differ. A sensible middle is to model the entities the business already argues about, such as the payout, the customer and the order, and leave the rest raw.

Who owns the tests. Source owners can test their own data, or the consumer can, since the consumer knows what they need to be true. In practice both do, and the interesting tests are the consumer’s: the source owner has no way of knowing that your report assumes a bank reference means paid.

Day to day

Daily, ten minutes. Read the overnight build before anyone asks. A failed test is a message about what the data did, not a nuisance. Triage by severity: blocking failures first, warnings after. Leave a note on the status page when a number is held back, because silence looks like an outage of trust.

Per request, a day or two. A new model starts with the question brief, a conversation with the person who will use it, not with SQL. You write down the entity, the grain and the first three questions it must answer. You then read the source with someone who knows it, before you write a column, and ask what each status and null really means. This conversation is the highest-value hour of the job.

Weekly. Review one model’s failures and near-misses with the analysts who use it. A thirty-minute session with a standing agenda: new failures, tests that fire too often, definitions that people have started to bend. Check the source team’s backlog for the requests you raised, and chase the one that costs you most.

Monthly. Reconcile a mart against a trusted external figure, such as the bank statement or the finance ledger, and publish the difference even when it is zero. Retire models nobody has queried in ninety days.

With the source team. A standing fortnightly conversation with whoever runs each important source, as short as fifteen minutes. The aim is to hear about a change before it breaks you, and to turn your workarounds into their fixes.

You will spend more time reading other people’s systems and writing definitions than writing code. The writing is what the code is for.

BY ORG SIZE
STARTUPunder 30 people

There is one person, possibly an engineer who also writes the queries, and no separate warehouse team. Model the two or three entities the founders argue about and skip layers you do not need: a staging model and one mart is plenty. Write the grain and the meaning of each status in a one-line description and add the four generic tests. Ask the engineer who wrote the product to change a bad status in the same week, while they remember why it exists.

SCALE-UP30 to 300

Several analysts now rebuild the same joins and two reports disagree. This is when the analytics engineer role is created. Adopt the layers, put every model in version control with review, and run the build on a schedule with alerts. Source systems belong to other teams who have their own roadmaps, so you learn to raise defects with evidence and a number, and to keep a list of workarounds you intend to retire.

ENTERPRISE300 and up

Sources are old, many and owned by teams who release quarterly through a change board, as in a bank’s core systems. You cannot ask for a status change and expect it soon, so the derived model is the interface and the contract with the source team is formal: a named owner, a data contract, a notice period for schema changes. Models carry an owner, a tier and a freshness promise, and finance and audit read the tests. Expect most of the effort to go on agreement and on keeping many marts consistent.

ARTEFACT Model one business entity and test it ~60 MIN
YOU PRODUCEA tested model for one entity, as a table of columns and tests

Template

# Model: <name>
Entity: <the business thing>   Grain: one row per <what>
Owner: <name>   Source: <system and table>   Refresh: <how often>   Freshness: warn after <n>, error after <n>

## Columns
| Column | Meaning | Type and unit | Derived from | Tests |
|---|---|---|---|---|
| <key> | | | | unique, not_null |
| <status or state> | | | <rule, in words> | accepted_values |
| <amount> | | integer kobo | <source column, conversion> | not_null |

## State rules
| State | Rule | Threshold owner |
|---|---|---|

## Tests beyond the columns
| Test | Query in words | Severity (error or warn) |
|---|---|---|

## Known source defects
| Defect | Evidence (count, amount) | Who is asked to fix it | Workaround until then |
|---|---|---|---|
WORKED EXAMPLE

Ferrowave runs a bulk payouts API. An analytics engineer there models the payout from its webhook events. The source table holds one row per event: event_id, payout_id, status (queued, paid, failed, returned), occurred_at. On the sample day there are 148,900 events for 61,200 payouts, and 2,310 event_id values appear more than once, 1.55% of events, because the sender retries.

Model: payouts. Grain: one row per payout, with the latest state by occurred_at; ties broken by status order. Freshness: warn after 2 hours, error after 6 (illustrative).

Column Meaning Type and unit Derived from Tests
payout_id The payout text events unique, not_null
state Latest known state text latest event by time after removing repeated event_id accepted_values: queued, paid, failed, returned
amount_kobo Amount instructed integer kobo payout request not_null
customer_id Business customer text request relationships to customers (210 rows)
paid_at When the bank confirmed UTC timestamp event with status paid not null when state is paid

Tests beyond the columns. Error: the paid total for a day equals the daily reconciliation file’s total to the kobo, after listing any payouts that cross midnight. Error: no payout has a paid event and a later failed event without also a returned one. Warn: yesterday’s event count is within 30% of the same weekday last week.

Known source defect. Repeated event_id values: the sender retries on timeout. Workaround: keep one row per event_id before ranking. Asked to fix: the webhook sender’s owner, with the 2,310 count.

Now you

You are Adesina, an analytics engineer at Northmere Bank. The data team has copied the 2014 disbursement system’s payouts table into the warehouse. Its columns are payout_id, batch_id, employer_id, account_no, amount (naira, two decimals), status (PROCESSED, FAILED or REVERSED), created_at, status_at and bank_ref. In October there are 412,600 rows marked PROCESSED, and 31,400 of them have no bank_ref. Of those, 29,300 were written less than three days ago and 2,100 are older. Silvia, who leads the team that runs the system, says a payout can legitimately wait up to three days for its release date or for funds, but she has not seen a payout older than that complete. The average payout is ₦120,000. Produce the model for the payout as a table of columns and tests, with the state rules, the tests beyond the columns, and the source defects you will raise with Silvia.

Self-check

DECIDE

Adesina finds that Northmere's 2014 disbursement system writes PROCESSED for both paid and queued payouts: 31,400 of 412,600 October rows, about ₦3.77bn, have no bank reference. The finance report goes to the board in nine days. Silvia's team can change the status, but the next release window is fourteen weeks away. What does Adesina do?

READING
  1. DOC
    Dimensional modeling techniques Kimball Group

    The catalogue of techniques from The Data Warehouse Toolkit, third edition: grain, fact table types, accumulating snapshots and slowly changing dimensions, each in a paragraph. Read the fact table techniques first.

  2. POST
    Keep to the Grain in Dimensional Modeling Ralph Kimball (Kimball University)

    A short column on declaring the grain and not mixing levels of detail in one table, which is the commonest cause of a double-counted total.

  3. DOC
    Add data tests to your DAG dbt Labs

    How generic and singular data tests are written and what a failing test means.

  4. DOC
    Source freshness properties dbt Labs

    How warn_after and error_after compare a source's newest timestamp with the clock.

  5. POST
    Functional Data Engineering: a modern paradigm for batch data processing Maxime Beauchemin, 2018

    The argument for deterministic, idempotent tasks that overwrite whole partitions, so a pipeline can be re-run and a bug fixed by recomputing.

All companies and people in these examples are fictional. Any resemblance to a real business or person is unintended.

RECALL CARDS Tap to flip. They join your review deck when you mark the lesson complete.
NEXT: LLMs in data work: evals, extraction and text as data →