Video in progress
How do you build SLOs and alerting for daily batch jobs and Kafka consumers? Why doesn't the approach for HTTP services work here?
Batch and stream processors have no "request" and no "response time", while the user notices whether the result is on time and complete. So the SLIs are freshness, completeness and correctness: "the report is ready by 07:00", "events are processed within 5 minutes", "no lost records".
📖 Answer
HTTP RED metrics say almost nothing about a batch job. It is normal for a job to run for 2 hours, but if the 07:00 report isn't ready, that is an incident. Or the job finishes "successfully" but half of the input file was skipped.
SLIs for batch jobs:
- Freshness: the age of the result data. A "last successful completion time" metric is the most useful signal.
- Completeness: records processed / records expected (from the source count).
- Correctness: reconciliation, where the result is compared against the source.
// at the end of the job, updated only on success
lastSuccess.set(Instant.now().getEpochSecond()); // a Gauge over an AtomicLong
processedRecords.increment(count);
For short-lived jobs, a Prometheus scrape may not get to them; in that case use the Pushgateway or OTLP push. And alert not on "the job failed" but on "the data went stale":
time() - batch_last_success_timestamp_seconds{job="daily-report"} > 26 * 3600
This one rule also catches the case where the job never started at all, while a "job failed" alert doesn't see that, because there is nothing there to fail.
For stream consumers:
- measure lag in time (the age of the oldest unprocessed message), not in message count;
- SLO: "99% of events are processed within 5 minutes", measured with an end-to-end histogram (
processed_at - produced_at); - poison messages and the DLT flow: the share that lands in the DLT can also be an SLI.
In Kafka, burrow or kafka-lag-exporter estimate lag in time. The consumer itself has records-lag-max, but if the consumer is dead it emits no metric, so lag has to be measured from outside, on the broker side.
The organizational side: who consumes the batch result: finance, analytics, a customer? The SLO has to be agreed with them, because the "07:00" number comes from their workflow.
Sign up to mark studied questions and save your progress.