For each photo, four versions (called images) are stored and they are: large, medium, small, and thumbnail

  • Challenges: Looking up a single file from a huge set of files

  • Design Goals

    1. High throughput and latency: Minimize disk I/Os
    2. Fault tolerant: Replicate photos in geographically distinct locations
    3. Cost effective: Cost per terabyte of usage must be kept low
    4. Simple: Straightforward to implement and maintain

Typical Design

  • CDN (content delivery network): is a network of nodes that cache contents.

    For example, clients want to retrieve some photos on a website. First, it would provide a query to local DNS, if local DNS does not know the mapping, it would forward the query to higher-level DNS servers with more mapping. But “todaynic.com” DNS does not directly return the IP address for “hksimg.com”, it returns the host name for the CDN server. Then, the local DNS server would try to use the hostname to resolve the IP address and contact the AWS DNS to get the IP address.

  • CDN serves a large-scale cache

    • Pros: world-wide scale deployment, fast response time
    • Cons: cannot control the content (DNS is also size limited, it would remove the old content if space insufficient)
  • Limitations
    Facebook (or social networking sites in general) has a very different access pattern from web sites that old contents are frequently visited (e.g, friend’s album)

Haystack

  • User Operations

    1. Web server forwards the request to the Haystack Directory

    2. The Haystack Directory constructs URL for each photo

      • http://<CDN>/<Cache>/<Machine id>/<Logical volume,Photo>
    3. CDN looks up the photo internally

      • If CDN lookup fails, the CDN strips the <CDN> part from the URL and contacts the Haystack Cache
      • If Cache lookup fails, the Haystack Cache strips the <Cache> part from the URL and contacts the Haystack Store

Haystack Directory

  • Directory have a global view of the storage, similar to the namenode in HDFS
  • Four main functions:
    1. Provides a mapping from logical volumes to physical volumes
    2. Load balances writes across logical volumes
    3. Determines whether a photo request should be handled by the CDN or by the Haystack Cache
    4. Identifies logical volumes that are read-only

Haystack Cache

  • Distributed hash table, uses photo’s id to locate cached data

  • Receives HTTP requests from CDNs and browsers

    • If photo is in Cache, return the photo
    • If photo is not in Cache, fetches photo from the Store and returns the photo
  • Add a photo to Cache if any one of two conditions are met:

    1. The request comes directly from a browser, not the CDN

      Because if the photo is not in the Cache, the Cache will return the photo to the CDN, and CDN itself is also a Cache, so CDN supposely would cache the photo. It is needless to cache two copies of photo in different part of Caches.
    2. The photo is fetched from a write-enabled Store machine

      Because the photo fetched by a write-enabled Store machine is likely to be accessed very soon

Haystack Store

Haystack Store would pack the images together, each image is called needle, each needle consists of multiple fields

  • Haystack store file

    • A superblock file accompanied by many needles
    • Log-structured format: append-only
  • Haystack index file

    • provides minimal metadata required to locate a particular needle in the store
    • Same order as store file
    • A subset of store file, butwithout photo data
    • For disaster recovery
    • Less than 1% of store file
  • Read

    • Each store machine maintains an in-memory index, which accessing in-memory does not count I/O
    1. Look up the in-memory index (0 I/O)
      • The offset in the Haystack store file is found (Assume store file is always opened)
    2. Seek and read by moving the disk arm to the beginning of the needle (1 I/O)
      • Seek takes (1 I/O)
      • Since the photo is sequentially written, no further I/O ops incurred
    • In total, 1 I/O
  • Write

    • Fault Tolerance: three replicas
    1. Append 4 images to the haystack store file
      • Seek to the end of file and sequentially write (1 I/O) [3 replicas, 3 I/Os]
    2. Append 4 images to the haystack index file
      Seek and then sequentially write (1 I/O)
    3. Update the in-memory index (0 I/O)
    • In total, 6 I/Os (2 I/Os * 3 replicas)
  • Delete

    • Need to delete 3 replicas
    1. Remove the files in the in-memory index
    2. Mark the 4 images of file deleted (modify the flag of the needles)
      • Noice: these flags are located in different position, which cannot modify it by 1 I/O to update the flags in all 4 different places, and need to issue 4 non-sequential I/Os to update the files individually.
      • 4 seek-and-write for images
      • another 4 for indexes
    • In total, 24 I/Os (8 I/Os * 3 replicas)

Contributions

  • Reduced disk I/O
    • 10 TB/node -> 10 GB of metadata
      • ~10 bytes per image, ~40 bytes per photo
      • This amount is easily cacheable!
  • Simplified metadata
    • No directory structures/file names
      • 64-bit ID
    • Results in easier lookups
  • Single photo serving and storage layer
    • Direct I/O path between client and storage
    • Results in higher bandwidth

BLOB Storage

  • An important class of data that Facebook stores is Binary Large OBjects (BLOBs)
  • BLOBs are immutable binary data (Created once, read many times, never modified, may be deleted)
  • Examples of BLOBs: Photos, videos, documents, traces, heap dumps, and source code

    • There exist significant diversities in BLOB sizes for different types

Temperature Zones Exist

  • Temperatures (access frequency)
    • Hot: BLOBs receive many requests
    • Warm: BLOBs receive few requests
    • Cold: BLOBs almost receive no requests
      • Need to be stored persistently
      • Take days or hours to retrieve
  • Strong correlation between age and temperature of a BLOB

    • Request rates drop over time (temperature drop over time)
    • But please notice that even the data is old, they may still regularly be accessed
  • Warm Content is a Lot!

    • Warm cutoff: 1 month
    • More than 80% of objects are warm of all types (Remaining 20% of objects are hot)

    • Applying replication to warm content provides fault tolerance, but introduces very high storage overhead

      • Haystack uses replication for fault tolerance, BUT it is not suitable for using Haystack for warm storage

Facebook’s BLOB Storage


Haystack and f4 are at the same layer, if the data is hot, they will be stored in Haystack, if they become warm, they will be moved and stored in f4

Haystack Fault Tolerance

Replication Factor: to quantify the storage overhead.
Store x amount of data, in fact it is required to introduce some redundancy for fault torlarence, so the actual amount of data is y (> 0). Replication Factor = y/x (min. = 1).

  • Triple replication of data files + (10+2)-RAID-6 (those data would be stored in different racks or servers)

    • In each host, the raid is attached which is a redundancy scheme that provides fault tolerance against failures (RAID-5: one disk failure, RAID-6: two disk failures)
    • (10+2)-RAID-6: 10 disks are storing data, and two additional disks are storing the redundant data (parity)
  • Replication factor = 1.2 x 3 = 3.6x (minimum number of disk failures that cause data loss: 9)

f4 Fault Tolerance

  • Goal: achieve storage-efficient fault tolerance
  • Four types of failures:

    1. Drive failures, at a low single digit annual rate
    2. Host failures, periodically
    3. Rack failures, multiple time per year
    4. Datacenter failures, extremely rare and usually transient but potentially more disastrous
  • A datacenter is partitioned in cells, each using 14 racks of 15 hosts with 30 4TB drives per host

    • Each cell has 25PB raw storage

Erasure Coding

  • Divide file to k data blocks
  • Encode data blocks to additional n-k parity blocks (e.g., linear multiplication)
  • Distribute n data/parity blocks (a stripe) to n nodes
  • Fault tolerance: any k out of n blocks can recover file data

    • Redundancy Factor: $4/2 = 2\times$ (i.e., $n/k$)
  • Bitwise XOR:

Reed-Solomon codes

  • Support any n and k (provided that n > k)
  • Minimum storage redundancy to provide the fault tolerance against any n-k failures
  • f4: (n, k) = (14, 10)

    • any 10 of this 14 blocks can recover the original data
    • Redundancy Factor: $14/10 = 1.4\times$ (i.e., $n/k$)
  • Advantages:

    • Reduce storage space
    • High fault tolerance
  • Disadvantages:
    • In general, k blocks needed to recover a lost block
      Expensive Repair Operarion (read amplification): It needs to read more data in order to recover some lost data. Any k out of n blocks can recover the data, so even if one block lost, still need to first read k blocks to recover the original data, in order to recover a particular block.

Erasure Coding in f4

  • Consider a big Block size = 1GB
    • Each block contains multiple BLOBs
    • Large block size reduces metadata management
  • Block layout in an f4 cell

    • Distribute each RS(14,10) stripe across 14 racks (10 blocks, generate 4 additional parity blocks, and distribute them into 14 nodes, each node is located in a distinct rack)
    • Tolerate rack, host, and disk failures of an f4 cell (Up to 4 racks, up to 4 hosts and up to 4 disks failures can be tolerate)
  • How to tolerate data center failures?

    • Double replication: Replicating a stripe in two cells at two different data centers
      • Redundancy factor = 1.4 * 2 = 2.8x
    • Geo-distributed XOR coding: Add an XOR parity to two stripes
      • Redundancy factor = 1.4 * 1.5 = 2.1x