Gbuck12DocsTechnology
Related
Ubuntu 26.04 LTS 'Resolute Raccoon': A Comprehensive Upgrade from 24.04Apple Releases Safari Technology Preview 238 with Critical Security Fix and Major Performance UpgradesMaximize Your Rewards: A Guide to Apple Card’s $100 Co-Owner BonusStack Overflow Co-Founder Warns AI Companies: 'Don't Kill the Goose That Lays the Golden Eggs'10 Key Upgrades Making Windows 11 Faster, Calmer, and More ProductiveKubernetes 1.36 Unleashes Next-Gen Dynamic Resource Allocation: Stable Prioritized Lists, Device Taints, and More6 Key Insights on Modern AI-Assisted Software DevelopmentEverything New in Safari Technology Preview 242: Q&A

Engineering Social Discovery at Scale: Building Friend Bubbles for Billions

Last updated: 2026-05-13 13:36:41 · Technology

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

  • Familiarity with machine learning concepts (e.g., collaborative filtering, embeddings, ranking models).
  • Experience with distributed systems and large-scale data pipelines (e.g., Spark, streaming infrastructure).
  • Knowledge of mobile app development on iOS and Android, including platform-specific APIs (e.g., notification handling, background fetch).
  • Understanding of A/B testing and experimentation at scale.

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:

  • Scale: Billions of users, hundreds of millions of daily Reels views.
  • Freshness: Bubbles should reflect recent friend activity (minutes to hours, not days).
  • Diversity: Avoid showing the same few friends or same viral Reel repeatedly.
  • Privacy: Friends must have opted into sharing their activity (default settings matter).

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:

  • iOS: Users tend to watch Reels in shorter bursts, often triggered by notifications. Background app refresh is limited, so friend activity can lag.
  • Android: Users engage in longer sessions, with more consistent data syncing. However, battery optimization settings vary wildly across OEMs.

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:

  • Precomputed candidate sets: For each user, precompute a list of “most likely interesting friends” based on historical engagement. Update this list every few hours.
  • Online scoring only for top candidates: When the user opens the app, score the top 50 candidates in real-time using a lighter model, then select the top 5 for display.
  • Sharding by friend cluster: Use graph partitioning to serve friend activity from the same region to reduce cross-datacenter latency.
// Example: Sharding logic
function getShardForUser(userId) {
    return hash(userId) % numShards;
}

Common Mistakes

  • Ignoring platform-specific constraints: Failing to account for iOS background refresh limits leads to stale bubbles and poor user experience. Always profile battery and network behavior on both platforms.
  • Over-engineering the ML model initially: Start with simple collaborative filtering; add complexity only after validating with A/B tests. The team learned that a simple model with real-time updates outperformed a complex model with batch inference.
  • Neglecting privacy controls: If friends can opt out, the feature becomes less useful. Design default-on but easy-to-revoke sharing; communicate value clearly in onboarding.
  • Not testing edge cases: What happens when a user has no friends watching Reels? Show popular Reels from the broader network or trending content as fallback. Test at scale with synthetic data.
  • Underestimating cold start: New users have no friend activity history. Use content-based recommendations (e.g., popular Reels in their region) paired with gradual friend discovery.

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.