# EP 58: How Facebook built its Video Delivery System?
*Facebook unified Reels, Watch, and Live, optimizing ranking, servers, and mobile to deliver personalized, efficient, and fresh video experiences.*
By [Rohit Lakhotia](https://scaleengineer.com/authors/rohit-lakhotia)
Published: 2024-12-23
Canonical: https://scaleengineer.com/blog/how-facebook-built-its-video-delivery-system
---
![](https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/ff79e3ad-93d4-4cc0-8540-6a3b58d70541/Ad_The_AI_report.png?t=1742251228)

### There’s a reason 400,000 professionals read this daily\.

Join [The AI Report](https://magic.beehiiv.com/v1/31a7c576-0eb2-4ef3-abc7-bc75ede786fe?email=%7B%7Bemail%7D%7D&_bhiiv=opp_fc32b6e0-466e-4d7d-a031-b0d41ed35ee3_65769d95&bhcl_id=cb6dd0bc-9f59-4778-a8b6-8482c725cdf5_SUBSCRIBER_ID_%7B%7Bemail_address_id%7D%7D), trusted by 400,000\+ professionals at Google, Microsoft, and OpenAI\. Get daily insights, tools, and strategies to master practical AI skills that drive results\.

[Sign up now for free and work smarter, not harder\.](https://magic.beehiiv.com/v1/31a7c576-0eb2-4ef3-abc7-bc75ede786fe?email=%7B%7Bemail%7D%7D&_bhiiv=opp_fc32b6e0-466e-4d7d-a031-b0d41ed35ee3_65769d95&bhcl_id=cb6dd0bc-9f59-4778-a8b6-8482c725cdf5_SUBSCRIBER_ID_%7B%7Bemail_address_id%7D%7D)

## Facebook Video Delivery

Discover How Facebook built its Video Delivery System\. Inside one of the world’s biggest video delivery systems\!

[Embedded content](https://youtube.com/embed/ycfSTzkcmrM)

Facebook delivers **billions **of videos daily to over **2\.9 billion users worldwide**\. It’s just a matter of few seconds for us but delivering videos isn’t as simple as pressing the **“upload”** button\. With over** **billions of monthly active users, Facebook faces challenges that most platforms can only imagine\. Let's discover in this blog, how Facebook manages it all\.

Before moving further let’s first understand,

## Why is video so Important?

Not just talking about Meta's growth and the three billion users on its platform but also about the world at large\.

Did you know that **92% **of Internet users worldwide watch an average of **19 hours** a week of videos?

I don't know about you, but I personally find myself watching a lot of videos pretty much daily\. Videos on social media are starting to replace search engines\. In 2023, **36% of Gen Z **use social media videos to search for Brands instead of search engines\.

***For example,***** ***if someone from Gen Z is interested in a cool new restaurant in Bangalore, they'll go to Instagram to learn more instead of a search engine\. *

We can see a lot of **emerging competition** in this space which is another sign of video's importance\. Some of the largest companies in the world have significant investments in video including** YouTube, Netflix, Snapchat, Tik Tok **and more\.

**Now that we have some context on video's importance, let's dive in\!**

## Video Unification at Facebook

**What is Video Unification?**

**Video unification** is the process of merging all separate video platforms like Reels, Watch, and Live into a single, streamlined system\.

Before unification, Facebook’s video ecosystem was so much fragmented, and all these platforms operated independently\. Users couldn’t seamlessly switch between **Reels, Watch, **and **Live\. **Facebook Watch and Reels on Facebook, two similar products that were functioning quite separately, means they couldn’t share improvements between them, leading to a worse experience across the board\.

For instance, what you enjoyed in **Watch **didn’t influence what **Reels **suggested, and vice versa\. Also, **Live videos** were disconnected from the other formats\.

### Goal of Unification

It’s divided into 3 parts, ie: users, creators, and Facebook\.

#### For Users:

- Make users feel more connected to the platform\.
- Improve content recommendations by using combined data from all video interactions through Watch, Reels, and Live\.

#### For Creators:

- Enable creators to reach wider audiences and monetize both short\-form and long\-form content\.

#### For Facebook:

- Reduce duplication in engineering efforts by their teams\.
- Be more ready to respond more quickly to changing trends in the video market\.

### Challenges Facebook Faced During Unification

- **Two Distinct Systems**: Reels and Watch had** separate codebases, features, **and **infrastructure**\. Combining their features into a single platform meant reviewing and integrating hundreds of features and** tens of thousands of lines of code\.**
- Since Facebook has billions of users, even making small changes would take time and precision to implement\.
- **Transition Challenges**: While building and working on the new system, engineers were still improving the old one\.** Deciding when to switch fully **to the unified platform was even more challenging\.
- **High Standards**: Throughout this process of video unification, the engineers at Facebook had to **maintain strong engagement **and **performance metrics** to ensure users continued to love their experience\.

## Mobile and Server Unification

![](https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/7f14cdb8-3ae6-451c-bcca-a590d03583a8/image.png?t=1734813013)

The first step in unification was unifying their** two client and server data models **and two architectures into one, with no changes to the user interface \(UI\)\. It took a year to unify the technical stack across the **server, iOS, and Android **due to the extreme complexity, but it was an important step in setting the stage for further developments\.

![](https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/a81a8cdd-984f-428a-94ff-ffc92bd72222/image.png?t=1734813293)

Major challenges encountered in this process are:

- **Massive User Base**: With billions of users, even tiny changes in how the system works **\(logging, interface, or speed\)** could show up in Facebook’s top\-level performance metrics\.
- **Complex Code**: Each layer i\.e\. **Android, iOS, and server**, had tens of thousands of lines of code, and unifying the systems meant sifting through this code while making sure nothing broke\.
- **Merging Reels and Watch**: Combining the two systems while keeping the best features of both required a detailed review of **hundreds of features** and **thousands of lines of code\.**
- **Layer Interactions**: The different system layers** \(mobile, server, ranking\)** needed to keep working smoothly together, even as Facebook changed the code inside it\.

In case you’re wondering what mobile, server, and ranking are, we’ve got you covered\!

**Ranking \(RecSys\)**: Suggests videos based on user interests and fresh content\. It balances both **short\-term \(what you like now\) **and **long\-term \(your overall preferences\)**, while reducing delays and optimizing speed\.

**Server \(WWW\)**: Acts as the middleman between mobile and ranking systems\. It manages tasks like video recommendations, **content organization, caching, **and **preventing duplicates\.**

**Mobile \(FB4A for Android, FBiOS for iOS\)**: Facebook’s mobile apps deliver an optimized user experience, it uses technologies like **client\-side ranking** to show the most relevant videos instantly, without always needing to contact the server\.

- **Ongoing Updates**: While they worked on unifying Reels and Watch, engineers on the other hand were working to improve the** old systems**\. This meant they had to constantly adapt their new unified system to keep up with those updates\. It’s more like aiming at a moving target\.
- **Right Timing for Team Transition**:
  
    - Moving engineers to the new system too early would **slow down progress **on the old systems and affect their goals\.
    - Moving them too late would add extra work to transfer all the updates and features to the new system\.
- **Maintaining Performance**: Through all these changes, the new system had to meet strict standards for** speed, reliability, **and **user engagement\.**

### Next Steps in the Unification Process

Some more steps were still needed before moving on\.

#### Migrating Watch to Reels UI

The first step was shifting the Watch experience to the Reels interface\. Since** Reels was designed for short videos** and **Watch for longer ones**, Facebook needed many tweaks to make it work for all users\. This process involved hundreds of tests and took a year to complete\.

#### Unifying Ranking for Reels and Watch

Next, they merged ranking systems for Reels and Watch\. This was challenging because both platforms had **different user interfaces*** \(e\.g\., buttons in different spots\)*, which could **confuse recommendation algorithms\.**

They also created a shared content pool with both **short and long videos **and trained machine learning models to recommend the best content, regardless of video length\. This helped Facebook in ensure smooth transitions for users who preferred either short or long\-form videos\.

#### Launching the Unified Video Tab

Finally, after years of hard work and struggle, they introduced a new video tab combining Reels, long\-form videos, and live streams\. It uses the **Reels\-style UI** and unified ranking to provide the best mix of performance, user interface, and recommendations\.

## How Facebook’s video delivery system works

The core principles that Facebook follows for distributing content to its users are:

- **Prioritize fresh content**
  
  *Videos are prioritized based on how recent and relevant they are thus ensuring users see up\-to\-date content that matches their interests\.*

- **Let rating determine the content's order**
  
  *The system relies on ranking algorithms to determine the best order to display videos thus ensuring the most relevant and engaging content appears first\.*

- **Vend as little as possible and only move content from memory to the UI layer when necessary**
  
  *Videos are only loaded \(or “vended”\) when needed, and only the minimum amount required is sent to the user interface\. This keeps the app fast and responsive while saving resources\.*
  
  
- **Make sure the fetching behavior is deterministic**
  
  *The process of fetching videos is designed to be consistent and predictable, avoiding unnecessary delays or surprises in how content is delivered\.*
  
  
- **When consumers express a definite desire for content, provide it\.**
  
  *Videos are shown only when there's a strong indication that the user wants them\. For example, when someone actively engages with the app or signals interest in certain types of videos, the system responds accordingly\.*

### Lifecycle of a Request

![](https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/4d9b1496-7a1e-4afd-8417-fea4fbd818a5/image.png?t=1734815116)

Lifecycle of a network request in the video feed

#### STEP 1: The Mobile App Sends a Request

Each request type has its own trigger, and the mobile client often has a few methods in place that can cause a network request\.

- **Prefetch**: This happens before you even open a video tab, right after the app starts\.
  
  *A prefetch request \(one issued before the surface is visible\) is triggered a short time after app startup\. Prefetch is available only for our tab surface\.*

- **Head Load**: Kicks in when you open the video tab for the first time\.
  
  *A head load \(the initial network request\) is triggered when the user navigates to the surface\.*

- **Tail Load**: This happens when you scroll through videos and need more content\.
  
  *A tail load request \( which includes all the subsequent requests\) is triggered every time the user scrolls, with some caveats\.*

If the app has multiple requests \(like prefetch and head load\), it uses whichever response comes back first\. Scrolling triggers more requests only when there are fewer than four videos loaded in memory\.

#### STEP 2: The Server Gets the Request

When a client request arrives at the server, it passes through several key layers\.

The request goes through these layers:

- **GraphQL Framework**: Handles the structure of the request\.
  
  *Since it’s a GraphQL request, the first of these layers is the GraphQL framework and our GraphQL schema definition of the video data model\.*

- **Video Delivery System**: Pulls video data from sources like feeds, databases, or caches\.
  
  *It is a generalized architecture that can provide video for any Facebook product experience\. This architecture is adaptable enough to accommodate a variety of backing\-data sources, including ****feeds, caches, databases ****like ****TAO, ****and other ****backend systems****\. Therefore, the video delivery stack supports all of them, whether you're viewing the video tab of a profile, browsing a list of videos that use a specific soundtrack or hashtag, or accessing the new video tab\.*

**Key Tasks for the Server**:

- Throttle requests during high traffic or emergencies\.
- Cache ranking results for speed\.
- Collect data needed to determine which videos to show\.
- Track performance and send parameters to ranking\.

#### STEP 3: The Ranking System Chooses Videos

Ranking at Facebook is a graph\-based execution service that orchestrates the entire serving workflow to eventually generate a number of video stories and return them to the web server\.

The ranking system runs a step\-by\-step process to pick videos:

1. Retrieve potential videos using machine learning\.
2. Filter out irrelevant or low\-quality options\.
3. Rank videos based on user preferences and diversity\.

**Advanced Features**:

- **Contextualization**: Shows videos that match the theme of what you’re watching\.
- **Elastic Ranking**: Adjusts ranking queries based on server load to balance performance and quality\.

#### STEP 4: The Server Processes Ranking Results

The ranking system sends the server a list of video IDs and ranking metadata for each one\.

- **Privacy Checks**: Only videos the user is allowed to see are included\.
- **Optimization**: Facebook focuses on reducing the server strain from these steps to save energy and improve efficiency\.

After processing, the server sends back the requested videos to the app\.

#### STEP 5: The mobile client receives a response from the server and displays Videos

When the client receives the network response, the video stories are added to the in\-memory pool\.

**Sorting and Prioritization**:

- Videos are prioritized based on the ranking system’s recommendations and whether the user has seen them\.
- Fresh and relevant content is prioritized\.
- Videos are preloaded in the background so swiping between them feels smooth and uninterrupted\.

## Dynamic Pagination

Now Facebook uses a new system called** “Dynamic Pagination”**\. It helps Facebook serve better content based on individual user behavior\. Curious to know how?

Let’s dive in\!

### Old Way

Previously, regardless of how many or how few videos they saw, everyone received the same set quantity of videos in a **single batch \(referred to as a "page"\)\.** It wasn't the best because:

- **Light users**: They wouldn't require every video that was delivered to them\.
- **Heavy users**: Needed more videos but didn’t get enough in one go\.

![](https://media.beehiiv.com/cdn-cgi/image/fit=scale-down,format=auto,onerror=redirect,quality=80/uploads/asset/file/dae1ba8d-0e6b-4926-8945-48beda7c9728/image.png?t=1734814848)

### New Way

**Using dynamic pagination, Page Size Is Determined by Ranking**

- Based on your viewing preferences, the algorithm determines how many videos you will receive\.
- You will receive a larger batch of films if you visit the site frequently\.
- A smaller batch will be sent to you if you're new or don't watch much in order to prevent you from becoming overwhelmed\.

*Ensures that even if ranking sends a large batch, your device only gets what it can handle efficiently\.*

## Real\-time Ranking

**What is Real\-Time Ranking?**

Real\-time ranking adjusts video content ranking based on user interactions and engagement signals, delivering more relevant content as people interact with the platform\.

**How it works**

1. **Collecting Real\-Time Signals**:
  
  Facebook refines recommendations by tracking actions like **how long you watch videos **or** whether you engage with them\. **Signals are collected in two ways:
  
    1. **Asynchronous**: Data is gathered in the background\.
    2. **Synchronous**: Signals are sent with actions, like scrolling to load more videos\.
2. **Adjusting the Ranking**:
  
  These signals help the system adapt quickly to changes in your behavior\. For instance, if you start watching cooking videos, it prioritizes similar content\.
3. **Limits of Real\-Time Signals**:
  
  If your interactions stay consistent between two ranking updates, there’s less room for change\. The system works best when new signals show evolving interests\.

By now, you must have had a clear idea of, **How Facebook built its Video Delivery System\.** In a nutshell, Facebook built its video delivery system by unifying fragmented platforms \(Reels, Watch, Live\) into a streamlined ecosystem, optimizing ranking, server, and mobile layers to deliver personalized, fresh, and efficient video experiences at scale\.

**Congratulations\! You've just advanced another step in your tech journey\. Keep progressing\!**
