Skip to content

Cheat Sheet

A single-page reference for all 46 patterns. Print it, bookmark it, or ctrl-F your way through it.

Pick by Problem

Not sure which pattern you need? Start here.

I need to...Reach forWhy
Limit concurrent accessSemaphoreCounter-based, proven in OS kernels
Handle slow consumersBackpressureDon't drop — push back
Cache with evictionLRU CacheO(1) get/put, auto-evict coldest
Fast prefix lookupTrieO(k) by key length, not collection size
Probably-in-set checkBloom FilterZero false negatives, tiny memory
Sorted range queriesB+ Tree or Skip ListB+ Tree for disk, Skip List for memory
Crash-safe writesWAL + CheckpointingLog-then-apply + periodic snapshots
Stop cascading failureCircuit BreakerFail fast, recover gradually
Retry failed callsRetry with BackoffExponential delay + jitter
Control throughputRate LimiterToken bucket, constant refill
Verify data integrityMerkle TreeO(log n) proof with hash chain
Reduce memory via sharingFlyweight or InterningShare immutable values
Avoid GC pressureObject Pool or ArenaReuse or bulk-free
Detect changes cheaplyDirty FlagSkip recomputation if clean
Order distributed eventsLogical ClockLamport or vector clocks
Lazy evaluationIteratorPull-based, zero intermediate alloc
Handle multiple typesTagged Union or VtableTag for closed set, vtable for open set
Write-heavy workloadLSM TreeBuffer → flush → merge
Compose middlewareMiddleware ChainOnion model, each handler wraps next
Balance work across threadsWork StealingIdle steals from busy
Track multiple flagsBitmaskN flags in one integer
Schedule by priorityMin HeapO(1) peek, O(log n) push/pop
Fixed-size FIFORing BufferWraps around, zero alloc
Minimal diff between statesDiff / PatchCompute + apply changes
Decouple producers/consumersObserverSubscribe model
Distribute keys across nodesConsistent HashingAdd/remove node remaps ~1/n
Build order from dependenciesDependency GraphDAG + topological sort
Atomic state transitionsState MachineExplicit states, impossible transitions unrepresentable
Soft-delete with later cleanupTombstoneMark deleted, compact later
Copy-on-mutation sharingCopy-on-WriteShare until someone writes
Deterministic cleanupReference CountingFree at rc=0, no GC pause
Register/discover servicesRegistryName → handler map
Atomic swap of stateDouble BufferingWrite to back, swap to front
Non-blocking readsMVCCVersioned snapshots
Responsive main threadCooperative SchedulingYield between chunks
Single-thread I/OEvent LoopMultiplex without threads
Accumulate then flushBatch ProcessingAmortize per-op overhead
Actor-style isolationActor ModelPrivate state + message passing
Tree traversal dispatchVisitorType-specific callbacks
O(1) alloc from freed slotsFree ListLinked list of free blocks
Merge sorted streamsMerge IteratorK-way merge via min-heap

Complexity Reference

Data Structures

PatternInsertLookupDeleteSpaceKey Tradeoff
BitmaskO(1)O(1)O(1)O(1)Limited to word-size flags
Min HeapO(log n)O(1) peekO(log n)O(n)Only peek-min is fast
Ring BufferO(1)O(1)O(1)O(n) fixedFixed capacity
TrieO(k)O(k)O(k)O(SIGMA * n)Memory-hungry for sparse keys
Skip ListO(log n) avgO(log n) avgO(log n) avgO(n) avgProbabilistic, simpler than trees
Bloom FilterO(k)O(k)N/AO(m) bitsFalse positives possible
LRU CacheO(1)O(1)O(1)O(n)Evicts on capacity
B+ TreeO(log n)O(log n)O(log n)O(n)Disk-optimized, high fan-out
Tagged UnionN/AO(1) dispatchN/AO(max variant)Closed set of types
Merkle TreeO(log n)O(log n)O(log n)O(n)Verification, not search
Merge IteratorN/AO(log k) nextN/AO(k)k = number of streams

System Patterns

PatternThroughputLatencyFailure Mode
Circuit BreakerNormal when closed+0 closed, fail-fast openBlocks all calls when open
Rate LimiterCapped at token rate+0 if tokens availableRejects excess (429)
Retry with BackoffReduced during retriesExponential increaseAmplifies if no jitter
WALSequential write speed+1 write (log first)Safe — replay from log
Batch ProcessingHigher (amortized)Higher (waits for batch)Loses batch on crash
Consistent HashingSame as underlying+hash computation~1/n keys remap on node change

Memory Patterns

PatternAllocFreeOverheadBest For
Object PoolO(1) amortizedO(1) returnPool sizeHigh-churn same-type objects
Arena AllocatorO(1) bumpO(1) bulk freeAlignment wastePhase-based lifetimes
Free ListO(1)O(1)Per-slot next pointerFixed-size blocks
FlyweightO(1) lookupShared, not freedLookup tableMany identical small objects
Copy-on-WriteO(1) shareO(n) on first writeRef count per pageRead-heavy shared data
Reference CountingO(1) cloneO(1) at rc=0Per-object counterDeterministic cleanup
InterningO(k) first, O(1) afterPooledHash tableString/symbol deduplication

Pattern Combos

Patterns rarely appear alone. These are the most common production combos:

ComboUsed InWhy Together
WAL + CheckpointingPostgreSQL, etcdWAL for safety, checkpoint to bound replay
Bloom Filter + LSM TreeLevelDB, RocksDBSkip unnecessary disk reads
Min Heap + Merge IteratorLevelDB compactionEfficiently merge K sorted runs
Circuit Breaker + RetrygRPC, HystrixRetry transient failures, break on persistent
Rate Limiter + BackpressureAPI gatewaysLimit ingress, signal overload
Ring Buffer + Event Looplibuv, io_uringFixed-size queue for I/O events
Object Pool + Free ListGo runtimePool manages slabs, free list tracks slots
MVCC + B+ TreePostgreSQLVersioned rows in disk-optimized index
Dirty Flag + Double BufferingReact FiberMark dirty, batch into next frame
Bitmask + State MachineReact reconcilerFlags encode state, transitions via bitwise ops
Consistent Hashing + RegistryService meshHash to locate, registry to discover
Trie + InterningCompilersIntern strings, look up by prefix

Decision Trees

"Which cache?"

?Need eviction?

"Which memory strategy?"

?All objects same size?

"Which concurrency model?"

?Shared state?

Released under the MIT License.