The encyclopedia · Engineering & Operations · Technical decision · 2008–2010
Facebook built Haystack to store billions of photos with metadata in RAM
Facebook's photo store packs each image as a needle in a giant haystack file, cutting per-photo metadata so all lookups run in memory — one disk read per photo.
The solution
By 2010 Facebook had over 65 billion uploaded photos — 260 billion images once all sizes were counted — growing by a billion new photos each week. On the old network-attached storage, each read needed several disk operations to translate a filename to an inode and load metadata, so metadata access became the throughput bottleneck.
Haystack's design inverts that: photos are appended sequentially into large files (the haystack), each photo a 'needle' with only a few bytes of metadata — enough to locate it. All metadata is loaded into main memory, so a read touches disk at most once. Because photos are written once, read often, never modified and rarely deleted, the append-only layout fits the workload perfectly.
Haystack also replicated photos across storage machines for fault tolerance and cut reliance on expensive CDN reads. The OSDI 2010 paper reported it as Facebook's production photo store handling over 20 petabytes on inexpensive commodity hardware.
Why it worked
- At most one disk operation per photo read
- Tiny per-photo metadata makes in-memory lookups practical
- Append-only layout matches write-once, read-often photos
- Reduced dependence on costly CDN traffic
What can be applied
When a filesystem's per-file overhead is the bottleneck, design storage around the workload: write-once, read-often data deserves an object store whose metadata fits in RAM.
Aftermath
Haystack anchored Facebook's photo infrastructure through the era of billions of uploads, and its log-structured, metadata-in-memory ideas influenced later object stores. The paper became one of the most cited systems papers on storage for social-scale photo workloads.
Sources
- Finding a Needle in Haystack: Facebook's Photo Storage
- Finding a Needle in Haystack: Facebook's Photo Storage (paper PDF)
spotted an error? The archive wants to know.