← Back to TypeScript
System Design Primitives
The small machines interviews ask you to build on the spot — a cache that evicts, a bucket that refills, a call that waits. Each one is an invariant you can hold in your head, not a library call.
Challenge: an LRU cache
intermediatechallengeImplement a fixed-capacity cache that evicts the least recently used key, with constant-time get and put.
Challenge: a token-bucket rate limiter
intermediatechallengeImplement a rate limiter that starts full, refills continuously up to capacity, and never reads the clock itself.
TTL cache mechanics
intermediateblankComplete the lazy-expiry path of a TTL cache — the write that stamps an expiry and the read that honours it.
Challenge: debounce with cancel and flush
advancedchallengeImplement a trailing-edge debounce whose pending call can be cancelled or fired on demand.
Review: the queue that stalls after a failure
advancedreviewA concurrency-limited task queue works perfectly until one task rejects. After that, nothing new ever starts. Find the leak.