An analysis of Facebook photo caching

Visit the post for more.

Wyatt Lloyd
8 min readadvanced
--
View Original

Overview

The article analyzes Facebook's photo caching system, detailing its multi-layered architecture and the effectiveness of various caching strategies. It discusses findings from a month-long study on request patterns and caching efficiencies, highlighting the importance of advanced algorithms and larger cache sizes in improving performance.

What You'll Learn

1

How to analyze the effectiveness of different caching layers in a photo-serving stack

2

Why increasing cache sizes can significantly improve hit ratios

3

When to implement advanced caching algorithms for better performance

Prerequisites & Requirements

  • Understanding of caching concepts and systems

Key Questions Answered

How effective are the different layers of Facebook's photo-serving stack?
The study found that each layer of the caching stack significantly reduces the volume of traffic, with the Haystack backend only needing to serve 9.9% of requested photos. This indicates a high effectiveness of browser, edge, and origin caches in handling requests.
What is the impact of cache size on hit ratios?
Doubling the size of an edge cache increases the hit ratio from 59% to 65%, while tripling it raises the ratio to 68.5%. Similarly, for the origin cache, doubling its size improves the hit ratio from 33% to 42.5%.
What caching algorithms were tested and how do they compare?
The article tested several algorithms including FIFO, LRU, LFU, and S4LRU. The S4LRU algorithm provided the highest hit ratios, increasing edge cache hit ratios from 59.2% to 67.7% at current size, and to 72.0% at double the size.
How does photo popularity distribution change across caching layers?
The study confirmed that photo popularity follows a power law distribution, which flattens as it moves down the caching layers. This indicates that less popular photos are less frequently cached effectively.

Key Statistics & Figures

Percentage of requests served by Haystack backend
9.9%
This statistic highlights the effectiveness of the caching layers in reducing the load on the backend.
Edge cache hit ratio increase from doubling size
59% to 65%
This demonstrates the impact of cache size on performance.
Origin cache hit ratio increase from doubling size
33% to 42.5%
This shows the potential for improvement in hit ratios with larger cache sizes.

Technologies & Tools

Backend
Haystack
Used for storing all photos in Facebook's photo-serving stack.

Key Actionable Insights

1
Implementing larger caches can significantly enhance performance metrics in photo-serving applications.
As demonstrated in the study, increasing cache sizes led to notable improvements in hit ratios, which is crucial for applications handling large volumes of requests.
2
Adopting advanced caching algorithms like S4LRU can lead to better resource utilization and faster response times.
The S4LRU algorithm showed substantial improvements in hit ratios, making it a valuable strategy for optimizing caching systems.
3
Understanding the shifting popularity of content can inform caching strategies and resource allocation.
By analyzing how photo popularity changes across layers, engineers can better predict which content to prioritize in caches.

Common Pitfalls

1
Relying solely on traditional caching algorithms may lead to suboptimal performance.
Without exploring advanced algorithms like S4LRU, systems may miss out on significant performance gains, especially in high-traffic scenarios.

Related Concepts

Caching Strategies
Performance Optimization Techniques
Content Delivery Networks (cdns)