Build an SSE stream

Resume after a disconnect

Use event identifiers and a snapshot fallback so reconnection cannot silently create a gap.

9 minute lesson

~~~

If incident 42 was the last applied event, the server replays later retained events or tells the client to fetch a fresh snapshot. That contrast gives us something useful to test instead of a rule to memorize.

EventSource reconnects automatically and can send Last-Event-ID, but the server must decide how much history it can replay. The useful target is not encyclopedic coverage. Make one deliberate choice, observe its consequences, and know which requirement would make you revise it.

The happy path can hide a bad design: you can treat reconnection as success even when the server has already discarded the missing events and still get one successful demo. Push past the demo. retain a bounded event log and fall back to a fresh snapshot when the requested position is no longer available, then test the condition most likely to prove the choice wrong.

The module is moving toward one outcome: Build an SSE feed that reconnects cleanly and can repair a gap instead of merely looking live in one browser tab. Save the before-and-after evidence now; it will make the final project review much more honest.

Disconnect the browser, create several incidents, reconnect, and prove the final state matches a fresh snapshot. Save the evidence, then explain which requirement would force you to choose a different design.

Lesson completed

Take this course offline

Get every free book and course as PDF and EPUB files.

Get the download library →