Schedule icon
Download icon
Get icon
If icon
Queries icon
Set icon
SlackIncomingWebhook icon
Log icon

Load World Bank Indicators with DuckDB and Detect Silent Revisions of Published History

Load World Bank indicators weekly, diff against the last run in DuckDB, log new, revised and withdrawn values to Parquet and alert on material revisions.

Categories
Data

The World Bank restates history with every release: GDP for 2022 changes again in 2026, a series is withdrawn, a new period appears. A loader that only appends the latest year keeps the old numbers, so growth rates computed downstream drift without anyone noticing. This flow fetches one indicator for every country in a single request, diffs it in DuckDB against the values the previous run accepted, keeps the accepted values and an append-only revision log as Parquet in Kestra's internal storage, and alerts only when an already published value moved more than the tolerance.

How it works

  1. A weekly Schedule trigger (Monday 07:00 UTC) runs the load; the World Bank refreshes most indicators a few times a year, so a weekly request catches a release within days.
  2. fetch_indicator (HTTP Download) calls api.worldbank.org/v2/country/{countries}/indicator/{indicator} with format=json&per_page=20000; the [metadata, rows] response lands in internal storage.
  3. previous_values and previous_log (KV Get, errorOnMissing: false) read the URIs of the Parquet files saved by the last run; both are missing on the first run.
  4. bootstrap (If) runs only without history: empty_history (DuckDB Queries) writes empty Parquet files with the right columns, so the diff has one code path.
  5. diff_and_load (DuckDB Queries, fetchType: FETCH_ONE) parses the JSON with read_text and from_json, keys rows on World Bank country id plus year (aggregates such as WLD have no ISO3 code) and FULL OUTER JOINs them to the previous values. Each difference is NEW, REVISED (with its relative change) or WITHDRAWN (null or gone). Three outputFiles are written: accepted values, the revision log (history plus this run's changes; first-run rows are the baseline) and this run's changes as CSV. The single result row is the run summary: rows and values loaded, counts per change type, material revisions above the tolerance, the largest move and a top_revisions string.
  6. save_values and save_log (KV Set) store the new URIs under wb_values_<indicator> and wb_revisions_<indicator>, so several indicators share the flow.
  7. alert_on_material_revisions (If) posts to Slack only when material_revisions > 0; the webhook has allowFailure, so a missing secret warns instead of failing the load. Otherwise a Log task records the counts.
  8. summary logs the result; the flow exposes the summary JSON and the three files as outputs.

What you get

  • A Parquet file of the latest accepted values, ready for read_parquet in DuckDB, Spark or a warehouse load.
  • An append-only revision log (execution id, detection time, country, year, previous and current value, change type, relative change, source lastupdated) that answers "when did this number change and by how much".
  • A CSV of this run's changes, sorted by size, on every execution.
  • A Slack alert only for material revisions; new periods and sub-tolerance restatements are logged, not paged.
  • No external database: state lives in internal storage and the KV store.

Who it's for

  • Analytics engineers computing growth rates, shares or rankings from World Bank or national statistics data.
  • Data engineers landing public reference data into a warehouse who want a diff, not a blind overwrite.
  • Economists and researchers who cite the vintage of a number and must trace later revisions.

Why orchestrate this with Kestra

  • Download plus inputFiles hands the API response to DuckDB without a script or container; the SQL is the whole transformation.
  • outputFiles and KV Get/Set carry Parquet state between runs declaratively; nothing to provision.
  • If and allowFailure make alerting a property of the flow, not a try/except in a script.
  • Indicator, country list, year range and tolerance are inputs: one flow serves GDP, inflation and population under separate KV keys.

Prerequisites

  • Kestra 2.0 with the JDBC DuckDB plugin and, for the alert, the Slack plugin (io.kestra.plugin.slack.notifications.SlackIncomingWebhook).
  • Outbound HTTPS to api.worldbank.org; the Indicators API needs no key.
  • The Parquet files live in the execution folders of this flow; if you purge executions, keep at least the latest successful one of this flow, or copy the files elsewhere first.

Secrets

  • SLACK_WEBHOOK_URL: Slack incoming webhook for the material-revision alert (optional; without it the alert task warns and the load still succeeds).

Quick start

  1. Import the flow and click Execute with the defaults: GDP (current US$) for all countries from 2015. The first run is a baseline (is_baseline: true) and loads about 2,900 country-years.
  2. Execute again: zero new, revised and withdrawn values, and bootstrap is skipped.
  3. To see the diff without waiting for a release, download the values Parquet from the first execution, change one value and drop one row with DuckDB, upload it as a namespace file and point the KV key wb_values_ny_gdp_mktp_cd at its kestra:/// URI. The next run reports one REVISED and one NEW value and takes the alert branch if the change exceeds revision_tolerance.
  4. Add SLACK_WEBHOOK_URL as a secret, set revision_tolerance (0.01 is 1 percent) and leave the weekly schedule on.
  5. Run with another indicator (FP.CPI.TOTL.ZG for inflation, SP.POP.TOTL for population); each keeps its own history.

How to extend

  • Load several indicators with a ForEach that runs this flow as a Subflow.
  • Append the accepted values to a warehouse table (BigQuery, Snowflake, Postgres) from the values_parquet output.
  • Keep every vintage by writing the values file with the execution date to S3 or GCS instead of internal storage.
  • Alert on WITHDRAWN values too by editing the If condition.
  • Swap the source for any API returning one value per entity and period (IMF, Eurostat, OECD) by changing the fetch_indicator URI and the JSON paths in the first two CREATE TABLE statements.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.