Software Architecture · Design Principles
Designing for Scale
Removing shared state and adding caching layers.
1 min readPublished Updated
- scale
- caching
Scaling a system usually means removing shared mutable state and adding caching layers.
ts
const cache = new Map<string, unknown>();
function memoize<T>(key: string, compute: () => T): T {
if (cache.has(key)) return cache.get(key) as T;
const value = compute();
cache.set(key, value);
return value;
}| Strategy | Trade-off |
|---|---|
| Horizontal scaling | More infra, less single-point risk |
| Caching | Faster reads, staleness risk |
| Sharding | More capacity, cross-shard queries get harder |
- Target p95 latency
- 15 ms
- Cache hit ratio
- > 95%
- Failure mode
- Serve stale, never block