Engineering Social Discovery at Scale: Building Friend Bubbles for Billions

By ✦ min read

Overview

At first glance, the Friend Bubbles feature on Facebook Reels appears simple: it highlights Reels that your friends have watched and reacted to. But beneath that straightforward interface lies a complex engineering challenge—delivering personalized, real-time social discovery to billions of users across iOS and Android. This tutorial distills the key engineering decisions behind Friend Bubbles, based on insights from the Meta Tech Podcast episode where engineers Subasree and Joseph shared their journey. You’ll learn how to design a scalable ML pipeline, handle cross-platform behavioral differences, and navigate the surprising discovery that finally made the feature click.

Engineering Social Discovery at Scale: Building Friend Bubbles for Billions
Source: engineering.fb.com

Prerequisites

Step-by-Step Instructions

1. Defining the Problem and Constraints

Before writing any code, crystallize the core user need: “Show me Reels my friends are watching and interacting with.” This implies real-time aggregation of watch events and reaction signals from a user’s social graph. Key constraints:

2. Designing the Machine Learning Model

The ML model evolved through several iterations. Start with a baseline:

  1. Collaborative Filtering: Use past watch/engagement patterns to predict which Reels a user’s friends are likely to have watched. Represent users and Reels as embeddings, then compute similarity scores.
  2. Add Recency Signals: Boost embeddings with temporal decay—older interactions lose influence.
  3. Incorporate Social Graph Features: Direct friends get higher priority than friends-of-friends. Use graph convolutional networks to capture multi-hop relationships.

Later iterations introduced a multi-task learning objective: predict not only watch probability but also engagement type (like, comment, share). This improved ranking diversity. The final model used a two-tower architecture (user tower, friend-tower) trained on billions of implicit feedback signals.

3. Handling iOS vs. Android Behavioral Differences

During testing, the team noticed stark differences between platforms:

To address this, the team implemented platform-adaptive caching:

// Pseudocode for platform-aware cache TTL
if (platform == iOS) {
    cacheTTL = 30 minutes; // shorter to compensate for delayed pushes
} else {
    cacheTTL = 15 minutes; // Android syncs more frequently
}

They also tuned notification strategies—iOS gets more proactive “friend watched” notifications; Android relies more on in-feed bubbles.

4. The Surprising Discovery: Social Proof Timing

The breakthrough came when engineers realized that showing a friend’s reaction immediately after they watch (synchronous timing) significantly improved engagement. Initially, the system batched friend activity and updated bubbles every 15 minutes. But user testing revealed that real-time updates (within seconds) led to a 40% increase in click-through rates. This required re-architecting the event pipeline:

  1. Stream watch events via Kafka with sub-second latency.
  2. Apply ML inference on the stream (using lightweight models deployed on edge servers).
  3. Push updates to the client via WebSocket or push notification — but only if the friend’s activity passes a quality filter (e.g., not spam, not a repeat).

The team later added a feedback loop: if a bubble appeared but the user didn’t engage, the system would increase the threshold for showing that friend’s next watch.

Engineering Social Discovery at Scale: Building Friend Bubbles for Billions
Source: engineering.fb.com

5. Scaling the Infrastructure

With billions of users, the compute cost of re-ranking bubbles for every user every few seconds is prohibitive. Solutions:

// Example: Sharding logic
function getShardForUser(userId) {
    return hash(userId) % numShards;
}

Common Mistakes

Summary

Building a social discovery feature like Friend Bubbles requires careful orchestration of machine learning, distributed systems, and cross-platform engineering. Start with a clear problem definition, iterate on your ML model from simple to sophisticated, and pay close attention to platform-specific behaviors. The key insight—real-time synchronicity of social proof—transformed the feature from a “nice-to-have” to a core engagement driver. Scale by precomputing candidates and using online scoring only for top results. Avoid common pitfalls like ignoring platform constraints and over-engineering early. With these principles, you can deliver a social experience that feels both magical and reliable to billions.

Tags:

Recommended

Discover More

Minimizing Token Costs in GitHub Agentic Workflows: A Practical Optimization GuideHow to Adapt to the New GitHub Copilot Individual Plan LimitsOrbital Data Centers: A Practical Guide to Overcoming the Rocket Shortage10 Essential Facts About Sony’s New Digital Game License Policy on PS4 and PS5Apple Unveils Radical Siri Overhaul in iOS 27: Full Chat Interface, Dedicated App, and Third-Party AI Integration