Skip to main content
Version: 0.7.x

Backpressure and buffering

ArkFlow never reads a source faster than the pipeline can absorb. The mechanism is a bounded channel between the input and the processors, plus buffer components that hold batches on purpose (windows). Backpressure is the visible effect: a replayable source simply pauses its fetch, and memory stays bounded.

The 1024-message threshold​

The channel between the input worker and the processor workers holds at most 1024 in-flight batches. When it is full, the input worker blocks until processors drain enough to drop below the bound. In a compiled Stream the memory buffer is a pass-through — the bounded channel itself provides the buffering.

This design has three consequences:

  • Memory use stays bounded under sustained overload instead of growing until the process is killed.
  • Replayable sources pause their fetch; the broker retains the data, so backpressure costs latency, not data.
  • Unbounded fan-in or an oversized window can turn backpressure into a stall: the channel is full because a downstream stage cannot emit, not because the source is fast.

Buffer components​

BufferBehaviorBackpressure interaction
memoryPass-through in compiled streams; the bounded channel does the work.None beyond the channel.
tumbling_windowHolds batches until a fixed processing-time window closes, then emits one aggregated batch.A large window holds output back for its whole duration; size it against input rate.
session_windowHolds batches per key until a processing-time inactivity gap closes the session.A never-quiet key can hold data indefinitely; the inactivity gap is the release bound.
sliding_windowLegacy row-count window; rejected by the unified stream compiler with a migration hint.Migrate to a Job window operator.

Window buffers change the latency profile: input keeps flowing until the window's own state or the 1024-batch channel fills. If a window emits a large batch to a slow sink, the channel drains slowly and the input stalls — the classic "window size versus sink throughput" mismatch.

Recognizing backpressure​

Symptoms:

  • Source lag grows while CPU is low; the process is idle because it is blocked, not because it has no work.
  • Throughput plateaus at a round number and latency rises linearly with input rate.
  • A window's flush produces a burst, then the source pauses until the sink catches up.

Diagnosis:

  1. Check whether the bottleneck is the sink: compare sink latency and error rate with source lag.
  2. Look for a window whose size or session gap is larger than the sink's sustainable batch time.
  3. Check thread_num: a single processor thread can be the bottleneck even when the source is fast.
  4. For Jobs, check max_buffered_keys eviction warnings and join capacity warnings — they indicate state bounds, not channel bounds.

If the source is non-replayable, backpressure is still safe (the source pauses) but a crash can lose in-flight messages; add a WAL if that matters. See Delivery and durability.

Ordered output under parallelism​

Processors run in parallel when thread_num > 1, so batches finish out of order. The output worker restores input order using sequence numbers and waits for the next expected batch before writing. This is why a slow batch can hold back later batches even when workers are idle — another form of head-of-line backpressure. The full description is in Backpressure and ordered delivery.