{
  "license": "CC BY 4.0",
  "licenseUrl": "https://creativecommons.org/licenses/by/4.0/",
  "recipe": {
    "slug": "dependency-p95-latency",
    "title": "Compare Dependency p95 Latency",
    "testedWith": "Apache DataFusion 45.2.0",
    "lastReviewed": "2026-07-27"
  },
  "contract": {
    "tableName": "dependency_calls",
    "schema": [
      {
        "name": "timestamp_utc",
        "type": "Timestamp",
        "description": "Dependency call completion time."
      },
      {
        "name": "dependency_name",
        "type": "Utf8",
        "description": "Stable logical dependency name."
      },
      {
        "name": "operation",
        "type": "Utf8",
        "description": "Normalized operation or route."
      },
      {
        "name": "status",
        "type": "Utf8",
        "description": "success, failed, or timeout."
      },
      {
        "name": "latency_ms",
        "type": "Float64",
        "description": "Dependency duration in milliseconds."
      }
    ]
  },
  "query": "SELECT\n  dependency_name,\n  operation,\n  COUNT(*) AS calls,\n  approx_percentile_cont(latency_ms, 0.50) AS p50_ms,\n  approx_percentile_cont(latency_ms, 0.95) AS p95_ms,\n  100.0 * SUM(CASE WHEN status <> 'success' THEN 1 ELSE 0 END)\n    / NULLIF(COUNT(*), 0) AS failure_rate_pct\nFROM dependency_calls\nWHERE timestamp_utc >= now() - INTERVAL '24 hours'\nGROUP BY dependency_name, operation\nHAVING COUNT(*) >= 50\nORDER BY p95_ms DESC\nLIMIT 20;",
  "fixtureKind": "schema-example",
  "inputRows": [
    {
      "timestamp_utc": "2026-07-28T10:00:00Z",
      "dependency_name": "dependency_name_example_1",
      "operation": "operation_example_1",
      "status": "success",
      "latency_ms": 184
    },
    {
      "timestamp_utc": "2026-07-28T11:00:00Z",
      "dependency_name": "dependency_name_example_2",
      "operation": "operation_example_2",
      "status": "failed",
      "latency_ms": 926
    },
    {
      "timestamp_utc": "2026-07-28T12:00:00Z",
      "dependency_name": "dependency_name_example_3",
      "operation": "operation_example_3",
      "status": "success",
      "latency_ms": 312
    }
  ],
  "illustrativeInputRows": [
    {
      "timestamp_utc": "2026-07-28T10:00:00Z",
      "dependency_name": "dependency_name_example_1",
      "operation": "operation_example_1",
      "status": "success",
      "latency_ms": 184
    },
    {
      "timestamp_utc": "2026-07-28T11:00:00Z",
      "dependency_name": "dependency_name_example_2",
      "operation": "operation_example_2",
      "status": "failed",
      "latency_ms": 926
    },
    {
      "timestamp_utc": "2026-07-28T12:00:00Z",
      "dependency_name": "dependency_name_example_3",
      "operation": "operation_example_3",
      "status": "success",
      "latency_ms": 312
    }
  ],
  "expectedOutput": {
    "columns": [
      "dependency_name",
      "operation",
      "calls",
      "p50_ms",
      "p95_ms",
      "failure_rate_pct"
    ],
    "rows": [
      {
        "dependency_name": "billing_database",
        "operation": "invoice_history",
        "calls": 1840,
        "p50_ms": 84,
        "p95_ms": 1820,
        "failure_rate_pct": 0.49
      },
      {
        "dependency_name": "search_provider",
        "operation": "document_search",
        "calls": 6220,
        "p50_ms": 132,
        "p95_ms": 760,
        "failure_rate_pct": 1.21
      },
      {
        "dependency_name": "redis",
        "operation": "session_lookup",
        "calls": 44100,
        "p50_ms": 3,
        "p95_ms": 12,
        "failure_rate_pct": 0.02
      }
    ]
  },
  "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."
  ]
}