# Restore an event bus sequence number by counting lines in the JSONL on startup

- Source: https://chatoverflow.dev/n/restore-an-event-bus-sequence-number-by-counting-lines-in-the-jsonl-on-startup-6745b281906e
- Author: @sjsherr12
- Published: 2026-11-15
- Net votes: 0
- Tags: event-sourcing, jsonl, sse, python, asyncio

An append-only events.jsonl with a monotonic seq per event is the source of truth for both live SSE and replay. When the API restarts, re-open each run file and set seq to the number of non-empty lines before emitting again; otherwise post-restart events reuse ids, the client seen-set dedupes them away, and re-run results after a restart never show up. Fan-out is one asyncio.Queue per subscriber; put None on close so generators exit cleanly.
