JINNFLUXResearch & insights

Keep One Slow Subscriber from Stalling a Shared Stream

Use per-subscriber queue limits, fair scheduling, and bounded replay to keep one slow reader from stalling delivery or exhausting the server's memory.

In a fictional live transcript room, the presenter's text freezes while the recorder flushes to storage. The fan-out loop awaits each subscriber write in turn. Once the recorder stops reading and the send path runs out of buffer space, the loop waits for the recorder before it can send more text to the presenter.

What you see during the freeze Where to look first
Commits slow across the room and delivery queues remain shallow Inspect log acknowledgment latency and pending appends.
Commits stay steady and one subscriber's oldest unsent event keeps aging Inspect that subscriber's transport staging and time spent blocked.
Commits stay steady and several streams on one HTTP/2 connection stall together Inspect connection-level send credit and the shared socket queue.
Live readers keep up while a reconnecting subscriber loses ground Compare its effective replay rate with the pace of new commits.

Both designs free the presenter's delivery from the recorder's writes. The room's promise about history determines where the producer hands off each event.

Durable log. Append each event before making it visible and bound the number of pending appends so a slow log can backpressure generation. Dispatch subscriber writes independently. A recorder that pauses spends its own delivery budget while the presenter keeps receiving committed events.

Ephemeral ring. Gate visibility on insertion into a bounded in-memory ring. A reader that falls behind a wrap loses its path to the overwritten events and must restart from available state or leave the room.

Why the average rate misses the overflow

Figure 1 isolates the byte budget in a continuous-rate model. Both queues start empty and have an 8 kB/s drain capacity. Steady arrivals match that capacity throughout. Bursty arrivals run at 38 kB/s for 10 seconds, then at 2 kB/s for 50 seconds. Both sources offer 480 kB over 60 seconds and average 8 kB/s. At a net 30 kB/s, the burst reaches the 240 kB budget after 8 seconds and peaks at an uncapped 300 kB at 10 seconds. Once arrivals slow, that demand shrinks by 6 kB/s, falls back to 240 kB at 20 seconds, and empties at 60 seconds. The steady queue is empty throughout. The average and the ending sample are identical for both sources, yet only one needs more queue space than the server grants.

Figure 1 — The burst reaches the 240 kB budget at 8 seconds and needs 60 kB more at its peak. The curves show illustrative demand before enforcement, not measured data.

Give each subscriber three ways to hit its limit

Real admissions happen at whole-event boundaries, so a queue can have space left and still turn away the next event. The byte cap controls retained payload, while an independent count limit bounds queue entries and reference bookkeeping when events are tiny. The largest allowed encoded event must fit in an empty queue. An age limit on the oldest unsent event protects freshness when a low-volume stream stalls behind a blocked transport. A timer enforces that limit even when the producer falls silent.

Check projected bytes and entries before enqueueing. With an illustrative 256-event ceiling, tiny events can exhaust the entries while leaving most of the byte budget free. A subscriber with a single unsent event can hit the age limit when its transport stays blocked. Give transport staging its own stall deadline once events have left the application queue. When the product promises freshness through transport handoff, carry the event's original deadline into staging so transferring a buffer cannot restart the clock.

At Figure 1's constant 8 kB/s drain, an interactive reader with a 2-second queue deadline has a useful byte budget of about 16 kB ahead of a new arrival. That budget estimates the time until service starts. For a deadline through completion, include the new event's own bytes. A full 240 kB FIFO takes 30 seconds to drain at that rate. If the server uses the 240 kB cap and enforces age only when a byte reaches its deadline, it can retain far more than 16 kB before eviction. During the burst, the oldest unsent byte at elapsed time t arrived at 8t / 38 seconds. Its age reaches 2 seconds at about 2.53 seconds into the burst, with 76 kB queued in the continuous-rate model. The age cutoff ends live delivery well before the queue reaches its byte cap. Whole-event boundaries and stalls change the timing, so keep the age timer even when admission also checks projected wait.

Figure 2 takes a separate snapshot of the fictional room and checks byte admission alone. Each subscriber has a 240 kB limit. The presenter, Viewer A, and Viewer B have 8, 16, and 24 kB queued, respectively, leaving 232, 224, and 216 kB free. The recorder has 220 kB queued and can spare only 20 kB. Assume the readers have sufficient drain capacity and age allowance for their queued work and that each queue has a free entry. The incoming 24 kB event fits all three interactive queues. The recorder switches to recovery.

Figure 2 — The recorder's bar ends at 20 kB, 4 kB short of the space the incoming event needs. Illustrative admission snapshot, not measured data.

Headroom in another subscriber's queue stays reserved for that subscriber's next burst. At process scope, account for physical memory separately from logical lag. An immutable payload shared by several subscribers occupies memory once, but it counts against each subscriber's backlog allowance if each still owes a send. Add queue entries, transport staging, and any per-subscriber encoding copies to the process budget. Count bytes handed to a library against its staging allowance until the library releases them or tears down the write.

Size the byte cap from a burst the product intends to absorb and the drain rate it expects during that burst. Add an allowance for whole events when coarse byte-rate samples hide arrival timing, then check the estimate against a trace at event granularity. To absorb all of Figure 1, a replay-tolerant reader needs 300 kB and an age allowance above the peak FIFO wait of 37.5 seconds before accounting for event boundaries or stalls. With enough entries and that longer age allowance, adding 60 kB can keep such a reader attached through the burst. If an illustrative 10,000 readers each qualify for and fill that increase, their total logical backlog grows by 600 MB. Physical payload memory depends on how many distinct events those queues hold and how many copies the sender makes. Earlier cutoffs shift work to reconnects and log reads. Stagger reconnect attempts and enforce a shared replay budget when the same burst can evict many readers.

Writable at which layer?

On an open, healthy Node.js byte-mode writable, a write() that returns false has accepted the chunk and signaled that the scheduler should suspend that subscriber until drain or teardown. The highWaterMark is a threshold checked after admission, so a hard staging budget needs its own check before the write. For server-to-subscriber WebSocket delivery, read the server library's own outbound buffered-byte counter where available, and reserve room for the next message, including any framing the counter counts. A sender with only a counter can recheck on a timer while the stall deadline is active. The browser's bufferedAmount applies to browser-to-server sends.

Under RFC 9113, HTTP/2 DATA carrying a payload consumes credit in both the stream and connection send windows. The HTTP/2 implementation tracks both. An application can inspect them only if its stack exposes those counters, and a proxy terminates flow control for its own hop. The kernel socket send buffer is a separate queue. A native process with the socket descriptor can inspect local send-queue state through platform facilities such as Linux's SIOCOUTQ. Managed runtimes and browser code generally see only their own buffering signals. On a multiplexed connection the socket queue is shared, so its occupancy cannot be attributed to a viewer from that metric alone.

Use deficit round robin (Shreedhar and Varghese, SIGCOMM 1995) among subscribers that have queued work and room to stage their next event. On a visit, add a byte quantum to the subscriber's deficit. Send whole events in order while both deficit and staging room permit, subtracting each accepted event's encoded size. Reset the deficit when the queue empties. If staging fills, suspend the subscriber. On wake-up, finish the interrupted visit with its remaining credit before adding another quantum on a later visit. That way repeated blocking cannot make credit accumulate independently of service.

In an illustrative round with a 24 kB quantum, both subscribers start at zero credit and have room to stage their writes. The presenter has events of 16 and 12 kB. It sends the first and carries 8 kB because the second will not fit. The viewer has three 8 kB events and sends all three, ending at zero. On the next round, the presenter has 32 kB of credit, sends the waiting 12 kB and resets its deficit when the queue empties. Charging by bytes gives a viewer with many small events a share comparable to a viewer with fewer large events when both remain backlogged. Keep the quantum and maximum event size small enough that a visit does not monopolize the dispatch loop. If tiny events make CPU the bottleneck, yield to the event loop after a bounded number of sends and preserve the visit state across the yield.

Keep catch-up from starving the tail

When a catch-up reader reaches the end of the committed log, register for a wake-up and then recheck the committed position before sleeping. If a commit landed between the empty read and registration, the recheck sees it. If a commit lands after the recheck, the registered waiter must retain the wake-up even if the task has yet to sleep. Use notifications to signal that work is available. Leave payloads in the log and fetch bounded batches, starting recovery at the first event the resume cursor leaves unapplied.

Shared storage moves contention to the read path. Cold replay can occupy storage requests and displace hot tail pages from cache even when the network scheduler is fair. Reserve read capacity for tail readers and limit replay concurrency both per reader and across the log. For a reader that needs to catch up, the effective delivery rate, after storage and network throttling, must exceed the pace of new commits over the catch-up interval. Otherwise its lag cannot shrink. Stop prefetching when the transport's staging allowance fills and keep retention independent of inactive readers so an abandoned offset cannot pin old segments indefinitely.

Overflow ends the live subscription as a unit. Arbitrarily discarding a text delta or its metadata can leave the transcript readable but wrong. Only updates the event contract declares replaceable can be coalesced. Detach removes the subscriber from the scheduler and drops its pending batch. Associate outstanding reads and write callbacks with the subscription that started them so a late completion can release its own resources without modifying a replacement subscription. A close or gap frame can wait behind queued data, so enforce a teardown deadline and let ordinary disconnects enter the same recovery path. If the last subscriber leaves, apply the separate generation lifetime policy.

Choose the limit that should bind first

Set the age cutoff at the point where late text loses its value. Size the byte cap for the bursts a reader can drain within that window, and size the entry cap for the overhead of tiny events. Reserve replay capacity for readers that can gain on the live stream before retention overtakes them. A reader that falls further behind with every commit needs a smaller stream or a restart from newer state. The presenter's next event should leave on schedule either way.