This is the "one billion checkboxes" idea from Anders Murphy's hyperlith, done the way this whole site works: CQRS over one SQLite database, and the server re-rendering the entire page for every change.
1. The board is one attribute
The state of all 2,304 pixels is one string on the element: cells, a hex digit (palette index) per pixel, row by row. The server renders it like any other markup. When a new frame morphs in, the attribute changes and the component repaints its canvas. The component never owns the board. It only draws what the server says, plus your own pixels in flight, drawn faded.
<!-- rendered by the server into every frame of the page's stream -->
<sb-pixel-board id="board" size="48" cells="0000…5ff5…0d00"
data-on:sb-paint="@post('/cmd/paint', {
payload: {color: evt.detail.color, cells: evt.detail.cells},
requestCancellation: 'disabled'
})"></sb-pixel-board>
2. Painting is a command
A stroke emits sb-paint every 80 ms, with the cells it crossed; fast drags are interpolated so there are no gaps. Each batch is a short POST that answers 204 No Content and returns no HTML. requestCancellation: 'disabled' matters here: by default Datastar cancels an in-flight request when a new one goes to the same URL, which would drop pixels mid-stroke. A per-session token bucket (20 pixels per second, bursts up to 60) keeps any one painter from flooding the board.
// internal/commands/board.go: runs inside the single writer's batch.
func (c PaintPixels) Apply(ctx context.Context, tx *sql.Tx) error {
for _, i := range c.Cells {
tx.ExecContext(ctx, `INSERT INTO board_cells (board, idx, color, painted_at)
VALUES (?, ?, ?, ?) ON CONFLICT (board, idx) DO UPDATE
SET color = excluded.color, painted_at = excluded.painted_at`,
c.Board, i, c.Color, now)
}
// bump the version: every open stream re-renders once the batch commits
...
}
A single writer goroutine drains the command queue. Everyone's strokes that arrive together are applied in one SQLite transaction, each in its own savepoint, and committed once.
3. Every tab re-renders the whole page
After the commit, the hub wakes every open render stream. Each re-renders its page from a fresh read snapshot and sends the entire page again. The encoded board is cached per version, so a thousand viewers cost one query. Pages whose output didn't change send nothing.
Sending the whole page sounds wasteful until you look at the wire. The stream is compressed with Brotli, and the compressor keeps its window across frames. A full frame of this page is about 9.7 KB; the first one compresses to about 3.4 KB, and after a paint each complete re-render costs about 17 bytes. There is no diffing code anywhere: Datastar morphs the DOM, and compression takes care of the network.
4. Presence
"Watching" counts the open render streams on this page. The hub wakes the other viewers when someone joins or leaves, so the number is live too.