Skip to content

Blog

One Loop Per Core

The part of every TCP server you keep rewriting, written once.

Every TCP server re-implements the same three unglamorous things: a pool of event loops across the cores, the accept loop that fans connections out to them, and the shutdown dance that tears it down without hanging. None of that is your protocol, and all of it is where the concurrency bugs live. The thirteenth familiar owns exactly that and nothing else, so a new protocol is a coroutine, not a runtime.

Interchangeable Parts

Three compression formats behind one interface, swapped by changing a single word.

Compression is a set of tradeoffs, interop versus speed versus ratio, and the honest answer is 'it depends,' which is useless if switching backends means rewriting your call sites. The twelfth familiar puts three incompatible formats behind one identical shape, so choosing between deflate, lz4, and zstd is a matter of changing a single word in your code, and nothing else.

The Shunting Yard

Turning a boolean query into something a machine can walk, in one pass over two stacks.

Infix is how people write boolean queries and the worst way to evaluate them, because precedence and parentheses mean you cannot just read left to right. Dijkstra's shunting-yard algorithm fixes that in a single pass with two stacks, reshuffling 'a OR (b AND NOT c)' into a form a machine walks without ever recursing. The eleventh familiar is that algorithm, and the query language it feeds never needs the parse tree at all.

Bytes You Can Type

A binary blob, rewritten as one big number in an alphabet a human can actually type.

Sooner or later a pile of bytes has to face a human: an id in a URL, a hash in a log line, a key read off a screen and typed into another. Hex is twice too long, base64 carries characters that break in URLs and look alike on paper. The tenth familiar makes bytes typeable by treating the whole blob as one enormous number and rewriting it in a friendlier base.

Packing a UUID

Shrinking a 128-bit id by noticing how much of it is not random.

A UUID is sixteen bytes, and we treat them as sixteen bytes of pure randomness. A time-based UUID is nothing of the sort: it is a timestamp and a clock and a machine id wearing a hex costume, and a stream of them from one server repeats itself enormously. The ninth familiar reads that structure and packs the same id into eight bytes, decoded in nanoseconds and sortable by time.