TomoLink
CompaniesNetflixSystem DesignCache Systems Every Developer Should Know
System Design
Mediumcaching-performance

Cache Systems Every Developer Should Know

30 minsCachingPerformance
30 mins
1 sections
Caching, Performance

Overview

Data is cached everywhere, from the client-facing side to backend systems. Let's look at the many caching layers:

Caching Layers

  • Client Apps: Browsers cache HTTP responses. Server responses include caching directives in headers. Upon subsequent requests, browsers may serve cached data if still fresh.
  • Content Delivery Networks: CDNs cache static content like images, stylesheets, and JavaScript files. They serve cached content from locations closer to users, reducing latency and load times.
  • Load Balancers: Some load balancers cache frequently requested data. This allows serving responses without engaging backend servers, reducing load and response times.
  • Message Brokers: Systems like Kafka can cache messages on disk per a retention policy. Consumers then pull messages according to their own schedule.
  • Services: Individual services often employ caching to improve data retrieval speeds, first checking in-memory caches before querying databases. Services may also utilize disk caching for larger datasets.
  • Distributed Caches: Systems like Redis cache key-value pairs across services, providing faster read/write capabilities compared to traditional databases.
  • Full-text Search Engines: Platforms like Elasticsearch index data for efficient text search. This index is effectively a form of cache, optimized for quick text search retrieval.
  • Databases: There are specialized mechanisms to enhance performance, some of which include caching concepts:

Database Caching Mechanisms

  • Bufferpool: This is a cache within the database that holds copies of data pages. It allows for quick reads and writes to temporary storage in memory, reducing the need to access data from disk.
  • Materialized Views: They are similar to caches in that they store the results of computationally expensive queries. The database can return these precomputed results quickly, rather than recalculating them.