Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Meta Engineering 6 min read Research mediumAdept

An analysis of Facebook photo caching

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.

Assumes: cache eviction policiesCDN basicspower law distributions

Related posts

  • Inside Facebook’s video delivery system

    Meta Engineering mediumAdept

    Facebook spent roughly two years unifying its separate Watch and Reels stacks across mobile clients, the server layer and ranking, in a deliberate order. First came a shared client and server data model, then the immersive Reels UI for long-form VOD, then unified ranking (shipped August 2024) once UI signals were consistent, and finally a single video tab mixing Reels, VOD and live. The delivery pipeline runs on five principles: freshness, ranking-decided order, minimal vending, deterministic fetching and signal-driven delivery. Concretely, clients use prefetch, head and tail loads gated on an in-memory pool of three or fewer network stories; the GraphQL server handles caching, throttling, TAO loads and costly privacy checks; and ranking runs a graph-based multi-stage retrieval and ranking workflow with elastic ranking under load.

  • Measuring the back/forward cache with Application Metrics

    Sentry mediumAdept

    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. Built on the pageshow event and the notRestoredReasons API, it emits three metrics: a hit/miss counter per back/forward navigation, a Chromium-only counter of not-restored reasons with the frame that caused them (e.g. unload listeners, websockets, Cache-Control: no-store), and a distribution of fallback reload duration that measures what each miss cost the user. Because eligibility can regress without code changes, the recommendation is to track hit rate continuously and break misses down by route, release and browser.

  • Making Shopify’s Flagship App 20% Faster in 6 Weeks Using a Novel Caching Solution

    Shopify Engineering mediumAdept

    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. To handle concurrent order updates without serving stale data, each user has a pending-writes counter that workers increment before a database write and decrement after it. A short-expiry key detects crashed writers so the cache can be safely rewarmed. The logic was mixed into Active Record models as concerns, so the ORM API was unchanged. Correctness was validated in a shadow rollout that compared cache and database reads before serving from the cache.

  • Cutting Threads’ send latency in half

    Meta Engineering mediumAdept

    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. The endpoint was IO-bound on a read-optimized write-through cache whose backing store lived in another region, so every write paid a cross-region round trip. Routing the whole web request to the region hosting the backing store batched those round trips. A client-side A/B flag, sent as an HTTP header and matched by a routing rule, showed about a 29% send latency improvement.

  • How Facebook encodes your videos

    Meta Engineering mediumAdept

    Facebook prioritizes advanced video encodings (VP9, slower H264 recipes) by a Benefit/Cost score instead of hard-coded rules. Benefit is relative compression efficiency at fixed quality, measured by Minutes of Video at High Quality per GB (MVHQ), multiplied by effective predicted watch time adjusted for device codec support. Cost is the normalized compute needed to finish the missing lanes of an encoding family, so priority rises as a family nears deliverability. Next-hour watch time comes from two ML models, one at upload time using creator history and one at view time using the video's watch trajectory. These are trained on rebalanced event data and evaluated with RMSE, MAPE, per-category metrics and threshold-based false positive/negative rates.

The quest for software engineering knowledge.

Look:
Layout: