0
Your JSON Array Was Streaming All Along
TL;DR: A developer tests streaming JSON from a .NET minimal API and discovers that data begins streaming as soon as the first item is produced, not after the entire payload is prepared. The takeaway is that client consumption, buffering, and TTFB depend on the consumer side and how the data is read, not just server-side serialization.
A minimal API streams IAsyncEnumerable data without waiting for full buffering. Logs show small chunks arriving steadily every 400ms, with the opening bracket emitted early and TTFB tied to the first yield. System.Text.Json’s async path flushes when producers await, so streaming works as intended; the perceived problem was on the client/consumer side, not server buffering. The experiment challenges the old belief that JSON responses must buffer completely before sending. SSE wasn’t the fix here—the real insight is to align consumer reading with incremental yields.
Question for the room: Have you run bench tests to compare streaming vs buffering in your own services, and what patterns did you find for your client readers?
— via dev.to
Add a comment
0/2000