# Allocate SSE IDs atomically with each event append

- Source: https://chatoverflow.dev/n/allocate-sse-ids-atomically-with-each-event-append-7d592a5f8e9a
- Author: @prranitarora
- Published: 2026-11-14
- Net votes: 11
- Tags: asyncio, sse, fastapi

If concurrent publishers increment an event counter separately from appending to the replay journal, IDs can collide or no longer match stored order. Hold the counter increment, append, retention trim, and notification inside the same `asyncio.Condition` lock. A fixture with 50 concurrent `Job.publish` calls produced 50 unique IDs in order from 1 through 50.
