Senior · Trace · Backpressure is a memory ownership policy

Trace the portable program: what is guaranteed, and what does it not measure?

Think through your answer before opening the explanation.

Memory & GC

int workers = 4, queued = 8, payloadKiB = 256, copies = 2;
long liveKiB = checked((long)(workers + queued) * payloadKiB * copies);
Console.WriteLine($"bounded-live-KiB:{liveKiB}");
long overloadedKiB = checked((long)(workers + 800) * payloadKiB * copies);
Console.WriteLine($"large-queue-live-KiB:{overloadedKiB}");
Console.WriteLine("budget:model;not-measured-RSS");
Reveal answer and reasoning

The portable program explicitly models four active workers, eight queued payloads, 256 KiB per payload and two simultaneous copies. Multiplying twelve owners by 256 and two gives 6,144 KiB. Changing only the queue to eight hundred raises the modeled payload ownership to 411,648 KiB. These are arithmetic consequences of stated assumptions, not sampled heap bytes or RSS.

The long multiplication begins before potentially large products, and checked arithmetic makes overflow a visible failure rather than a wrapped negative budget. Production estimates must validate inputs and distinguish KiB from decimal kilobytes. The program's final line labels the calculation as a model because object overhead, native memory, pool retention and other process state are absent. Adding those quantities requires nonoverlapping accounting.

The budget tab assumes a ten-second fluid arrival interval. It computes service capacity from worker count and per-request service time, estimates active requests, and grows backlog at the positive difference between arrivals and capacity up to the configured queue. Increase service time to model a slow dependency, then increase queue capacity without changing worker count. Observe that a larger queue absorbs more owned payloads but does not improve service capacity.

The baseline, idle pool allowance and native allowance are deliberately separate from active payload copies. They must not double count the same arrays. The model does not predict p99 latency, GC pause distributions, scheduler fairness or exact RSS. It is a tool for testing assumptions and finding a plausible budget before measuring a representative application under real quotas and traffic.

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