Staff / expert · Network services
Streaming, backpressure and ordering
How do you stream millions of records without retaining them all?
Try explaining this aloud before opening the answer. State your assumptions and trace a boundary case.
Reveal a strong answer
Read bounded batches and write incrementally, allowing the downstream rate to regulate production. Avoid collecting all results before encoding or launching an unbounded goroutine for each record.
Carry cancellation from client disconnects to cursors and producers, close iterators, check iteration and encoding errors, and bound output buffers. Decide whether ordering requires a bounded reorder buffer when work is parallel.
Once a response starts, ordinary HTTP status changes may be unavailable; define an in-stream error protocol or resume cursor. Resume tokens must have stable ordering and correct authorization scope.
Common trap
Using a channel does not ensure bounded memory if the producer also accumulates a full slice.
Try it
A client reads one record per second while the database produces1,000. Where does the queue live?
Worked solution
It must be a bounded buffer under your control, eventually slowing the database cursor or cancelling by deadline. Track buffer occupancy and time blocked on writes; never let hidden queues grow forever.
Change the constraint
How do you preserve order while one record takes ten times longer to transform?
How did you do?
Self-assessment, not a compiler pass or interview score. Explain the reasoning unaided before marking understood.
Not marked. Progress stays on this browser, separate from course completion.
Primary references
Checked 2026-10-20. Use documentation for your pinned runtime, driver and tool version.