The router is a poller; a full pool defers instead of blocking the queue
Status
Section titled “Status”Accepted. The topology dates from the first router implementation; the deferral rule refined it on 2026-09-22.
2026-09-22 (deferral ruling; the poller topology predates it, router-architecture.md first committed 2026-08-25).
Context
Section titled “Context”A router receives messages from one or more brokers (SQS, NATS, a Postgres-backed queue) and delivers each to an HTTP target under a concurrency limit and a rate limit. Two structural questions follow.
- Who talks to the broker? A server that accepts messages pushed to it would need its own durability. A poller that pulls from a queue inherits the broker’s durability, redelivery and dead-letter behaviour.
- What happens when the pool a message belongs to is full? A queue feeds many pools, but a batch cannot be split: the consumer either fetches another batch or it does not.
The first rule the router used was simple: if any pool fed by the last batch is full, stop polling that queue. It failed in production-like conditions. One dedicated pool at concurrency 1, handed 10,000 five-second messages, parked its queue for about fourteen hours. Every other pool on that queue starved, although their targets were idle.
Decision
Section titled “Decision”The router is a poller, not a server. A manager owns one consumer per queue. Pools are passive: they hold the concurrency cap, the rate limiter and the per-group FIFO buffer, and they never touch a broker. Because one pool serves many queues, every acknowledgement or negative acknowledgement resolves back to the message’s source consumer through its queue identifier.
Backpressure is expressed as a deferral, not a failure:
- A message for a pool at buffer capacity (
max(concurrency × 40, 100)) is handed back with a Defer, which is not a Nack and does not count as a failed attempt. - Each deferral is given a reservation. The pool measures its completion rate over five minutes and keeps a cursor of when the last deferred message was told to return. The next deferral is booked one slot (
1/rate) after the later of that cursor and the buffer’s own drain time. Deferred messages therefore return spaced at the pool’s pace, in the order deferred, each bouncing about once instead of returning together as a herd. There is deliberately no “come back early” hedge, because an early return finds the pool still full and re-books at the back of the schedule. - The consumer keeps polling while any pool it feeds has room, or while its per-queue deferral budget lasts (
FC_ROUTER_DEFERRAL_BUDGET, default 15,000). It pauses only when every pool it feeds is full and the budget is spent. - A single reservation is capped by
FC_ROUTER_DEFERRAL_MAX_DELAY_SECONDS(default one hour), with backward jitter over its last quarter. - Every backend honours the deferral delay and counts the redelivery. The NATS consumer defaults became
max-deliver=-1andmax-ack-pending=-1, so the router owns the decision to give up. - While a deferred copy is parked, its in-flight entry is kept (
DeferredUntil). A second copy of the same message id arriving under a new broker id is acknowledged as a duplicate, not deferred beside it.
Intra-pool head-of-line blocking, where one slow message group monopolises a shared pool buffer, is explicitly not addressed. A job like that belongs in its own pool.
Consequences
Section titled “Consequences”Good:
- A slow pool no longer starves its siblings on the same queue.
- The broker keeps durability and dead-lettering. A router restart loses nothing because nothing is held that the broker does not also hold.
- Deferral is breaker-neutral and attempt-neutral, so backpressure never trips a circuit or burns retry budget.
Bad:
- The deferral budget exists because deferred messages stay in flight at the broker, and SQS FIFO stops delivering from a queue at 20,000 in flight. The budget must be at least the slow pool’s backlog. A backlog beyond roughly 15,000 on a shared FIFO queue cannot be handled from the consumer side and needs its own queue.
- A reservation is not recalled. Raising a pool’s concurrency tenfold mid-backlog leaves already-deferred messages returning on the old schedule, so the pool idles until they arrive (bounded by the horizon).
- The router keeps per-process state (buffers, reservations, in-flight tracker), which is why ordered processing needs a single active router (see leader-gated processors).
Alternatives considered
Section titled “Alternatives considered”| Alternative | Why not |
|---|---|
| Stop polling when any fed pool is full (the original rule) | Head-of-line blocking across pools, as described above. |
| Nack messages for a full pool | A Nack reads as failure to redrive policies and breakers, and returns immediately, so the batch bounces in a tight loop. |
| One consumer per pool | A queue’s messages cannot be filtered by pool at the broker, so each consumer would still fetch and bounce the others’ traffic. |
| A push endpoint on the router | Shifts durability onto the router and duplicates broker features. |