FDE Times dataFDE jobs open 932▼14 Change in open roles over 7 days, like-for-like: roles from companies we started tracking this week are left outNew in 7 days 62Companies hiring 202Remote-friendly 24%Median US pay $201kTop hirer Databricks 92
中文VI

The newspaper of the Forward Deployed Engineer

Guides

Your green pipeline may be feeding clients the wrong numbers

Checks on freshness, row counts and schema, plus a safety net for jobs that never run, let you catch bad data before the client does.

ShareLinkedInFacebookX

In brief

  • Client data usually breaks in three ways: it arrives late, rows go missing or the schema changes. Each needs its own check, plus one more layer for jobs that do not run.
  • Measure freshness by load time instead of event time, and set thresholds for each feed according to its SLA.
  • Alert only on symptoms the client will see, and leave enough slack that a few minutes' delay wakes nobody in the middle of the night.
Diagram of four stacked layers. Layer 1, late arrival: dbt freshness. Layer 2, missing rows: Great Expectations. Layer 3, schema change: column list. Layer 4, at the bottom and highlighted in orange: job stopped, Prometheus absent(). It is the safety net because the top three layers only run when the job runs.
The three checks only produce a result when the job runs. If cron dies, only the fourth layer raises the alarm. Source: hypothetical scenario in the article, based on dbt, Great Expectations and Prometheus documentation.

A job can finish successfully on yesterday’s file, on a file with only half its rows, or on one in which the client has just renamed the amount column to total_amount. The pipeline reports green and the dashboard still shows figures. The figures are wrong.

For an FDE, few incidents destroy trust faster. Clients have no need to know how many services your system runs. They remember the first time they spotted a wrong number before you did. If you are handed a pipeline that takes in client data, these checks are among the first things to build.

This guide follows a hypothetical retail chain that sends an orders table to the warehouse every night and a product catalog every week. You will build three layers of checks for three kinds of failure: late arrival, missing rows and schema changes. A fourth layer then acts as a safety net for jobs that do not run at all.

What do you need before you start?

You need a dbt project with its sources declared, a Python environment with Great Expectations installed, and a monitoring tool. That tool can be Prometheus, Datadog or Sentry, depending on what the client uses; you do not need all three. On a real engagement, pick the one the client’s operations team is already used to watching.

The most important requirement concerns the data itself: every table must have a column recording when each row was loaded, such as _etl_loaded_at. If that column does not exist, your first task is to add it at the ingest step.

Step 1: dbt freshness catches late data

The dbt documentation describes the freshness configuration as the place to declare how recent source data needs to be. The two main thresholds are warn_after, the maximum age of the newest record before dbt issues a warning, and error_after, the point at which dbt reports an error. Each threshold needs both a count and a period.

sources:
  - name: retail_client
    loaded_at_field: _etl_loaded_at
    freshness:
      warn_after: {count: 12, period: hour}
      error_after: {count: 24, period: hour}
    tables:
      - name: orders
        freshness:  # stricter for orders
          warn_after: {count: 6, period: hour}
          error_after: {count: 12, period: hour}
          filter: _etl_loaded_at >= current_date - 3
      - name: product_catalog
        freshness: null

This snippet is simplified. The position of the freshness key can vary between dbt versions, and the date syntax in filter depends on the warehouse. Three details in the configuration deserve attention.

Separate thresholds for each table. dbt lets you set thresholds per table and turn the check off. orders is therefore checked more strictly, while product_catalog, which is updated only weekly, is skipped.

A filter to keep the check cheap. This key adds a WHERE clause to the freshness query, so dbt does not have to scan the whole of a large table.

A loaded_at_field that points to load time. This is the detail most often missed. dbt needs the column to know when data last arrived, in cases where the adapter does not supply that metadata. Point it at the time the row was loaded, and not the time the order was placed.

Say the client backfills orders from three days ago. Judged by event time, the data looks three days old. Only load time shows you when the file actually arrived.

Check: run dbt source freshness, then temporarily lower warn_after to 1 hour to make sure you see the warning state.

Step 2: an unusual row count often means a truncated file

Freshness tells you only whether data arrived, and says nothing about whether it is complete. If an export is cut off partway through, the newest record still has a recent timestamp and the freshness check still passes.

Great Expectations has an expectation that checks whether a table’s row count falls within a range, with both bounds included. min_value can be set on its own, so a lower bound is all you need to detect missing rows.

import great_expectations as gx

row_check = gx.expectations.ExpectTableRowCountToBeBetween(
    min_value=30000,
    max_value=None,
)

The snippet leaves out connecting to a batch and running the validation. To see how the number works, take the retail chain’s data. If orders ranged from 38,000 to 45,000 rows over the past 14 nights, a floor of 30,000 still leaves room for a quiet night. But if tonight’s file has only 19,000 rows because it was cut in half, the check fails.

A fixed threshold struggles when volume varies by day of the week, for instance when weekends bring twice as much data as weekdays. Datadog has an anomaly monitor that learns from historical data to detect unusual behavior, which suits this pattern better.

Datadog also offers monitors for freshness, row count and column-level metrics across many warehouses, so all three kinds of failure can be tracked in one tool.

Check: run the expectation on a copy of the table with half its rows deleted. It must fail.

Step 3: catching schema changes takes an agreed column list

The first two checks cover only freshness and row counts. For schema, the simplest approach is to write a small check yourself. The example below is an illustration and not a complete solution: store the list of columns agreed with the client, then compare it with the actual columns in each load.

EXPECTED = {"order_id", "store_id", "amount", "created_at", "_etl_loaded_at"}

def schema_diff(actual_columns):
    actual = set(actual_columns)
    return {"missing": EXPECTED - actual, "new": actual - EXPECTED}

Treat a missing column as an error. A new column should raise only a warning, since the client has most likely added information without breaking anything. If the client uses Datadog, you can turn this check into a custom SQL monitor, a type listed in Datadog’s documentation.

Check: rename a column in a test table. missing must contain the old name and new the new one.

Step 4: a safety net for jobs that do not run

All three steps above depend on the job running. If cron dies, no check will report an error, because no check was executed.

Prometheus collects metrics by pulling them and uses a multidimensional data model, in which each time series is identified by a metric name and key/value pairs. Your pipeline can expose a metric recording the time of its last successful load.

The absent() function works counterintuitively: while the series still has data, it returns nothing, and it returns a result only once the series has disappeared. An alert based on absent() therefore fires only when a feed stops reporting altogether.

- alert: OrdersFeedStale
  expr: time() - pipeline_last_success_timestamp_seconds{feed="orders"} > 6 * 3600
  for: 30m
- alert: OrdersFeedMissing
  expr: absent(pipeline_last_success_timestamp_seconds{feed="orders"})

This is a shortened version, without routing labels or annotations. If the client does not use Prometheus, Sentry Cron Monitoring can watch any scheduled job, including an ingest job that pulls client data.

Common mistake: too many alerts

Prometheus’s guidance on alerting recommends keeping alerts to as few as possible and alerting only on symptoms tied to what end users actually experience.

It also advises leaving slack in thresholds so that small fluctuations do not trigger alerts. The for: 30m setting and the gap between warn_after and error_after in the examples above exist for that reason.

Two other mistakes are also common. The first is applying the same threshold to every table, so that a table updated weekly shows red every day until the whole team mutes the notifications.

The second is sending alerts to a channel nobody owns. Every alert should come with the name of the person handling it and one line on what to do first.

With a real client, it starts with a question

The hardest part lies outside the YAML. It is asking the client: “How late can the orders file be before it causes you problems?” Their answer is your error_after. Setting thresholds this way shows that you are doing customer discovery as well as configuring tools.

When reading the job description for an FDE role, or for a data engineer working directly with clients, look for phrases such as “data quality,” “observability” or “customer SLAs.” On your resume, describe the work by its results.

For example: “Built freshness, row-count and schema checks for 6 client feeds, catching truncated files before the morning report went out.” The numbers in that sentence must be real ones from your own project.

On your first day with a new client, do not try to build all four layers at once. Start with freshness on the most important feed: it is the cheapest check, and it tells you about a problem before the client has to call.

Was this article useful?

Use with your AI assistantAsk Claude ↗Ask ChatGPT ↗
7 sources
Read next on the roadmap · Stage 6: MeasurementOffline evals won't win a renewal. A clean A/B test willAssign users with a stable hash, log the right fields and check for sample ratio mismatch before you show the client a single number.