Query icon
Script icon
If icon
SlackIncomingWebhook icon
Log icon
Schedule icon
Webhook icon

Data Freshness SLA Guard for Warehouse Tables

Watch warehouse tables against freshness SLAs in Kestra. One query returns hours since the newest row per table, stale tables alert Slack with age and SLA.

Categories
Data

A broken pipeline that stops loading does not usually fail - it stops producing rows. The dashboard keeps rendering yesterday's numbers with today's timestamp on the page, and the first person to notice is the analyst who sees their order count flatline. Freshness is the cheapest data-quality signal there is: newest row, compare against an allowance, and someone hears about it. This blueprint makes that signal a scheduled workflow instead of a widget nobody watches.

How it works

  1. check_freshness (io.kestra.plugin.jdbc.postgresql.Query, FETCH) renders one UNION ALL statement over the tables input - for each entry it selects max(column) as last_row_at and the age in seconds, coexisting with the table's own max_age_hours. One round trip covers the whole watch list.
  2. classify (io.kestra.plugin.scripts.python.Script, stdlib only) compares every age against its SLA. A NULL age means the table has no rows at all - an empty table is stale, never fresh - and is reported with an age_display of no rows.
  3. freshness_gate (io.kestra.plugin.core.flow.If) posts one Slack message listing each stale table with its real age, its SLA, and the last row timestamp; a clean run logs a one-line all-clear.
  4. The flow-level errors handler alerts Slack when the check itself fails, so a dead connection or a dropped table never reads as "everything is fresh".

The watch list is a plain input: add a table by appending an entry with its timestamp column and hours of tolerance, no SQL edits required.

What you get

  • A per-table freshness verdict with the numbers that matter: age, SLA, last row time.
  • An alert that names the table and column, so the owning team knows where to look.
  • checked_count, stale_count, and the stale list as flow outputs for dashboards or escalation flows.
  • Empty-table detection built in - "no rows" is treated as the breach it is.

Who it's for

  • Data engineers owning warehouse loads who want an early warning before dashboards lie.
  • Analytics teams whose stakeholders ask "is this data current?" on every Monday.
  • Platform teams wiring data-quality signals into the same on-call machinery as service health.

Why orchestrate this with Kestra

Freshness checks are usually a cron script that nobody maintains until it silently dies. Kestra gives the check scheduled and webhook triggers, retries, a failure path that alerts instead of hiding, execution history with the actual ages recorded as outputs, and a shape you can extend into paging (add a Squadcast or PagerDuty task in the then branch) without rewriting the logic.

Prerequisites

  • PostgreSQL 12 or newer reachable from Kestra (the same SQL works on the jdbc.postgresql plugin against most Postgres-backed warehouses).
  • SELECT access to each watched table and a timestamp-typed column on each.
  • A Kestra instance.

Secrets

  • POSTGRES_JDBC_URL: JDBC URL for the warehouse (for example jdbc:postgresql://host:5432/analytics).
  • POSTGRES_USERNAME: database username.
  • POSTGRES_PASSWORD: database password.
  • SLACK_WEBHOOK_URL: Slack incoming webhook URL for breach and failure alerts.

Quick start

  1. Add the four secrets above to your Kestra instance.
  2. Replace the default tables input with your real tables, columns, and SLAs.
  3. Run once manually and inspect check_freshness rows before trusting the gate.
  4. Trigger via the on_demand webhook after a load, then enable the hourly schedule.

How to extend

  • Route the then branch to a data on-call tool (Squadcast, PagerDuty) instead of, or alongside, Slack.
  • Chain this flow after your load pipeline with a Flow trigger so freshness is checked the moment data lands.
  • Group stale tables by owning team with a Switch on the table name.
  • Persist stale_count to a history table to chart freshness reliability over time.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.