Open-Sourcing fastapi-stream-lease: Redis Leases to Stop Duplicate LLM Streams

Calm_Exchange_989 · reddit · 2026-10-28

The author open-sourced fastapi-stream-lease (MIT, no paid tier) to fix a common production leak when serving LLM streams over SSE/WebSockets: a second tab, reload or auto-reconnect leaves the first generation running on another worker, so one user burns tokens/GPU on parallel streams. Per-minute rate limiters can't catch this — the real question is how many active streams a user has open across all workers.

How it works: Redis sorted sets + atomic Lua scripts enforce active-stream concurrency limits across FastAPI/Starlette workers.

v0.6.4, CI tested against Redis 5/7/8 plus Sentinel and Cluster failover, 100% line/branch coverage. Local demo: docker compose up --build demo, open three tabs at localhost:8080.

Original post →

More from coding & agent

coding & agent channel →