From-Scratch Engineering

System Implementations

12 working implementations of consensus protocols, message brokers, and distributed data structures.

Load Balancer From Scratch

A tiny L7 request router with health checks, round-robin routing, least-connections routing, and forwarded request metadata.

JavaScriptstartersrc/balancer.js

Consistent Hashing Ring

A readable hash ring with virtual nodes and binary-search lookup, the core primitive behind cache and storage routing.

TypeScriptstartersrc/ring.ts

Bloom Filter Membership

A compact membership filter that can reject misses cheaply while accepting a controlled false-positive rate.

TypeScriptstartersrc/bloom.ts

Tiny Search Engine

A small inverted index with tokenization, posting lists, and a BM25-style ranking pass.

TypeScriptintermediatesrc/index.ts

Sliding Window Rate Limiter

An in-memory limiter that stores recent request timestamps per key and computes allow, remaining, and retry-after decisions.

TypeScriptstartersrc/limiter.ts

Lease Leader Election

A lease-based leader election sketch with expiry and fencing tokens, showing the state transition behind one active worker.

JavaScriptstartersrc/leaseStore.js

Write-Ahead Log

A tiny durable key-value store that writes JSONL WAL records before applying in-memory state, then replays safe records after a crash.

JavaScriptstartersrc/wal.js

Gossip Protocol

A push-pull gossip simulation where nodes sample peers, exchange versioned records, and converge without broadcasting to everyone.

JavaScriptstartersrc/node.js

TTL Cache Reaper

An in-memory TTL cache that stores absolute expiry timestamps, enforces lazy expiration on reads, and reclaims memory with active sweeps.

JavaScriptstartersrc/cache.js

LRU Cache

A small least-recently-used cache where reads refresh recency and full-capacity writes evict the oldest entry.

JavaScriptstartersrc/lru.js

Snowflake ID Generator

A compact Snowflake-style generator that packs timestamp, worker id, and per-millisecond sequence fields into one sortable integer.

JavaScriptstartersrc/generator.js

Keyset Pagination Cursors

An ordered in-memory dataset showing how cursor predicates resume after the last seen row while offset pagination can drift after inserts.

JavaScriptstartersrc/pagination.js