{
  "license": "CC BY 4.0",
  "licenseUrl": "https://creativecommons.org/licenses/by/4.0/",
  "recipe": {
    "slug": "event-ingestion-freshness",
    "title": "Measure Event Ingestion Freshness",
    "testedWith": "Apache DataFusion 45.2.0",
    "lastReviewed": "2026-07-27"
  },
  "contract": {
    "tableName": "telemetry_events",
    "schema": [
      {
        "name": "timestamp_utc",
        "type": "Timestamp",
        "description": "When the event occurred in the producer."
      },
      {
        "name": "received_at",
        "type": "Timestamp",
        "description": "When the ingestion service accepted the event."
      },
      {
        "name": "source",
        "type": "Utf8",
        "description": "Stable producer or workflow name."
      },
      {
        "name": "environment",
        "type": "Utf8",
        "description": "Deployment environment."
      }
    ]
  },
  "query": "SELECT\n  source,\n  MAX(timestamp_utc) AS latest_event_at,\n  MAX(received_at) AS latest_received_at,\n  date_part('second', now() - MAX(received_at)) / 60.0\n    AS minutes_since_receive,\n  AVG(date_part('second', received_at - timestamp_utc)) / 60.0\n    AS average_delivery_delay_minutes\nFROM telemetry_events\nWHERE received_at >= now() - INTERVAL '24 hours'\n  AND environment = 'production'\nGROUP BY source\nORDER BY minutes_since_receive DESC;",
  "fixtureKind": "schema-example",
  "inputRows": [
    {
      "timestamp_utc": "2026-07-28T10:00:00Z",
      "received_at": "2026-07-28T10:00:00Z",
      "source": "source_example_1",
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T11:00:00Z",
      "received_at": "2026-07-28T11:00:00Z",
      "source": "source_example_2",
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T12:00:00Z",
      "received_at": "2026-07-28T12:00:00Z",
      "source": "source_example_3",
      "environment": "production"
    }
  ],
  "illustrativeInputRows": [
    {
      "timestamp_utc": "2026-07-28T10:00:00Z",
      "received_at": "2026-07-28T10:00:00Z",
      "source": "source_example_1",
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T11:00:00Z",
      "received_at": "2026-07-28T11:00:00Z",
      "source": "source_example_2",
      "environment": "production"
    },
    {
      "timestamp_utc": "2026-07-28T12:00:00Z",
      "received_at": "2026-07-28T12:00:00Z",
      "source": "source_example_3",
      "environment": "production"
    }
  ],
  "expectedOutput": {
    "columns": [
      "source",
      "latest_event_at",
      "latest_received_at",
      "minutes_since_receive",
      "average_delivery_delay_minutes"
    ],
    "rows": [
      {
        "source": "billing_sync",
        "latest_event_at": "2026-07-27 12:11",
        "latest_received_at": "2026-07-27 12:12",
        "minutes_since_receive": 48,
        "average_delivery_delay_minutes": 1.4
      },
      {
        "source": "api_gateway",
        "latest_event_at": "2026-07-27 12:59",
        "latest_received_at": "2026-07-27 12:59",
        "minutes_since_receive": 1,
        "average_delivery_delay_minutes": 0.1
      },
      {
        "source": "queue_workers",
        "latest_event_at": "2026-07-27 12:58",
        "latest_received_at": "2026-07-27 12:59",
        "minutes_since_receive": 1,
        "average_delivery_delay_minutes": 0.8
      }
    ]
  },
  "notes": [
    "The compact input rows demonstrate field names and JSON types; they are not claimed to generate the displayed aggregate by themselves.",
    "The expected output is deterministic synthetic review data for the documented output shape.",
    "Adapt time windows, thresholds, identities, and business definitions before operational use."
  ]
}