Parallel icon
Get icon
Download icon
Query icon
UploadFiles icon
Set icon
Log icon
Schedule icon

Stop a Bad Monthly Load with SLA Assertions on NYC Taxi Data in DuckDB

Profile a month of NYC taxi data in DuckDB and stop the load with Kestra SLA assertions before a bad month is published.

Categories
Data

A monthly load guarded by flow-level sla: rules instead of If and Fail tasks: a month of NYC TLC green taxi trips (about 1 MB) is profiled in DuckDB, and a bad month fails the run before anything is published.

How it works

  1. monthly runs on the 25th for the month two months back; a manual run takes month or that default.
  2. fetch (Parallel) reads the previous month's trip count from the KV store and downloads the month.
  3. profile (DuckDB) computes the numbers the rules read: trips, change from the previous month, share of trips without a passenger count, share picked up outside the month.
  4. The sla rules are checked every time the execution changes. As soon as profile ends, a false rule fails the run and labels it sla_breach: <rule>: curate, publish and remember never start.
  5. Otherwise curate writes the cleaned month to Parquet, publish uploads it to the namespace files and remember keeps its numbers as the next baseline. load_duration caps the run at 15 minutes.

Rules are evaluated before profile has run, so each one reads its output through ??:

# Wrong: fails every run at the first task ("could not be evaluated and is treated as violated")
assert: "{{ outputs.profile.row.trips >= inputs.min_trips }}"
# Right: passes until profile has run, then checks the real value
assert: "{{ (outputs.profile.row.trips ?? inputs.min_trips) >= inputs.min_trips }}"

Don't add afterExecution tasks to this flow: on Kestra 2.0.6, a flow that has them still starts the next task after an SLA failure, so a bad month would be published (kestra-io/kestra#22036).

What you get

  • A Parquet file per month in nyc_taxi/green/, only for months that pass every rule.
  • Otherwise a failed execution labelled with the broken rule, the rule in the logs, and nothing published.

Who it's for

Data engineers and analytics engineers who load third-party files on a schedule.

Why orchestrate this with Kestra

Declared once for the flow, a rule also guards tasks added later, needs no extra task in the Gantt, and labels the execution so failures can be filtered or alerted on. Switch a rule's behavior to NONE to try a new threshold without stopping loads.

Prerequisites

Kestra 2.0 with the DuckDB plugin. The TLC files are public.

Secrets

None.

Quick start

  1. Execute with the defaults: the latest month is published.
  2. Execute with month 2020-03, then 2020-04: April 2020 (35,644 trips, down 84%) fails on stable_volume.
  3. Keep the monthly trigger.

How to extend

  • Alert from a second flow with a Flow trigger on FAILED executions where labels.sla_breach is defined.
  • Load to a warehouse instead, or add rules on fares and distances.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.