The interview problem

Practice prompt

A producer is faster than a network consumer and memory grows continuously. Design bounded buffering and cancellation.

Original practice, not a reported company interview. Scenarios and numbers are illustrative. Interview date: not applicable. Sources retrieved October 1, 2026.

1. Scope and worked approach

Assume a stream pipeline with explicit read/write flow control. When downstream buffers reach a high-water mark, stop accepting more upstream data and resume after drainage. Bound every stage, including decompression and serialization, rather than only the final socket. Propagate errors and cancellation upstream so abandoned consumers stop production. Define whether overload blocks, drops or rejects data according to the product contract.

2. Trace the design or derivation

Read within demand
  → transform bounded chunk
  → write
  → pause on pressure
  → resume or cancel

Report both logical and encoded bytes when compression is involved. A small network queue can coexist with a huge decoded-object queue earlier in the pipeline. Backpressure should limit the expensive representation at its own boundary, and cleanup must release pending buffers when a deadline expires.

3. Calculate the example

A producer emits 20 MB/s while the consumer drains 5 MB/s. Without backpressure, buffered data grows 15 MB/s; a 150 MB budget fills in 10 seconds. Increasing the buffer postpones exhaustion but does not fix the sustained rate mismatch.

4. Failure cases and trade-offs

One library call that ignores a write backpressure signal can bypass the entire design. Blocking while holding unrelated locks can deadlock. Larger buffers absorb bursts but increase memory and cancellation latency; smaller buffers improve bounds but may reduce throughput on high-latency links.

5. Validation, follow-ups and self-review

Throttle the receiver and disconnect mid-stream; measure peak buffers and stopped upstream work. Follow-up: how does compression change byte accounting? Self-review: bound every stage and distinguish burst absorption from sustainable capacity.

Sources and related practice

Technical reference: nodejs.org — Producer/consumer backpressure and buffering.

Source publication/update: Not established. Retrieved October 1, 2026. The workflow, calculations and review exercises are original; this reference is not evidence that a company asked this question.

Continue with Design a video streaming service; Generate resumable customer data exports.

Continue your preparation

Choose a connected learning path or browse more System design questions. Read our editorial method and attribution policy.