Posts tagged “go”
-
How do two replicas find what's different without sending everything?
Comparing two replicas of a million 200-byte records: a full copy is 203 MiB, a hash per key 43 MiB. A Merkle tree found one changed key with 2 KiB of hashes and ten changed keys with 15 KiB. The catch is round trips: a deeper tree sends fewer bytes but needs more of them. Measured, with the code.
-
How do you find what's nearby?
Among a million points across India, finding everything within 1 km took 104 ms with a full scan, 1.2 ms with geohash cells and 43 µs with a quadtree, all returning the same results. Geohashes are simple and fit any key-value store; quadtrees adapt to density. Measured, plus what PostGIS and Redis…
-
How do you add a cache node without moving every key?
hash(key) % N moves 91% of keys when you add an 11th node. Consistent hashing, rendezvous hashing and jump hash move 9%. Measured on a million keys: keys moved, balance, lookup cost, and which one to pick.
-
How do queues schedule millions of delayed retries?
"Retry this in 30 seconds", a million times over. A min-heap, a timing wheel, and a row in PostgreSQL with an index on its due time, measured: what each costs to add, cancel and fire, how late jobs run, and what survives a restart.
-
Why is there an append-only log under queues, databases and the outbox?
PostgreSQL's WAL, Kafka's partitions, a transactional outbox and an event-sourced store are all the same structure: records appended to the end, read in order, never changed. Why appending is the shape durability takes, what an fsync costs, and how group commit gets 30x more out of the same disk…
-
How do you check "have we seen this?" for millions of items cheaply?
An exact set of a million emails took 56 MB; a Bloom filter answering the same question with 1% false positives took 1.2 MB. Bloom vs cuckoo vs an exact set, measured: memory, false positives, deletes, and what happens when you overfill them.
-
Why are some databases fast at writes and others at reads?
Under the hood, most databases are either a B-tree or an LSM tree. A B-tree updates data where it lives and pays for random writes; an LSM tree appends and sorts later, and pays at read time. Measured with the engines under etcd and CockroachDB: 54× vs 7× bytes written per byte stored, and reads…
-
Which cache eviction policy keeps the most hits?
On skewed traffic, LFU and W-TinyLFU kept 49% hits in a cache holding 1% of keys, against LRU's 40%. A one-off scan cut LRU to 26% for a while. When popularity moved to new keys, plain LFU collapsed from 51% to 13% and stayed there; W-TinyLFU recovered to 47%. Measured, with the code.
-
How do you match messy part numbers to a catalog?
Customers write 'brg-6204 2rs', 'BRG62O4RS' and 'sealed bearing 6204'. Exact maps, normalised keys, edit distance and token overlap each catch a different kind of mess, and each has a data structure that keeps it fast at 100,000 parts. Measured.
-
How do you find the top 10 among billions of events?
Counting every key exactly took 58-149 MiB for 5 million keys. A count-min sketch with a small heap found the true top 10 in 2 MiB; Space-Saving did it in 62 KiB. With too few counters on flatter traffic, Space-Saving found only 2 of the 10. Measured, and when each one is safe.
-
How does a leaderboard stay sorted under constant updates?
At a million players, a skip list updated a score in 6 µs and found a player's rank in 3 µs. A sorted array found ranks fast but took 3.4 ms per update; a plain map updated in nanoseconds but needed 22 ms per rank. That's why Redis sorted sets use skip lists. Measured, with the code.
-
How do you count unique visitors without storing them?
An exact set of 10 million visitor IDs took 289 MiB. A HyperLogLog sketch of 16 KiB counted them within about 1%, and seven daily sketches merged into a weekly count without the raw data. How it works, measured at four precisions, and where Redis and PostgreSQL already have it.
-
How do you make LLM document extraction reliable enough to automate?
Why I route extracted documents by their weakest field, treat model output as untrusted, and judge the system by straight-through rate and error rate among auto-accepted documents.
-
How do you rate-limit without running out of memory?
A rate limiter is a map that attackers get to grow. How I key it, bound it, and decide what happens when it's full, with the Go code and tests.