Writing

Notes on systems, protocols, and the small primitives that make them — from the people building barehands challenges.

Go networkingio

The One-Line Echo Server, and Why io.Copy(conn, conn) Works

A whole TCP echo server fits in io.Copy(conn, conn). It looks like a typo, a thing copied onto itself, but it is a tiny masterclass in interface design. Here is why it works, and why the same line quietly powers proxies, file servers, and your last big download.

Go concurrencycaching

Thundering Herd, One Survivor: Deduplicating Work with Singleflight

A cache entry expires and a thousand requests stampede your database at the same instant, all asking for the same missing key. Singleflight is the tiny pattern that lets exactly one of them do the work while the other 999 ride along.

Go concurrencyrate-limiting

Bursts Are a Feature: Rate Limiting with a Token Bucket

A good rate limiter does not just cap the average rate. It lets a quiet client spend a little saved-up credit on a sudden burst, then settles back to the steady rate. The token bucket models exactly that, and in Go it is a buffered channel and a ticker.

Go networkinghttp

Don't Hang Up Mid-Sentence: Graceful HTTP Shutdown

Every deploy sends your server a SIGTERM. If it dies instantly, the requests it was in the middle of answering become 502s in someone's browser. Graceful shutdown is the difference between a clean rollout and a wall of error-rate alerts.

Go resiliencenetworking

Fail Fast on Purpose: The Circuit Breaker

When a downstream service is down, the worst thing you can do is keep calling it. Every doomed request ties up a goroutine and a timeout, and the failure spreads upstream. A circuit breaker notices the trouble, trips, and starts failing instantly, then carefully checks whether it is safe to try again.

Go concurrencyprofiling

The Bug You Cannot See: Data Races and the Go Memory Model

A counter incremented from several goroutines quietly loses updates. It passes your tests, ships, and then produces wrong numbers at 3am under load. The fix is small. The lesson, that "it worked when I ran it" proves nothing about concurrent code, is the valuable part.

Rust cachingdata-structures

Why LRU Is a Rust Rite of Passage

In C or Go, an LRU cache is a hash map plus a doubly linked list, twenty minutes of work. In Rust, that exact design walks straight into the borrow checker and stops. The struggle is not Rust being difficult. It is Rust pointing at a design smell you learned to ignore.

Rust httpmiddleware

Tower in Miniature: HTTP Middleware from One Trait

Auth, logging, CORS, rate limiting. Every web framework stacks these as middleware, and the pattern underneath axum and tower is smaller than it looks. It is one trait that turns a request into a response, and one function that wraps a service in another.

Rust data-structures

Express Lanes for Sorted Data: A Skip List Without the Borrow-Checker Fight

A skip list gives you O(log n) ordered lookups with nothing but linked nodes and a coin flip, no rotations, no rebalancing. It is also wall-to-wall pointers, which in Rust usually means pain. The trick is to stop using pointers and use an index arena instead.

Rust concurrencynetworking

Borrow, Block, Return: A Connection Pool with a Condvar

Opening a database connection is expensive, so you keep a handful around and share them. The interesting part is what happens when all of them are busy: the next caller has to wait, efficiently, until someone gives one back. That is a job for a condition variable.

Rust cachinghashing

The Ring: Consistent Hashing, and Why hash % N Ruins Your Day

You shard keys across N cache servers with hash(key) % N. It works perfectly until you add a server, at which point almost every key moves and your entire cache misses at once. Consistent hashing moves only about 1/N of the keys instead. Here is the ring that makes that happen.

C data-structuresmemory

A Queue With No malloc: The Ring Buffer

The data structure that audio drivers, network stacks, and embedded firmware are built on is a fixed array and two integers. A ring buffer is a FIFO that never allocates, never moves data, and wraps around the end of its storage as it fills and drains.

C data-structuresmemory

How the Kernel Does Linked Lists: Intrusive Nodes and container_of

The linked list you learned holds a pointer to your data and allocates a node for every element. The Linux kernel turns that inside out. The link lives inside your struct, the list allocates nothing, and one object can be on several lists at once. The magic that makes it work is a pointer-arithmetic macro.

C data-structureshashing

Why Hash Tables Need Tombstones

Open-addressing hash tables store everything in one flat array and resolve collisions by probing to the next slot. They are fast and cache-friendly, right up until you delete a key from the middle of a probe chain and accidentally make every key after it disappear. The fix is a small marker called a tombstone.

C memoryallocators

Free Everything at Once: The Arena Allocator

malloc and free are general, which means they are slow and easy to leak. A huge amount of real software does not need general. It allocates a pile of objects with the same lifetime and throws them all away together. An arena allocator makes that pattern fast, simple, and leak-proof by moving a single pointer.

C encodingparsing

Decoding UTF-8 by Hand, and the Three Traps That Are Security Bugs

UTF-8 looks like a five-minute decode: read a lead byte, read its continuation bytes, shift the bits together. The hard part is rejection. Overlong encodings, surrogates, and out-of-range values are not just invalid, they have been the root of real security holes. A correct decoder is mostly a careful validator.