Ravindra BagaleCourses & study guides Track your progress

Guides

Facebook Architecture Explained: How Facebook Works Behind the Scenes

Short answer: Facebook runs in Meta's own data centres: more than 20 data centre regions with millions of machines, managed by Meta's container system Twine (2024). The web code is written mostly in Hack, running on HHVM. Thousands of microservices sit behind it. Your friends, posts, likes and comments are a giant social graph, stored in MySQL (with the MyRocks storage engine) and served through a huge cache layer called TAO, plus Memcache. Facebook does not use AWS, Google Cloud or Azure for its main app.

Suppose you open Facebook and see a friend's photo

You open Facebook in Nagpur. Your feed shows your cousin's wedding photo, 120 likes and comments from relatives. In simple terms:

  1. Your request reaches the nearest entry point of Meta's network and its load balancers (Meta open-sourced its Katran load balancer in 2018).
  2. A web server running Hack on HHVM starts building your feed.
  3. It calls many microservices, for example ranking, ads and notifications, which run as containers on Twine.
  4. Graph data such as who your friends are, who liked the photo and the comments comes from TAO, a cache that sits in front of MySQL.
  5. Other hot data comes from Memcache.
  6. The photo file comes from Meta's BLOB storage and edge caches close to you.
  7. Your phone shows the post with likes and comments.

What architecture style does Facebook use?

Facebook's architecture is a mix of one huge web application and thousands of services, all on Meta's private infrastructure.

  1. Today: thousands of microservices on Twine. In 2024, thousands of microservices power Facebook, Instagram and WhatsApp, deployed as Twine jobs across 20+ data centre regions.
  2. Graph-first data model: everything is an object (user, post, photo) or an association (friend of, liked, commented). TAO stores these.
  3. Read-heavy design: people read far more than they write, so huge cache layers (TAO, Memcache) protect the databases.
  4. Replicated MySQL with Raft (2023): Meta moved its MySQL replication to a Raft-based system to make failover safer and faster.
  5. Key-value at scale: ZippyDB is Meta's distributed key-value store; in 2026 Meta added ZGateway, a proxy in front of ZippyDB.

Facebook architecture diagram (public parts)

This diagram shows only what Facebook or its partners have shared publicly. Press Play to follow a request step by step.

Watch the orange dot follow each numbered step.
Facebook architecture from public information (simplified)Meta-owned data centres (20+ regions)Storage and edge deliverySimplified; based on publicly shared information.Userapp or browserMeta edge + LBKatran, ProxygenHack/HHVM + servicescontainers on TwineTAOsocial graph cacheMySQL (MyRocks, Raft)users, posts, linksMemcache + ZippyDBcache, key-valueGorilla + Scubametrics, logsBLOB storage + CDNphotos, videos
  1. You open Facebook and your feed starts loading.
  2. Meta's edge and load balancers pick a nearby data centre.
  3. Hack/HHVM code and microservices build your feed.
  4. Friends, likes and comments come from the TAO graph cache.
  5. On a miss, TAO reads sharded MySQL.
  6. Other hot data comes from Memcache or ZippyDB.
  7. Metrics and logs flow into monitoring systems.
  8. The photo loads from BLOB storage through edge caches.
  9. The post appears on your screen.
Diagram 1: the public parts of Facebook's architecture. Simplified; based only on publicly shared information. Open the diagram as an image (PNG) · WebP

What does Facebook use? Main technologies

LayerWhat Facebook uses (public)What it does in simple words
Web languageHack on HHVMMain web code
ServicesThousands of microservicesFeed, ads, messaging, ranking
ContainersTwineRuns services on millions of machines
Social graphTAO over MySQLObjects and associations
DatabaseMySQL with MyRocks; MySQL Raft (2023)Durable user and graph data
CacheMemcache, TAOFast reads
Key-valueZippyDB (+ ZGateway, 2026)Distributed key-value data
Load balancingKatran (L4), ProxygenSpreads traffic
PhotosHaystack, f4 BLOB storageStores billions of photos

Which cloud provider does Facebook use?

Facebook uses no public cloud for its main app. It runs on Meta-owned data centres.

  1. As of 2024: 20+ data centre regions and millions of machines.
  2. Services run as containers managed by Twine.
  3. The same shared infrastructure also runs Instagram, WhatsApp and Threads.

How it started: Facebook's data systems (2010 to 2019)

  1. Haystack (2010): a photo store built to cut the disk reads needed per photo.
  2. TAO (2013): a geographically distributed graph store; reads served by caches, data kept in sharded MySQL.
  3. Scaling Memcache (2013): Facebook ran Memcache across regions, with leases to stop thundering herds and invalidations to keep caches fresh.
  4. f4 (2014): "warm" BLOB storage for older photos, using erasure coding to save space.
  5. Gorilla (2015): an in-memory time-series database for monitoring.
  6. MyRocks (2017): Facebook moved its user database (UDB) from InnoDB to MyRocks (RocksDB inside MySQL), saving storage.
  7. Katran (2018): open-source layer-4 load balancer.

How does Facebook store data?

  1. MySQL (MyRocks engine) holds durable user and graph data; replication now uses Raft (2023).
  2. TAO caches the social graph in every region.
  3. ZippyDB stores key-value data for many services.
  4. Haystack and f4 store photos and other BLOBs (hot and warm).
  5. Exact current capacity numbers are not publicly shared.

How does Facebook monitor its systems?

  1. Gorilla (2015): in-memory time-series database for metrics.
  2. Scuba: fast in-memory data analysis used for debugging and monitoring.
  3. For the 2026 World Cup, Meta prepared for record traffic spikes and reliability at scale.
  4. Full current alerting setup is not publicly shared.

If we built an app like Facebook on AWS (illustrative)

Please read this first

This section is a learning design by Ravindra Bagale. It is not Facebook's real setup. Facebook runs in Meta's own data centres. We use AWS here because it is what you learn in the AWS course.

Suppose you want to build "GaavConnect", a small social network for your village and college friends. Here is a simple AWS layout.

1. Network: VPC, subnets, route tables, gateways

  1. Create one VPC with CIDR 10.0.0.0/16 in the Mumbai region (ap-south-1).
  2. Use two Availability Zones (A and B), so one AZ failing does not stop the app.
  3. In each AZ make three subnets: public (load balancer, NAT gateway), private app (your code) and private data (databases, cache).
  4. Attach one internet gateway (IGW) to the VPC. Public route table: 0.0.0.0/0 → IGW. This route is what makes a subnet public.
  5. Private app route table: 0.0.0.0/0 → NAT gateway, so servers can download updates but nobody can connect in from the internet.
  6. Private data route table: only the local VPC route. Use VPC endpoints to reach S3, DynamoDB and SQS without going over the internet.

2. Compute: where the code runs

  1. ALB in both public subnets.
  2. API and feed services on EKS in private app subnets.
  3. Workers read SQS for notifications and feed fan-out.
  4. Start with a few services; split more as the team grows.

3. Storage and databases

  1. S3 + CloudFront for photos and videos.
  2. Aurora for users and posts.
  3. DynamoDB for likes and follow edges (a simple graph: partition key = user, sort key = friend).
  4. ElastiCache in front, like Facebook's Memcache and TAO idea.

4. Monitoring

  1. CloudWatch metrics and alarms on errors and latency.
  2. X-Ray traces across services.
  3. CloudWatch Logs Insights to search logs, a small cousin of Scuba.

Request flow diagram

Press Play. The numbered list below the diagram lights up with each step.

Watch the orange dot follow each numbered step.
If we built a Facebook-like app on AWS (illustrative)AWS Region (for example ap-south-1, Mumbai)VPC 10.0.0.0/16Availability Zone AAvailability Zone BPublic subnet 10.0.1.0/24RT: 0.0.0.0/0 → IGWPublic subnet 10.0.2.0/24RT: 0.0.0.0/0 → IGWApp subnet 10.0.11.0/24RT: 0.0.0.0/0 → NATApp subnet 10.0.12.0/24RT: 0.0.0.0/0 → NATData subnet 10.0.21.0/24RT: local onlyData subnet 10.0.22.0/24RT: local onlyvia VPC endpointsIllustrative learning design only. This is NOT the company's real setup.Userphone appRoute 53DNS lookupCloudFrontCDN edge cacheAmazon S3photos, videosIGWApplication Load Balancerspans both AZsNAT gatewayNAT gatewaySocial APIEKS pods (auto scaling)Social APIEKS pods (auto scaling)ElastiCachefeed, sessionsAurorausers, postsElastiCachefeed, sessionsAuroraread replicaSQSnotificationsDynamoDBlikes, followsCloudWatch + X-Raymetrics, logs, traces
  1. You open GaavConnect. Route 53 finds the address.
  2. Photos load from CloudFront.
  3. On a miss CloudFront fetches from S3.
  4. Feed requests enter through the internet gateway.
  5. The ALB picks a healthy pod.
  6. The social API builds your feed.
  7. It reads cached feed data from ElastiCache.
  8. Posts from Aurora; likes and follows from DynamoDB.
  9. "New like" notifications go to SQS.
  10. CloudWatch and X-Ray record everything.
  11. Your feed appears.
Diagram 2: an illustrative AWS design for learning. Facebook does not necessarily run like this; see the sections above for what is publicly known. Open the diagram as an image (PNG) · WebP

Facebook versus our AWS design

PartFacebook (public info)Our AWS design
HostingMeta data centres, 20+ regionsAWS, one region, two AZs
Web tierHack on HHVMAny language on EKS
GraphTAO over MySQLDynamoDB edges + ElastiCache
DatabaseMySQL (MyRocks, Raft)Aurora
CacheMemcache, TAOElastiCache
PhotosHaystack, f4S3 + CloudFront
MonitoringGorilla, ScubaCloudWatch, X-Ray

Quick quiz: check what you learned

  1. Where does Facebook run its main app?

    1. Meta-owned data centres
    2. AWS Mumbai region only
    3. Google Cloud regions
    4. Microsoft Azure regions
    Show answer

    A. Facebook runs on Meta's own data centres.

  2. What is TAO used for?

    1. Encoding videos
    2. Caching the social graph
    3. Load balancing traffic
    4. Writing Hack code
    Show answer

    B. TAO serves objects and associations of the social graph.

  3. Which language runs most of Facebook's web code?

    1. Ruby on Rails
    2. Go with gRPC
    3. Hack on HHVM
    4. Java Spring
    Show answer

    C. Facebook's web code is mainly Hack running on HHVM.

  4. What does Twine manage at Meta?

    1. Photo compression
    2. Ad pricing rules
    3. MySQL schema files
    4. Containers on machines
    Show answer

    D. Twine is Meta's cluster manager for containerized jobs.