Distributed Caching

Multi-tier cache design, TTL expiration policies, cache invalidation strategies, and write-through/write-back patterns.

1 / Building Caches From Scratch

Distributed caching was not a technology I adopted through a library — I built two complete implementations. Shard in Python using asyncio event loops, and Cairn in Java using Virtual Threads. Both implemented Consistent Hashing, TTL-based key expiration, and multi-tier cache design patterns.

2 / Cache Design Patterns

Building caches taught me patterns that are invisible when using Redis as a black box. TTL expiration requires both active (periodic sweep) and passive (check-on-access) expiration to balance memory reclamation with CPU overhead. LRU and LFU eviction policies involve different trade-offs — LRU is simpler but LFU better handles skewed access patterns. Write-through caching provides consistency at the cost of write latency, while write-back caching improves write performance but risks data loss on crash.

3 / Observability

Both Shard and Cairn exposed Prometheus metrics for cache hit rates, miss rates, and p50/p99 latency percentiles. Grafana dashboards visualized these metrics in real time. This observability was essential — without it, you cannot distinguish between a cache that is working well and one that is experiencing high miss rates due to poor key distribution or aggressive eviction.