9 min read

The Billion-User Heartbeat: Inside the High-Concurrency Engine Powering TikTok’s Recommendation Infrastructure

Scaling TikTok’s High-Concurrency Recommendation Infrastructure

The Billion-User Heartbeat: Inside the High-Concurrency Engine Powering TikTok’s Recommendation Infrastructure

You open the app. Within milliseconds, a video plays. It’s exactly what you wanted to see, even if you didn’t know you wanted to see it. You swipe. The next video is even better. This isn’t just “good code”—it is a feat of distributed systems engineering that operates at a scale and velocity that few companies on Earth have ever attempted.

At the heart of ByteDance’s global dominance lies a recommendation engine so responsive it feels sentient. But behind the “For You” page (FYP) isn’t a single “algorithm” in the way the media describes it. Instead, there is a massive, multi-tiered infrastructure known internally and in research circles as Monolith. It is a system designed to handle hundreds of billions of parameters, trillion-edge graphs, and real-time model updates that happen in the span of seconds.

To serve over a billion users with sub-100ms latency, TikTok had to rewrite the playbook on how recommendation systems are built. This is a deep dive into the infrastructure that makes it possible.


The “Secret Sauce” is Actually a Scale Problem

For years, the tech world obsessed over TikTok’s “secret sauce.” Was it a special neural network architecture? A hidden data point? The reality is more impressive: the “secret” is dynamic, real-time consistency at astronomical scale.

Most recommendation systems (like those used by traditional e-commerce sites) use “batch training.” They collect data today, train the model tonight, and deploy it tomorrow. In the world of short-form video, where trends live and die in hours, a model that is 24 hours old is ancient history.

TikTok’s infrastructure solves the Online Learning challenge. Their models learn from your behavior as you are behaving. If you watch a video of a capybara for 3 seconds too long, the weights in the neural network’s embedding layers are updated and synchronized across global data centers almost instantly.

To achieve this, ByteDance engineers had to solve three fundamental problems:

  1. The Sparse Parameter Problem: How do you handle trillions of unique IDs (users, videos, tags) without crashing your memory?
  2. The Latency Bottleneck: How do you perform complex deep learning inference in the time it takes for a user to flick their thumb?
  3. The Training-Serving Consistency: How do you ensure the model being trained on live data is the exact same one serving the next video?

The Architecture: Monolith and the Multi-Stage Funnel

TikTok doesn’t just “pick” a video for you. It filters the entire library of billions of videos through a multi-stage funnel.

1. Candidate Retrieval (The Recall Phase)

When you refresh your feed, the system can’t run a deep neural network on every video in its database—that would take minutes. Instead, the Recall phase uses lightweight algorithms to narrow down the pool from billions to a few thousand candidates.

  • Vector Embeddings: Every user and video is represented as a high-dimensional vector.
  • Approximate Nearest Neighbor (ANN) Search: Using tools like Faiss or custom-built HNSW (Hierarchical Navigable Small World) graphs, the system finds videos whose vectors are geometrically close to your user vector.
  • Collaborative Filtering: “Users who liked X also liked Y.”

2. The Scorer (The Ranking Phase)

This is where the heavy lifting happens. The thousands of candidates are fed into Monolith, a massive deep-learning model. This model predicts the probability of multiple actions:

  • $P(\text{Like})$
  • $P(\text{Complete Watch})$
  • $P(\text{Share})$
  • $P(\text{Retain})$

These probabilities are combined into a final score using Multi-gate Mixture-of-Experts (MMoE), which allows the model to optimize for conflicting goals (e.g., a video might be highly likely to be liked but unlikely to be watched to completion).

3. Re-ranking (The Freshness & Diversity Filter)

The top-scored videos aren’t just dumped on the user. A final pass ensures you don’t see five capybara videos in a row. It applies:

  • Diversity Constraints: Forcing a mix of content types.
  • Exploration (Epsilon-Greedy): Inserting a “wildcard” video to see if your interests have shifted.
  • Feedback Loops: Removing videos you’ve already seen or skipped.

Deep Dive: How Monolith Handles Trillion-Entry Embedding Tables

In standard machine learning, features are often dense (like the pixels in an image). In recommendations, features are sparse. A “User ID” or a “Video ID” is a categorical feature with billions of possible values.

The industry standard was to use Parameter Servers (PS), but TikTok found they couldn’t scale. If you use a static hash table for embeddings, you run into collisions (two different users being treated as the same) and memory bloat (storing IDs of users who haven’t logged in for years).

Collision-less Hash Tables

TikTok’s Monolith uses a dynamic, collision-less hash table. Instead of pre-allocating a massive matrix, it allocates memory for embeddings on the fly.

  • Expiring Embeddings: Monolith implements a “Time-to-Live” (TTL) for features. If a video hasn’t been watched in a month, its embedding is evicted from the high-speed cache to save RAM.
  • Cuckoo Hashing: They utilize advanced hashing techniques to ensure that even with a billion users, the lookup time remains $O(1)$.

The Sparse/Dense Split

Monolith splits the model into two parts:

  1. The Sparse Part: Huge embedding tables stored across a distributed Parameter Server cluster.
  2. The Dense Part: A deep neural network (MLP) that processes the output of the embeddings, usually stored on GPUs.

By using RDMA (Remote Direct Memory Access), the GPU clusters can pull embedding weights from the Parameter Servers with near-zero CPU intervention, slashing network latency by orders of magnitude.


The “magic” of the algorithm is its responsiveness. This is powered by a massive stream-processing pipeline.

Every action you take—a pause, a double tap, a fast-forward—is an event emitted to Apache Kafka. From there, Apache Flink jobs process these streams in real-time to update your “user state.”

# Conceptual representation of a real-time feature update
def process_user_event(event):
    user_id = event.user_id
    video_metadata = feature_store.get_video_features(event.video_id)

    # Calculate real-time aggregate: e.g., "How many cat videos in the last 10 mins?"
    current_state = state_manager.get_user_state(user_id)
    updated_state = sliding_window_aggregator(current_state, video_metadata)

    # Push back to the Online Feature Store (e.g., Redis or ByteDance's custom KV store)
    feature_store.update_user_features(user_id, updated_state)

The engineering feat here is the Streaming Join. The system must join the “User Action Stream” with the “Video Metadata Stream” and the “Contextual Stream” (time of day, location, device) to create a feature vector for the model. Doing this at a scale of 100 million events per second requires a highly tuned Flink cluster with massive state checkpoints stored on ultra-fast NVMe SSDs.


Online Training: The Synchronization Nightmare

Most AI models are trained in a “closed-loop.” TikTok uses Online Training, meaning the model is constantly being updated while it is being used.

This creates a “Training-Serving Decoupling” problem. If the training cluster updates a weight, how does the serving cluster (the one showing you videos) get that weight without a restart?

Monolith solves this via a Parameter Synchronization Service.

  1. Worker Nodes pull the latest mini-batch of data from the Kafka stream.
  2. They compute gradients and push updates to the Parameter Server.
  3. The Serving Nodes (the ones responding to your app requests) subscribe to a delta-update stream from the Parameter Server.
  4. Weights are updated in the serving memory in near real-time.

This means if a specific song suddenly goes viral in Indonesia, the global model can incorporate that trend into its weight distribution in under a minute.


Scaling the Compute: GPUs are Not Enough

At TikTok’s scale, hardware becomes a bottleneck. Traditional x86 CPUs are too slow for the embedding lookups, and standard GPUs have limited memory for those multi-terabyte embedding tables.

Tiered Storage for Embeddings

To manage the cost and scale, ByteDance utilizes a tiered memory architecture:

  • L1 (HBM/GPU Memory): The most “active” embeddings (trending videos, active users).
  • L2 (System DRAM): The vast majority of active feature parameters.
  • L3 (NVMe SSD): Cold features (users who haven’t logged in recently).

This tiered approach allows them to run models with 10 Trillion Parameters—orders of magnitude larger than GPT-3—without needing a dedicated power plant for every data center.

The Network is the Computer

When you have thousands of nodes trying to synchronize weights, the network becomes the “bus.” TikTok relies heavily on ByteCollector, a custom-built, high-performance user-mode network stack. By bypassing the Linux kernel’s standard TCP/IP stack and using RDMA over Converged Ethernet (RoCE), they reduce the communication overhead of parameter syncing by 40-60%.


Tackling the “Cold Start” with Curiosity

One of the most impressive technical aspects of TikTok’s infrastructure is how it handles the Cold Start—a brand-new video with zero views.

Most algorithms ignore new content because there is no data. TikTok’s infrastructure is designed to solve this through Automated Creative Evaluation.

  • Content Understanding (The Vision/Audio Stack): The moment a video is uploaded, a separate pipeline of CNNs (Convolutional Neural Networks) and Transformers analyzes the frames, the audio transcripts, and the “vibe” (lighting, tempo, objects).
  • The “Seeding” Mechanism: The infrastructure automatically injects new videos into the “Recall” phase for a small, randomized bucket of users.
  • Exploration vs. Exploitation: The ranking engine uses a Multi-Armed Bandit approach. It “bets” a small amount of traffic on new content. If the engagement rate (normalized for the small sample size) exceeds a threshold, the video is promoted to the next “traffic pool.”

This requires the infrastructure to support multi-tenancy at the model level—running different versions of the ranking logic for different user segments simultaneously.


Why This Matters: The Engineering Philosophy

The technical substance of TikTok’s infrastructure reveals a shift in engineering philosophy. We are moving away from “Static AI” to “Fluid AI.”

The engineering curiousity here is that TikTok doesn’t care about a “perfect” model. They care about a “fast-learning” model. The infrastructure is built to favor low-latency feedback over high-precision batch processing. It treats the entire global user base as a single, living organism, where every tap is a nerve impulse that recalibrates the brain.

Building a system that can handle 1 billion concurrent users, 10 trillion parameters, and sub-100ms end-to-end latency isn’t just about writing a better ranking function. It’s about building a distributed system that treats data as a river, not a lake.

As we move into the era of Generative AI, the lessons from Monolith—collision-less hashing, RDMA-accelerated parameter syncing, and real-time Flink pipelines—will become the blueprint for any company trying to serve personalized intelligence at the speed of thought.

The “scroll” feels effortless to you, but beneath that thumb-flick is a symphony of thousands of servers, synchronized to the millisecond, all working to answer one question: What will you love next?


More to explore

Keep diving in