Search⌘ K
AI Features

Background of Distributed Cache

Define the core concepts for designing a high-performance distributed cache. Analyze various writing policies, such as write-through and write-back, alongside common eviction algorithms like LRU. Learn how to apply consistent hashing and sharding to ensure scalability and reliability in distributed System Design.

We'll cover the following...

“”

  • <a href=\"#Writing-policies\" aria-label=\“Read more about Writing policies\” >Writing policies
  • <a href=\"#Eviction-policies\" aria-label=\“Read more about Eviction policies\” >Eviction policies
  • <a href=\"#Cache-invalidation\" aria-label=\“Read more about Cache invalidation\” >Cache invalidation
  • <a href=\"#Storage-mechanism\" aria-label=\“Read more about Storage mechanism\” >Storage mechanism
    • <a href=\"#Hash-function\" aria-label=\“Read more about Hash function\” >Hash function
    • <a href=\"#Linked-list\" aria-label=\“Read more about Linked list\” >Linked list
  • <a href=\"#Sharding-in-cache-clusters\" aria-label=\“Read more about Sharding in cache clusters\” >Sharding in cache clusters
    • <a href=\"#Dedicated-cache-servers\" aria-label=\“Read more about Dedicated cache servers\” >Dedicated cache servers
    • <a href=\"#Co-located-cache\" aria-label=\“Read more about Co-located cache\” >Co-located cache
  • <a href=\"#Cache-client\" aria-label=\“Read more about Cache client\” >Cache client
  • <a href=\"#Conclusion\" aria-label=\“Read more about Conclusion\” >Conclusion
""

This chapter explains the design of a distributed cache. First, it is important to understand core concepts such as data write policies, eviction strategies, and cache invalidation. The following prerequisites are covered:

Section

Motivation

Writing policies

Data is written to cache and databases. The order in which data writing happens has performance implications. We’ll discuss various writing policies to help decide which writing policy would be suitable for the distributed cache we want to design.

Eviction policies

Since the cache is built on limited storage (RAM), we ideally want to keep the most frequently accessed data in the cache. Therefore, we’ll discuss different eviction policies to replace less frequently accessed data with most frequently accessed data.

Cache invalidation

Certain cached data may get outdated. We’ll discuss different invalidation methods to remove stale or outdated entries from the cache in this section.

Storage mechanism

A distributed storage has many servers. We’ll discuss important design considerations, such as which cache entry should be stored in which server and what data structure to use for storage.

Cache client

A cache server stores cache entries, but a cache client calls the cache server to request data. We’ll discuss the details of a cache client library in this section.

Writing policies

A cache stores a temporary copy of data that is persistently stored in a database or another datastore. A key design decision is when to write data to the cache versus the database. This choice, known as the write policy, directly affects performance and data consistency.

There are three common writing policies:

  • Write-through: Data is written to the cache and the database in the same operation. This approach ensures strong consistency between the cache and the database, but increases write latency because the operation is only complete after both writes succeed.

  • Write-back: Data is written to the cache first, then to the storage. The write to the database happens later, asynchronously. This results in low write latency but introduces the risk of data loss if the cache fails before the data is persisted to the database. It can also lead to temporary inconsistency.

  • Write-around: Data is written directly to the database, bypassing the cache. Data is loaded into the cache only on a subsequent read miss. This is useful for applications that don’t immediately re-read recently written data, as it avoids filling the cache with potentially unused items.

Quiz

1.

A system wants to write data and promptly read it back. At the same time, we want consistency between the cache and the database. Which writing policy is the optimal choice?

A.

Write-through cache

B.

Write-around cache

C.

Write-back cache


1 / 3

Eviction policies

...