Senior · Design · Backpressure is a memory ownership policy

How would you design admission, buffer ownership and cancellation for an overloaded upload API?

Think through your answer before opening the explanation.

Memory & GC

Reveal answer and reasoning

Write down the owner at each stage: admission, input read, queue, worker, downstream write and response completion. A successful enqueue can transfer ownership to the queue; a failed or cancelled enqueue must leave one clearly responsible owner that disposes or returns the item. If the queue drops an item, the drop policy needs a resource-release path. Channel completion and task completion are separate events, so shutdown must drain or dispose remaining owned items deliberately.

For an interview, ask what happens when every producer waits while holding a rented one-megabyte buffer. A strong answer identifies the unbounded ownership outside the channel, moves admission earlier and specifies full-queue behavior. It then proposes evidence: peak waiting callers, active leases, bytes retained by stage, cancellation cleanup and throughput under a slow consumer. Merely increasing GC frequency does not solve that graph.

Use the interactive comparison button to increase queue capacity to ten thousand. Keep arrival and service rates fixed and explain why capacity is unchanged while retained payload ownership rises. Restore the bounded queue and discuss where rejected or waiting callers go. If they retain full payloads elsewhere, add them to the model rather than declaring the system bounded.

Extend the portable budget with one MiB of independent per-worker workspace and a retained idle pool allowance. Keep the accounting nonoverlapping and test zero, negative and overflow inputs. Finish with a shutdown timeline covering queued, active and not-yet-admitted requests, including which component releases each buffer when cancellation interrupts the pipeline.

What a strong answer covers

  • A bounded channel does not bound memory held by waiting producers.
  • Acquire a bounded admission lease before large payload allocation.
  • More replicas multiply per-process pools and baselines.

Common pitfall

Calling a pipeline memory-bounded merely because its channel capacity is bounded while producers hold payloads outside it.

Follow-up questions

  1. Where do waiting producers retain state when admission is full?
  2. How do per-process pools affect aggregate memory across replicas?

Self-review

Choose what to revisit. These marks are your own assessment and are separate from lesson completion.

Primary references

Open lesson and code ↗

← All interview questions