---
title: "An analysis of Facebook photo caching"
description: "Facebook's photo-serving stack (browser caches, PoP edge caches, a photo-ID-sharded origin cache spanning data centers, and the Haystack backend) cuts backend traffic so Haystack serves only 9.9% of photo requests, based on a month-long trace from an SOSP study."
url: "https://swe.quest/articles/an-analysis-of-facebook-photo-caching-9de93a54cc38848d"
canonical: "https://engineering.fb.com/2014/02/27/web/an-analysis-of-facebook-photo-caching-2/"
source: "Meta Engineering"
published: "2014-02-27"
difficulty: "medium"
kind: "Research"
reading_minutes: 6
tags: ["caching","cdn-edge","performance","algorithms"]
---

# An analysis of Facebook photo caching

A post on [Meta Engineering](https://swe.quest/sources/meta.md), published 2014-02-27, 6 min read, Research. Original: [https://engineering.fb.com/2014/02/27/web/an-analysis-of-facebook-photo-caching-2/](https://engineering.fb.com/2014/02/27/web/an-analysis-of-facebook-photo-caching-2/)

## Summary

Facebook's photo-serving stack (browser caches, PoP edge caches, a photo-ID-sharded origin cache spanning data centers, and the Haystack backend) cuts backend traffic so Haystack serves only 9.9% of photo requests, based on a month-long trace from an SOSP study. Photo popularity follows a power law that flattens toward a stretched exponential deeper in the stack, and browser/edge caches mainly absorb the most popular photos. Trace replay shows doubling cache size lifts edge hit ratio from 59% to 65% and origin from 33% to 42.5%. Replacing FIFO with S4LRU (segmented LRU) raises edge hit ratio to 67.7% and origin to 46.9% at current size, outperforming LRU, LFU and other tested policies.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Caching](https://swe.quest/tags/caching.md) (Backend & APIs)
- [CDN & edge](https://swe.quest/tags/cdn-edge.md) (Infrastructure)
- [Performance engineering](https://swe.quest/tags/performance.md) (Reliability & operations)
- [Algorithms](https://swe.quest/tags/algorithms.md) (Architecture & design)

## Prerequisites

- cache eviction policies ([easy posts on Caching](https://swe.quest/tags/caching.md?difficulty=easy))
- CDN basics ([easy posts on CDN & edge](https://swe.quest/tags/cdn-edge.md?difficulty=easy))
- power law distributions

## Keywords

Facebook, Haystack, S4LRU, SOSP, LRU, LFU

## Related posts

- [Inside Facebook’s video delivery system](https://swe.quest/articles/inside-facebook-s-video-delivery-system-d5975357617c95f8.md): Meta Engineering · 2024-12-10 · Medium · 13 min read · Recommendations & ranking, Video & media, System design, Mobile, Refactoring & migrations
  Facebook spent roughly two years unifying its separate Watch and Reels stacks across mobile clients, the server layer and ranking, in a deliberate order.
- [Measuring the back/forward cache with Application Metrics](https://swe.quest/articles/measuring-the-back-forward-cache-with-application-metrics-3b96d5be7b308071.md): Sentry · 2026-09-24 · Medium · 5 min read · Web performance, Browsers, Observability, JavaScript
  Sentry's new opt-in bfcacheMetricsIntegration (JavaScript SDK v11) turns the browser's back/forward cache decisions into application metrics, closing a blind spot where cache hits leave no page-load telemetry.
- [Making Shopify’s Flagship App 20% Faster in 6 Weeks Using a Novel Caching Solution](https://swe.quest/articles/making-shopify-s-flagship-app-20-faster-in-6-weeks-using-a-novel-caching-100f1c4cb3fa31e6.md): Shopify Engineering · 2021-09-22 · Medium · 8 min read · Caching, Ruby, Scaling, Deployment, Performance engineering
  Shop's home feed, which aggregated orders and carrier tracking data and accounted for 30% of database load, was moved behind a custom write-through cache in Memcached, cutting database load by 15%, overall GraphQL latency by about 20% and CPU usage by a double-digit percentage.
- [Cutting Threads’ send latency in half](https://swe.quest/articles/cutting-threads-send-latency-in-half-8bdebcb999eebcc4.md): Meta Engineering · 2021-03-22 · Medium · 4 min read · Performance engineering, Caching, Load balancing, Distributed systems
  Instagram's Threads messaging app cut media send latency in half, partly by fixing a "configure" endpoint that ran four times slower in one region.
- [How Facebook encodes your videos](https://swe.quest/articles/how-facebook-encodes-your-videos-a25a3c51f5bfb7c5.md): Meta Engineering · 2021-04-05 · Medium · 12 min read · Video & media, Machine learning, Scheduling, Cost optimization
  Facebook prioritizes advanced video encodings (VP9, slower H264 recipes) by a Benefit/Cost score instead of hard-coded rules.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
