Why
Strategy and Warhammer streamers run interactive moments during events like ZEvent: they ask a question and want to see where the chat is pointing. HitMap shows it on the stream, almost live. The target was 5,000 to 10,000 viewers, and it had to hold 50,000, with up to ten clicks each on a big moment.
How a click travels
The extension sends a POST with the viewer's Twitch token. The server keeps the last click of each viewer in the channel's session. Every 200 ms, one timer per channel builds the map: a 128×72 density field and the zones sorted by size. The map goes out by Server-Sent Events to the overlay, a browser source in OBS.
Decisions I can defend
- Stateless HTTP POST in, Server-Sent Events out. No SignalR, no WebSocket: viewers only send positions and receive nothing.
- Ingestion and broadcast are decoupled. Nothing is sent per click; the timer produces the map.
- Last click wins for each viewer: an upsert, not a counter.
- Anonymous viewers are filtered when the map is built, not when clicks arrive, so the setting can be changed without losing anything.
- The core library has no ASP.NET dependency: all the logic is tested without a server.
The algorithm
- Positions are stored raw, so a changed setting applies to every click already received.
- Distances are computed in a space corrected for the 16:9 aspect, or a rotated ellipse comes out distorted.
- A separable sliding-sum blur: its cost does not depend on the radius, and no mass is lost at the edges.
- Peak detection, then one zone per peak: centre, covariance ellipse, percentage.
- No allocation per tick: pooled buffers, value types, a bounded stackalloc.
Security
- Channel and role always come from the validated Twitch JWT, never from the request body.
- Stream controls are reserved to the broadcaster.
- The overlay URL is an HMAC token with a generation number: regenerating it revokes the old URL and cuts open streams. It is never written to the logs, and a test checks that.
The bench
A tool that plays the real thing: real HTTP POSTs, real JWTs, and the map received over SSE like the overlay. Four scenarios, from 10,000 viewers clicking once to 50,000 viewers of whom 30,000 click. Its central check replays the accepted clicks locally and requires a map identical to the one received.
Results: tick p99 at most 7.2 ms, click to broadcast p99 211 to 217 ms (bounded by the 200 ms tick), POST p99 at most 19 ms, zero failures, 44 checks out of 44.
What the bench taught me
- Perfect Gaussian clicks only make discs and ellipses. I wrote a crowd generator: irregular targets, each viewer's own aim, sloppy clicks, arrivals in waves, people changing their minds.
- That crowd revealed a real limit: an hourglass-shaped target is split into two zones. It is documented, not hidden.
- Stopping a round dropped the last clicks; the channel's loop now plays a final tick.
- Chrome blocks twitch.tv from calling localhost, so the API serves the extension itself, behind a tunnel, to test inside Twitch.
How it was built
In six steps with Claude Code as an assistant, each one stopped and reviewed before the next. A project file set the decisions that could not move, and the order of priorities: correctness, then testability, then performance, then elegance.


