Skip to content

Backpressure

Fibril’s current backpressure model is intentionally plain: consumers pull work and each subscription has a prefetch limit.

Prefetch bounds the number of messages a consumer may have inflight at once.

let mut sub = client
.subscribe("email.send")?
.prefetch(32)
.sub()
.await?;

The default client subscription prefetch is small. The broker also clamps subscription prefetch to at least one.

Each delivered message occupies an inflight slot. A slot is released when the message is durably settled, or eventually by lease expiry if the consumer disappears.

This keeps slow consumers from accepting unlimited work and gives the broker a concrete signal for who can receive more messages.

When a subscription is dropped or unsubscribed, messages that were prefetched but not acknowledged are not considered lost. The broker requeues those unacked deliveries so other active subscribers can receive them.

This matters for high-prefetch consumers. A reader can hold many messages locally before processing them. If that reader goes away, Fibril should redistribute the outstanding work instead of waiting for every lease to expire one by one.

The behavior is still at-least-once. A message may be delivered again after unsubscribe, so handlers should remain idempotent.

This is not a full adaptive flow-control system yet. There is no production tuning guide, no automatic per-topic policy, and no cluster-level balancing.

The current model is useful because it is simple, explicit, and easy to reason about under failure.