Posts tagged “Deep Dive”

Why a stream processor must never reorder a partition

StoatFlow used to sort each partition's buffered records by timestamp, so the oldest event went first. Under the right timing that lost a record for good after a crash, under exactly-once and at-least-once alike, without a log line or a metric. This post walks the sequence from a buffered record to a committed offset that runs past it, why the obvious patch would have broken exactly-once, and how the one stall that offset order introduced was removed as well.

Your timer fired on another thread

StoatFlow runs a key's timers on the same lane as its records, so onTimer never races process() for that key. The lane is chosen by hashing key bytes — and a timer key is serialised again, by its own serde. Behind a Processor API source declared with only a deserializer, that serde was the default, and when the default wrote different bytes than the topic, a key's timer fired on another lane, concurrently with its records, without a word. How it happens, why Kafka Streams never meets it, and how StoatFlow now refuses to run a proven split.

Testing and operating event time

The TopologyTestDriver's stream time is the maximum it has seen, with no out-of-orderness lag and no cross-partition minimum; production keeps a 10-second lag and the minimum. A window-close test that passes in the driver emits later on a real broker, and can count a record the driver dropped. Part 4 of the event-time series: which tests transfer, how to read /watermarks, the meters that matter, the one alert to set on day one, and what a restart does to the watermark.

Closing a window under exactly-once

In StoatFlow a window's final result is not emitted the instant the watermark passes its close — it is emitted at a commit barrier, judged against the watermark stamped on the barrier before, up to two commit intervals later. Part 3 of the event-time series follows one watermark advance from the consumer thread to the committed result: what listens, the one clock that drops and closes, the committed-watermark frontier, and what survives a restart.

Making the watermark move: sources, idleness, and the partition that stopped the world

StoatFlow's watermark is a minimum across partitions, so one source decides for all of them. Part 2 of the event-time series is the configuration discipline that follows: what each source declares about its own time, what idleness does and the two bugs it took to get it right, the one strategy StoatFlow refuses beside a window, how to give a single source a Kafka Streams-style watermark, and why ordered dispatch already does most of what Flink needs watermark alignment for.

Three clocks: stream time, Flink watermarks, and the one watermark StoatFlow computes

Kafka Streams, Flink and StoatFlow answer "is this window done?" with three different clocks. StoatFlow runs two of them: it accepts a late record the way Kafka Streams does, on the operator's stream time, and closes the window the way Flink does, on a single global watermark. Part 1 of a four-part series on event time — including two corrections to a claim our own compatibility matrix made about grace.

Three gates, one transaction: error handling in StoatFlow

A record can fail on the way in, in the middle, or on the way out. StoatFlow gives every gate the same verdicts — continue, fail, or dead-letter — and settles them all inside the exactly-once transaction: DLQ records commit on the same barrier as your output, and what cannot be handled kills the epoch, never the guarantee. The full model, from one bad record to a Kubernetes restart.

Internal consistency on Kafka: emitting a correct answer at every commit

Money can only be moved, never created — so a stream that tracks balances should read total = 0 at every consistent cut. The Flink Table API gets it right 0.035% of the time; our Kafka Streams twin sends total to −1,619 … +1,792. StoatFlow holds it at exactly 0, at every one of its committed cuts. Here is why, and the measured proof.

KIP-1271: record headers in state stores, and the cost of a value format

KIP-1271/1285 let a state store keep a record's headers next to its value — shipped in Apache Kafka 4.3.0. What the KIP is, where Kafka Streams has got to (and what is still in flight), how StoatFlow 1.0.0 compares — and why a one-varint format change becomes an engine-wide one.

KIP-1035: Why Kafka Streams 4.3 lets state stores own their offsets

Kafka Streams kept each task's changelog offsets in a separate checkpoint file that could drift from the state it described. KIP-1035, in Kafka 4.3, moves them inside the state store — atomic with the data, and the keystone for transactional state stores.