The Computing Series

Tradeoffs

AT3 — Simplicity vs. Flexibility

Naive modular hashing (hash(key) % N) is simple: O(1), one line of code, easy to understand. Consistent hashing is more complex: a ring data structure, O(log N) lookup via binary search, virtual nodes to correct uneven distribution. The cost of flexibility is complexity.

The decision point is: does your server pool change? If N is fixed forever, modular hashing is correct. If N changes — due to failures, autoscaling, planned capacity changes — the cost of modular hashing is session breakage on every cluster change. For any system that operates at scale, the server pool changes. Consistent hashing is the standard choice.

AT9 — Correctness vs. Performance

SHA-1 (used by Git) is cryptographic: collision-resistant but slow (~200 MB/s on modern hardware). MurmurHash and xxHash are non-cryptographic: not collision-resistant but extremely fast (5–10 GB/s). For a load balancer routing decision, collision resistance is irrelevant — you do not need a security guarantee, you need speed. For Git, where the hash is a trust anchor, collision resistance matters. Use SHA-2 or SHA-3 for security; use MurmurHash or xxHash for performance.


Read in the book →