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:
- Your request reaches the nearest entry point of Meta's network and its load balancers (Meta open-sourced its Katran load balancer in 2018).
- A web server running Hack on HHVM starts building your feed.
- It calls many microservices, for example ranking, ads and notifications, which run as containers on Twine.
- 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.
- Other hot data comes from Memcache.
- The photo file comes from Meta's BLOB storage and edge caches close to you.
- 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.
- 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.
- Graph-first data model: everything is an object (user, post, photo) or an association (friend of, liked, commented). TAO stores these.
- Read-heavy design: people read far more than they write, so huge cache layers (TAO, Memcache) protect the databases.
- Replicated MySQL with Raft (2023): Meta moved its MySQL replication to a Raft-based system to make failover safer and faster.
- 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.
- You open Facebook and your feed starts loading.
- Meta's edge and load balancers pick a nearby data centre.
- Hack/HHVM code and microservices build your feed.
- Friends, likes and comments come from the TAO graph cache.
- On a miss, TAO reads sharded MySQL.
- Other hot data comes from Memcache or ZippyDB.
- Metrics and logs flow into monitoring systems.
- The photo loads from BLOB storage through edge caches.
- The post appears on your screen.
What does Facebook use? Main technologies
| Layer | What Facebook uses (public) | What it does in simple words |
|---|---|---|
| Web language | Hack on HHVM | Main web code |
| Services | Thousands of microservices | Feed, ads, messaging, ranking |
| Containers | Twine | Runs services on millions of machines |
| Social graph | TAO over MySQL | Objects and associations |
| Database | MySQL with MyRocks; MySQL Raft (2023) | Durable user and graph data |
| Cache | Memcache, TAO | Fast reads |
| Key-value | ZippyDB (+ ZGateway, 2026) | Distributed key-value data |
| Load balancing | Katran (L4), Proxygen | Spreads traffic |
| Photos | Haystack, f4 BLOB storage | Stores 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.
- As of 2024: 20+ data centre regions and millions of machines.
- Services run as containers managed by Twine.
- The same shared infrastructure also runs Instagram, WhatsApp and Threads.
How it started: Facebook's data systems (2010 to 2019)
- Haystack (2010): a photo store built to cut the disk reads needed per photo.
- TAO (2013): a geographically distributed graph store; reads served by caches, data kept in sharded MySQL.
- Scaling Memcache (2013): Facebook ran Memcache across regions, with leases to stop thundering herds and invalidations to keep caches fresh.
- f4 (2014): "warm" BLOB storage for older photos, using erasure coding to save space.
- Gorilla (2015): an in-memory time-series database for monitoring.
- MyRocks (2017): Facebook moved its user database (UDB) from InnoDB to MyRocks (RocksDB inside MySQL), saving storage.
- Katran (2018): open-source layer-4 load balancer.
How does Facebook store data?
- MySQL (MyRocks engine) holds durable user and graph data; replication now uses Raft (2023).
- TAO caches the social graph in every region.
- ZippyDB stores key-value data for many services.
- Haystack and f4 store photos and other BLOBs (hot and warm).
- Exact current capacity numbers are not publicly shared.
How does Facebook monitor its systems?
- Gorilla (2015): in-memory time-series database for metrics.
- Scuba: fast in-memory data analysis used for debugging and monitoring.
- For the 2026 World Cup, Meta prepared for record traffic spikes and reliability at scale.
- 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
- Create one VPC with CIDR
10.0.0.0/16in the Mumbai region (ap-south-1). - Use two Availability Zones (A and B), so one AZ failing does not stop the app.
- In each AZ make three subnets: public (load balancer, NAT gateway), private app (your code) and private data (databases, cache).
- 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. - Private app route table:
0.0.0.0/0 → NAT gateway, so servers can download updates but nobody can connect in from the internet. - 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
- ALB in both public subnets.
- API and feed services on EKS in private app subnets.
- Workers read SQS for notifications and feed fan-out.
- Start with a few services; split more as the team grows.
3. Storage and databases
- S3 + CloudFront for photos and videos.
- Aurora for users and posts.
- DynamoDB for likes and follow edges (a simple graph: partition key = user, sort key = friend).
- ElastiCache in front, like Facebook's Memcache and TAO idea.
4. Monitoring
- CloudWatch metrics and alarms on errors and latency.
- X-Ray traces across services.
- 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.
- You open GaavConnect. Route 53 finds the address.
- Photos load from CloudFront.
- On a miss CloudFront fetches from S3.
- Feed requests enter through the internet gateway.
- The ALB picks a healthy pod.
- The social API builds your feed.
- It reads cached feed data from ElastiCache.
- Posts from Aurora; likes and follows from DynamoDB.
- "New like" notifications go to SQS.
- CloudWatch and X-Ray record everything.
- Your feed appears.
Facebook versus our AWS design
| Part | Facebook (public info) | Our AWS design |
|---|---|---|
| Hosting | Meta data centres, 20+ regions | AWS, one region, two AZs |
| Web tier | Hack on HHVM | Any language on EKS |
| Graph | TAO over MySQL | DynamoDB edges + ElastiCache |
| Database | MySQL (MyRocks, Raft) | Aurora |
| Cache | Memcache, TAO | ElastiCache |
| Photos | Haystack, f4 | S3 + CloudFront |
| Monitoring | Gorilla, Scuba | CloudWatch, X-Ray |
Quick quiz: check what you learned
Where does Facebook run its main app?
- Meta-owned data centres
- AWS Mumbai region only
- Google Cloud regions
- Microsoft Azure regions
Show answer
A. Facebook runs on Meta's own data centres.
What is TAO used for?
- Encoding videos
- Caching the social graph
- Load balancing traffic
- Writing Hack code
Show answer
B. TAO serves objects and associations of the social graph.
Which language runs most of Facebook's web code?
- Ruby on Rails
- Go with gRPC
- Hack on HHVM
- Java Spring
Show answer
C. Facebook's web code is mainly Hack running on HHVM.
What does Twine manage at Meta?
- Photo compression
- Ad pricing rules
- MySQL schema files
- Containers on machines
Show answer
D. Twine is Meta's cluster manager for containerized jobs.
Learn it properly
Build the AWS parts yourself with these free guides and lessons:
- How to create a custom VPC with subnets, internet gateway and route tables
- Public vs private subnet in AWS · 3-tier architecture project on AWS
- How to launch an EC2 instance · Install the CloudWatch agent on EC2
- AWS course: What is a VPC? Default VPC vs custom VPC
- Related architectures: WhatsApp Architecture Explained: Erlang, Encryption, Meta Servers · YouTube Architecture Explained: Google Data Centres, VCU, Vitess · Spotify Architecture Explained: Google Cloud, Kubernetes, Bigtable · Snapchat Architecture Explained: Multicloud on AWS and Google Cloud
- All famous app architectures explained