Free — no signup required

Introduction: The Millisecond Imperative

2 min read

Why Caching Matters

Imagine a library where every time you want to read a book, a librarian walks to a warehouse three blocks away, finds the book, photocopies the relevant page, and walks back. That's what happens when your application queries a database for every request. Caching is the equivalent of keeping the most popular books on a shelf right next to the front desk — the answer is already there, ready in an instant.

In cloud architectures, databases are almost always the bottleneck. Three forces drive this:

  • Disk is Slow: Even NVMe SSDs operate in the microsecond-to-millisecond range. RAM operates in nanoseconds — roughly 100x faster for random access.
  • Network is Slow: A round trip to a relational database involves a TCP handshake, TLS negotiation, SQL parsing, query planning, disk I/O, and serialization. Even on a fast network, this adds up to 1–10ms per query.
  • Money is Finite: Scaling a relational database (RDS, Aurora) to handle 1,000,000 reads per second requires massive instance types, read replicas, and careful tuning. The cost is orders of magnitude higher than adding a cache layer.

Amazon ElastiCache is AWS's managed in-memory caching service. It puts a high-performance key-value store in front of your database, acting as a fast lookup layer:

  • Cache Hit: The requested data is already in memory. Response time: sub-millisecond (typically 0.1–0.5ms).
  • Cache Miss: The data is not in the cache. The application fetches it from the database, stores it in the cache with a TTL (Time To Live), and returns it. Subsequent requests hit the cache.

The cache hit ratio — the percentage of requests served from cache — is the primary metric for cache effectiveness. A well-tuned cache achieves 95–99% hit ratios, meaning the database handles only 1–5% of total traffic.

This is one of 18 chapters

Get every chapter — Kubernetes, Terraform, SRE, distributed systems, and more — with fast daily review built in.

See pricing