← Back to list

How to Design and Scale Facebook Architecture

A plain-English guide to building a social network that serves 3 billion people — for TPMs, Agile leads, and curious engineers.

Muhammad Hassaan Bashir · 2026-05-31 13:26 · 0 claps · 6.5 min read
#design-systems #facebook #system-design-concepts
Open on Medium ↗
Wiki topics: PRD · Product Design 🔒 · Cybersecurity 📋 · Product Management 🏛️ · Architecture

How to Design and Scale Facebook

Architecture

A plain-English guide to building a social network that serves 3 billion people — for TPMs, Agile leads, and curious engineers.

Imagine building a city for 3 billion residents, one where everyone can post a message, see their friends’ updates instantly, and never experience a crash. That is, roughly, what Facebook’s engineering team maintains every single day. This guide walks you through the core architectural decisions behind that achievement, in plain, simple terms.

01 - PRODUCT BACKLOG: Core Requirements & Scope

Functional Requirements: What Must the Product Do?

Before writing a single line of code, a Technical Program Manager (TPM) defines the user stories, specific things real users need to accomplish. For Facebook, the critical ones are: posting text, photos, and videos; adding friends and following pages; scrolling through a personalized news feed; sending messages; and receiving notifications in real time.

Non-Functional Requirements: The Invisible Contract

These are the promises the system makes, but users never see. Availability (the site must be up 99.99% of the time, that’s less than an hour of downtime per year). Latency (your feed must load in under 200 milliseconds). And scale (it must handle billions of users simultaneously without slowing down).

Back-of-the-Envelope: How Big Is the Problem?

These numbers tell engineers what kind of database, servers, and network they need before building anything. It’s like checking how many guests are coming before deciding how big to build the kitchen.

02 — CORE INFRASTRUCTURE: High-Level Architecture

When you tap the Facebook app, a request travels through several layers before you see your news feed. Think of it like ordering at a large restaurant, the waiter (load balancer) takes your order, routes it to the right kitchen station (microservice), which retrieves your food from the pantry (database), and sends it back.

Each microservice handles one specific job. Instead of one giant kitchen doing everything, Facebook has a separate team (service) for your news feed, another for authentication, and another for the social graph. This is why you can still post photos even if the chat feature has a problem; they’re independent.

03 — DATA MODELING: Managing the Social Graph

A social network is, at its core, a graph. You are a node. Your friends are nodes. The “friend” relationship between you is an edge. Facebook has roughly 1 trillion such edges to manage.

KEY CONCEPT: WHAT IS A GRAPH DATABASE? A graph database stores data as interconnected points, like a subway map. Traditional databases store rows in a table(like a spreadsheet). For “find all friends of friends of Alice who live in Lahore,” a graph database is 1,000× faster than a regular one.

Facebook built a custom system called TAO (The Associations and Objects) specifically for this problem. It stores billions of user-relationship pairs and answers queries like “does Alice follow Bob?” in microseconds.

04 — FAN-OUT ARCHITECTURE: Designing the News Feed

The news feed is Facebook’s hardest engineering problem. When Cristiano Ronaldo posts a photo, 600 million followers need to potentially see it. That’s the fan-out problem — one event spreading to millions of people.

“When a regular user posts, we push the update to all their friends’ feeds immediately. When a celebrity posts, we wait and pull the update on demand — otherwise we’d crash our own servers.”

The clever insight: Facebook detects whether you have more than ~10,000 followers. If so, your posts aren’t pre-pushed to anyone’s feed cache. Instead, your posts sit in a shared location, and followers fetch them when they open the app.

05 — PERFORMANCE LAYER: Distributed Caching & Storage

Hitting a database for every single request would be like consulting the library’s original archive every time someone asks a common question. Caches are the answer — fast, temporary storage for frequently needed data. Facebook runs the world’s largest Memcached cluster — tens of thousands of servers holding hot data in RAM. Your profile photo, your friend list, your recent posts: all cached. When you load your feed, 95% of the data comes from cache, not the database. That’s what keeps load time under 200ms.

KEY CHALLENGE: THE THUNDERING HERD When a cache entry expires, thousands of servers simultaneously try to rebuild it from the database — causing a traffic spike. Facebook’s solution: only one server rebuilds the cache; the rest wait and use the stale data for a moment. Problem solved.

For persistent storage, Facebook uses database sharding, splitting the database horizontally across thousands of machines. User ID 1–1M goes to Shard A; 1M–2M goes to Shard B, and so on. Each shard also has read replicas: copies that serve read requests, so the main database only handles writes.

06 — REAL-TIME SYSTEMS: Notifications & Live Engagement

When someone likes your photo, you receive a notification within seconds. This requires a persistent connection between your phone and Facebook’s servers — the phone can’t keep asking “any updates?” every second (that would drain your battery and flood Facebook’s servers).

The solution is WebSockets, a permanent open channel between your app and Facebook’s servers. When you’re tagged in a photo, the event enters a Kafka message queue, which fans it out to the notification service, which immediately sends a message down your WebSocket channel. No polling needed.

07 — PRODUCT EVOLUTION: A/B Testing & Continuous Deployment

Facebook deploys code changes multiple times per day to 3 billion users. How do they do this without breaking things? Through a practice called decoupling deployment from release — meaning the new code is shipped to servers long before users ever see it.

Feature Flags (Gatekeeper System)

A feature flag is simply an on/off switch in the code. Engineers can deploy a new button, but keep its flag set to” off” for everyone. Then they slowly open it: first to 1% of users, then 5%, then 25%, watching metrics at each stage. If something goes wrong, one configuration change rolls it back instantly — no need to redeploy code.

A/B Testing at Scale When Facebook tests a new feed ranking algorithm, they split users into two groups: Group A sees the old algorithm, Group B sees the new one. After a statistically significant period, engineers compare key metrics — time spent, clicks, comments, and ad revenue. The winner gets rolled out to everyone. This is how every small change in your experience is validated before it’s permanent.

AGILE BEST PRACTICE: Feature flags make A/B testing an Agile superpower. Teams can merge code to the main branch daily (continuous integration) without waiting for a “big release” — features just sit behind flags until they’re ready. This eliminates the risk of large, infrequent deployments.

08 — RELIABILITY ENGINEERING: Resilience, Monitoring & Disaster Recovery

In October 2021, Facebook went offline for six hours. It lost an estimated $60 million in revenue and shook user confidence. Resilient system design exists precisely to prevent this — and to recover faster when it inevitably happens again.

Circuit Breaker Pattern Imagine a service that’s struggling — maybe the database is slow. Instead of letting every request pile up and fail, a circuit breaker “trips open” just like an electrical breaker in your home. Requests to the broken service are immediately rejected (with a graceful fallback), preventing a cascade of failures spreading to healthy parts of the system.

Multi-Region Active-Active Failover Facebook runs identical, fully operational data centers on multiple continents simultaneously — not one primary and one backup. This is called active-active. If a region fails, users are rerouted to the nearest healthy one in seconds, not minutes. Data replicates asynchronously between regions, so each is always roughly up-to-date.

Observability: Knowing Before Users Do The trio of metrics, logs, and distributed traces gives engineers eyes into the entire system. Metrics tell you that latency spiked at 2:14 AM. Logs tell you which server logged the first error. Distributed traces — like following a single request through 20 microservices — tell you exactly which call broke down and why. Facebook’s internal tools (Scuba, Logview, Canopy) process millions of events per second to surface these insights in near-real time.

“The goal isn’t to build a system that never fails. It’s to build a system that fails gracefully, recovers automatically, and is always observable.”

The Bottom Line

Building at Facebook’s scale is not about using any single clever technology. It’s about making hundreds of deliberate architectural decisions — each one trading off simplicity for scale, consistency for speed, or cost for reliability. The eight epics above represent those tradeoffs made explicit. Whether you’re a TPM scoping a project, an Agile lead planning sprints, or an engineer choosing a database, the mental models here apply at any scale: from a ten-user prototype to a three-billion-user platform.


메타데이터
post_id
575ec52c19cd
slug
how-to-design-and-scale-facebook-architecture-575ec52c19cd
url
https://medium.com/@eeng.hassaan/how-to-design-and-scale-facebook-architecture-575ec52c19cd
canonical_url
https://medium.com/@eeng.hassaan/how-to-design-and-scale-facebook-architecture-575ec52c19cd
author_url
https://medium.com/@eeng.hassaan
status
ok
fetched_at
2026-06-09 15:37:30