Batch API lab
Add observability and tests
Metrics for batch_line_success_ratio ≥ 0.90 and dollars_per_1k_lines ≤ 8 must distinguish bad input from component failure for QA lead who needs cost-capped offline eval by 07:00 UTC.
1Learn the idea
Read
Golden signals for this system
Instrument overnight batch job that grades 50k support transcripts via provider Batch API so QA lead who needs cost-capped offline eval by 07:00 UTC can answer: demand, errors, latency/age, saturation. Emit fields needed by batch_line_success_ratio ≥ 0.90 and dollars_per_1k_lines ≤ 8 with bounded labels. Sample successful high-volume traces; keep errors and rollout transitions denser within policy.
Read
Alert path worth paging
Define at least one alert that would fire for BATCH-DUP-8841, with a for/pending window that survives deploy blips. Missing scrape or missing revision labels must not look like health. Include a trace/log example id format you will actually search.
Read
Implementation artifact
stats = {"succeeded": 18, "failed": 2, "usd": 0.37, "batch_id": "batch_01J"}
assert stats["succeeded"] / (stats["succeeded"] + stats["failed"]) >= 0.9
print(stats)
Read
Tests for telemetry
Add a unit/integration check that metrics increment on the happy path and on the duplicate custom_id causes silent overwrite of the better grade branch. Store machine-readable output in CI artifacts when practical.
Read
Stage depth
Cardinality discipline: tenant and revision are usually enough; raw question text is not a label. Exemplars or trace links beat screenshots alone when debugging BATCH-DUP-8841. Define who owns alert fatigue review. If you export to a vendor, record retention and access. Synthetic probes should use non-sensitive fixtures and still exercise POST /v1/batches. Practice the query you will type at 2am once, while calm.
Read
Field notes for `batch-api-lab` / `observability`
Document the exact PromQL or log query in the runbook stub for this service. Verify histograms have buckets around your SLO target. Add a canary synthetic check that exercises the oracle path every few minutes in staging. Confirm that PII redaction happens before export. Track build/version as a label on the golden signals. Delete noisy debug logs before they become accidental product dependencies. In this chapter the product is overnight batch job that grades 50k support transcripts via provider Batch API, the human stakeholder is QA lead who needs cost-capped offline eval by 07:00 UTC, and the incident id you design against is BATCH-DUP-8841. Re-state the oracle in your notes — fixture of 20 lines yields 18 succeeded + 2 failed with error objects; cost ≤ $0.40 — and keep the invariant visible: each input line has a stable custom_id; failed lines never poison the whole file. Track batch_line_success_ratio ≥ 0.90 and dollars_per_1k_lines ≤ 8 as the scoreboard. Surface under change control: POST /v1/batches. If you only have forty minutes, finish the fixture for duplicate custom_id causes silent overwrite of the better grade before polishing UI. Promotion language stays ternary: promote, hold, or roll back based on evidence, not hope.
Go deeper
Before you start
Why this matters
Name the dashboard row or log line QA lead who needs cost-capped offline eval by 07:00 UTC opens first during BATCH-DUP-8841. It must include a correlation id and a bounded label from batch_line_success_ratio ≥ 0.90 and dollars_per_1k_lines ≤ 8. If telemetry is missing, write whether you promote, hold, or roll back — and why hold is the default.
In the wild
See how this idea shows up as a product and a company — then come back to the lesson. Skills transfer across vendors.
Related lessons
Check your understanding
Page assessment
Answer from memory. Completion is saved from this evidence, not from opening the next page.
All responses are required.