A technical analysis explores why Server-Sent Events (SSE) messages may arrive in batches rather than individually. The study uses a Python 3.15.0 environment with zlib 1.3.1 to simulate HTTP/1.0 communication without TLS, proxies, or browser interference.
The author identifies two primary causes for delayed event processing: missing separators in the SSE stream and improper gzip compression handling. In the missing separator scenario, the client receives data but fails to trigger events until a final empty line is processed, resulting in a single multi-line event.
When using gzip without intermediate flushing, the compressor buffers data, sending nothing to the socket until the final Z_FINISH signal. This causes all events to appear simultaneously. Using Z_SYNC_FLUSH allows the compressor to output accumulated data while keeping the stream open, enabling real-time event delivery.
The experiment demonstrates that monitoring the timing of HTTP body reads, decoded text availability, and event parsing helps isolate the cause of latency. The author notes that these findings are specific to the tested configuration and do not imply that compression is incompatible with SSE.


