Skip to main content

Real architecture · Senior

Instagram Explore

Real production architecture. Key points: two towers, early/late stage ranking, ig2vec, and integrity filters.

17 min read · Source: Instagram · Content reviewed on October 23, 2026

Short answer

Real production architecture. Key points: two towers, early/late stage ranking, ig2vec, and integrity filters. Explore is the Instagram surface for discovering photos, videos, and Stories relevant to each person's interests. Meta says that more than half of the Instagram community visits it every month and, in another text, that hundreds of millions of people visit it daily.

01 · CONTEXT AND SCALE

What Explore is and why it is hard

Explore is the Instagram surface for discovering photos, videos, and Stories relevant to each person's interests. Meta says that more than half of the Instagram community visits it every month and, in another text, that hundreds of millions of people visit it daily.

The core challenge is to recommend the most relevant content among billions of options, in real time and at scale, which brings several challenges of ML system design. The Meta AI post describes the result as a 3-part ranking funnel that extracts 65 billion features and makes 90 million model predictions every second.

This case uses two Meta sources: the Meta AI post about Explore and an engineering post on how the system was scaled. The second sums up the idea that runs through the text: smart use of caching and precomputation across the different ranking stages, which allows heavier models to be used at each stage.

02 · CANDIDATE GENERATION

From seed accounts to an eligible inventory

The Meta AI post divides Explore into two main stages: candidate generation (also called sourcing) and ranking.

Generation starts from accounts the person has already interacted with, for example by liking or saving media from an account, to find other accounts of interest; they are called seed accounts. Instead of looking at media by media, the retrieval pipeline focuses on account-level information.

The account embeddings come from ig2vec, a framework similar to word2vec that treats the account IDs the person interacts with as a sequence of words in a sentence. A KNN search then finds accounts topically similar to any account in the embedding, and the version described covers millions of accounts.

The sources are written in IGQL, a domain-specific language optimized for retrieving candidates. Execution is optimized in C++ to reduce latency and compute usage, and each source type is a different IGQL subquery.

  1. The person opens Explore and the service triggers the candidate sources, each one an IGQL subquery.

    Architecture diagram: Explore: account-based candidates and ranking in passes
    CLPerson in the app
    CPExplore service
    CPCandidate sourcessubconsultas
    DBPerson's interactions
    DBSimilar-accounts index
    CPIntegrity filters
    CPDistillation pass
    CPLightweight neural network
    CPDeep neural network
  2. The sources start from the seed accounts: accounts the person has already interacted with.

    Architecture diagram: Explore: account-based candidates and ranking in passes
    CLPerson in the app
    CPExplore service
    CPCandidate sources
    DBPerson's interactionsseed accounts
    DBSimilar-accounts index
    CPIntegrity filters
    CPDistillation pass
    CPLightweight neural network
    CPDeep neural network
  3. The index returns accounts similar to the seed accounts, using nearest-neighbor search over account embeddings.

    Architecture diagram: Explore: account-based candidates and ranking in passes
    CLPerson in the app
    CPExplore service
    CPCandidate sources
    DBPerson's interactions
    DBSimilar-accounts indexsimilar accounts
    CPIntegrity filters
    CPDistillation pass
    CPLightweight neural network
    CPDeep neural network
  4. Before the eligible inventory is formed, filters remove whatever cannot be recommended.

    Architecture diagram: Explore: account-based candidates and ranking in passes
    CLPerson in the app
    CPExplore service
    CPCandidate sources
    DBPerson's interactions
    DBSimilar-accounts index
    CPIntegrity filtersfiltra
    CPDistillation pass
    CPLightweight neural network
    CPDeep neural network
  5. On each ranking request, 500 candidates sampled from the eligible inventory move on to ranking.

    Architecture diagram: Explore: account-based candidates and ranking in passes
    CLPerson in the app
    CPExplore service
    CPCandidate sources
    DBPerson's interactions
    DBSimilar-accounts index
    CPIntegrity filters
    CPDistillation passreceives candidates
    CPLightweight neural network
    CPDeep neural network

Before forming each person's eligible inventory, Meta filters out content it identifies as ineligible; besides blocking content that likely violates policies and misinformation, it uses ML systems to detect and filter content such as spam. On each ranking request, thousands of eligible media items are identified for an average person, of which 500 candidates are sampled and sent to the ranking stage.

03 · RANKING IN PASSES

Distillation, lightweight network and deep network

With 500 candidates available, the Meta AI post uses a three-stage ranking infrastructure to balance ranking relevance and computational efficiency.

  1. The first pass is the distillation model, with minimal features, which keeps 150 of the 500 candidates.

    Architecture diagram: Explore: account-based candidates and ranking in passes
    CLPerson in the app
    CPExplore service
    CPCandidate sources
    DBPerson's interactions
    DBSimilar-accounts index
    CPIntegrity filters
    CPDistillation passdistillation
    CPLightweight neural network
    CPDeep neural network
  2. The second pass is a lightweight neural network with the full set of dense features and picks 50 candidates.

    Architecture diagram: Explore: account-based candidates and ranking in passes
    CLPerson in the app
    CPExplore service
    CPCandidate sources
    DBPerson's interactions
    DBSimilar-accounts index
    CPIntegrity filters
    CPDistillation pass
    CPLightweight neural networklightweight network
    CPDeep neural network
  3. The final pass is a deep neural network with dense and sparse features and picks 25 candidates for the first page.

    Architecture diagram: Explore: account-based candidates and ranking in passes
    CLPerson in the app
    CPExplore service
    CPCandidate sources
    DBPerson's interactions
    DBSimilar-accounts index
    CPIntegrity filters
    CPDistillation pass
    CPLightweight neural network
    CPDeep neural networkdeep network
CriterionFirst passSecond passFinal pass
ModelDistillation that imitates the other passesLightweight neural networkDeep neural network
AtributosMinimalFull set of dense featuresDense and sparse features
Candidates that move on150 of 5005025

The first pass is a super lightweight model that learns to approximate the main ranking models as closely as possible. The inputs and outputs of the more complicated models are logged, and the NDCG ranking loss over the main model's output is the training objective. The described gain is evaluating a larger set of media per request while keeping computational resources under control.

A multi-task, multi-label (MTML) neural network predicts the actions on each media item, which include positive actions such as like and save and also negative actions. The predictions are combined by an arithmetic formula called the value model; if saving matters more than liking, the weight for saving should be higher.

The value model also gets a simple diversity rule: posts from the same author or the same seed account are demoted by a penalty factor, which grows as you go down the ranked batch and encounter more posts from the same author.

04 · RETRIEVAL WITH TWO TOWERS

Offline embeddings and approximate search

The engineering post, from August 2023, describes a ranking approach with several well-defined stages, each with its own objectives and algorithms.

In retrieval, the role of a source is to pick hundreds of relevant items out of billions. Sources can be heuristics, such as trending posts, or more sophisticated ML approaches, real-time or pre-generated. Candidates from multiple sources are combined and passed to the ranking models, and those from pre-generated sources can be generated offline during off-peak hours, which contributes to scalability.

The Two Tower model has two separate neural networks, one for the user and one for the item. Each network consumes only features of its own entity and produces an embedding, and the goal is to predict engagement events (such as liking a post) as a measure of similarity between the user and item embeddings.

Criterionig2vecTwo Tower
Training inputIDs of accounts the person interacts with, treated as words in a sentenceArbitrary user and media or author features
Learning signalPredict accounts the person is likely to interact with in a sessionPredict engagement events as similarity between embeddings

Two Towers extends the Word2Vec algorithm: it accepts arbitrary features and multiple tasks at the same time, for multi-objective retrieval, and keeps the maintainability and real-time nature of Word2Vec.

  1. Outside the online path, the item tower generates item embeddings in an offline pipeline, daily.

    Architecture diagram: Explore: two-tower retrieval and staged ranking
    CLPerson in the app
    CPExplore service
    CPUser tower
    DBUser features
    DBApproximate search (ANN)
    CPItem tower pipelinegenerates offline
    CPLightweight ranker (two towers)
    CHEmbedding cache
    CPHeavy ranker (MTML)
    DBPrecomputed recommendations
    CPOff-peak precomputation
    CPFinal reranking
  2. The generated embeddings go to an approximate nearest-neighbor search service, which avoids scanning all items.

    Architecture diagram: Explore: two-tower retrieval and staged ranking
    CLPerson in the app
    CPExplore service
    CPUser tower
    DBUser features
    DBApproximate search (ANN)item embeddings
    CPItem tower pipeline
    CPLightweight ranker (two towers)
    CHEmbedding cache
    CPHeavy ranker (MTML)
    DBPrecomputed recommendations
    CPOff-peak precomputation
    CPFinal reranking
  3. At request time, the user tower fetches the freshest features and generates the person's embedding on the fly.

    Architecture diagram: Explore: two-tower retrieval and staged ranking
    CLPerson in the app
    CPExplore service
    CPUser towerembedding on the fly
    DBUser featuresfresh features
    DBApproximate search (ANN)
    CPItem tower pipeline
    CPLightweight ranker (two towers)
    CHEmbedding cache
    CPHeavy ranker (MTML)
    DBPrecomputed recommendations
    CPOff-peak precomputation
    CPFinal reranking
  4. That embedding queries the approximate search service, which returns the most similar items as candidates.

    Architecture diagram: Explore: two-tower retrieval and staged ranking
    CLPerson in the app
    CPExplore service
    CPUser tower
    DBUser features
    DBApproximate search (ANN)nearby items
    CPItem tower pipeline
    CPLightweight ranker (two towers)
    CHEmbedding cache
    CPHeavy ranker (MTML)
    DBPrecomputed recommendations
    CPOff-peak precomputation
    CPFinal reranking

There is a cost: the model cannot consume user-item interaction features, because it would lose the ability to provide user and item embeddings that can be cached. The main advantage is that these embeddings can be stored in cache, which makes Two Tower inference extremely efficient.

It is also possible to use item embeddings to look up items similar to those in the person's interaction history, which gives more control over the trade-off between types of engagement. In that case, a rule-based approach filters low-quality items out of that history.

05 · RANKING AND RERANKING

Two stages, value model and final rules

Explore uses two ranking stages. The first is a lightweight model, less accurate and less costly, which can retrieve thousands of candidates. The second is a heavy model, more accurate and compute-intensive, which operates on the top 100 candidates from the first. With two stages, more candidates are ranked while keeping the quality of the final recommendations.

In the first stage, Two Tower is used again, because of cacheability. The architecture can be similar to the one in retrieval, but the learning objective differs quite a bit: the first-stage ranker is trained to predict the output of the second, a form of distilling knowledge from a larger model into a smaller one.

  1. The first stage uses a lightweight two-tower model, which reuses cached embeddings.

    Architecture diagram: Explore: two-tower retrieval and staged ranking
    CLPerson in the app
    CPExplore service
    CPUser tower
    DBUser features
    DBApproximate search (ANN)
    CPItem tower pipeline
    CPLightweight ranker (two towers)lightweight model
    CHEmbedding cacheembeddings
    CPHeavy ranker (MTML)
    DBPrecomputed recommendations
    CPOff-peak precomputation
    CPFinal reranking
  2. The second stage receives only the top 100 candidates from the first.

    Architecture diagram: Explore: two-tower retrieval and staged ranking
    CLPerson in the app
    CPExplore service
    CPUser tower
    DBUser features
    DBApproximate search (ANN)
    CPItem tower pipeline
    CPLightweight ranker (two towers)
    CHEmbedding cache
    CPHeavy ranker (MTML)heavy model
    DBPrecomputed recommendations
    CPOff-peak precomputation
    CPFinal reranking
  3. The heavy model consumes the most powerful user-item interaction features.

    Architecture diagram: Explore: two-tower retrieval and staged ranking
    CLPerson in the app
    CPExplore service
    CPUser tower
    DBUser features
    DBApproximate search (ANN)
    CPItem tower pipeline
    CPLightweight ranker (two towers)
    CHEmbedding cache
    CPHeavy ranker (MTML)interaction features
    DBPrecomputed recommendations
    CPOff-peak precomputation
    CPFinal reranking
  4. To ease the peak, part of the recommendations is precomputed off-peak and stored.

    Architecture diagram: Explore: two-tower retrieval and staged ranking
    CLPerson in the app
    CPExplore service
    CPUser tower
    DBUser features
    DBApproximate search (ANN)
    CPItem tower pipeline
    CPLightweight ranker (two towers)
    CHEmbedding cache
    CPHeavy ranker (MTML)
    DBPrecomputed recommendationsready-made lists
    CPOff-peak precomputationoff-peak
    CPFinal reranking
  5. In the final reranking, integrity and diversity rules adjust the ordered list.

    Architecture diagram: Explore: two-tower retrieval and staged ranking
    CLPerson in the app
    CPExplore service
    CPUser tower
    DBUser features
    DBApproximate search (ANN)
    CPItem tower pipeline
    CPLightweight ranker (two towers)
    CHEmbedding cache
    CPHeavy ranker (MTML)
    DBPrecomputed recommendations
    CPOff-peak precomputation
    CPFinal rerankingintegrity and diversity

The second stage predicts the probability of engagement events with an MTML model, much heavier than Two Towers, but able to consume the most powerful user-item interaction features. Applying such a heavy model at peak time can be complicated, and so the recommendations for some users are precomputed off-peak, which helps ensure availability for every Explore user.

The predicted probabilities are combined with weights in a formula called the value model (VM), the approximation of the value each media item brings to the user. Tuning the VM weights explores trade-offs between online engagement metrics.

In the final reranking, returning items ordered only by the VM score may not be a good idea: items may be filtered or demoted based on integrity scores, and business rules may reorder to increase diversity, for example to avoid showing items from the same author in sequence. These rules give much more control over the final recommendations.

The models can be retrained (fine-tuned) every hour as soon as there is new data.

06 · TRADE-OFFS AND TUNING

What changes between versions and how to tune

CriterionMeta AI postEngineering post (2023)
Ranking stagesThree passes: distillation, lightweight network and deep networkTwo stages, with final rule-based reranking
First stageDistillation model, with minimal featuresTwo-tower model trained to predict the output of the second stage
Last prediction stageDeep neural network with dense and sparse featuresMTML model that consumes user-item interaction features

There are hundreds of tunable parameters that control the system's behavior. The engineering post cites two popular tuning approaches: Bayesian optimization and offline tuning.

CriterionOnline Bayesian optimizationOffline tuning
VantagemOnly requires the set of parameters, the objective metric and the regression limits on other metricsSets up the experiment in hours instead of weeks
DesvantagemOften takes a long time to converge, sometimes more than a monthRequires a strong correlation between offline and online metrics

In the engineering write-up, Meta notes that the system's growing complexity brings maintainability and feedback-loop challenges, and that it is investigating consolidating the retrieval strategies into fewer, highly configurable ML algorithms.

Frequently asked questions

What is Instagram Explore?

Real production architecture. Key points: two towers, early/late stage ranking, ig2vec, and integrity filters.

What does the Instagram Explore design cover?

It is organized in these sections: What Explore is and why it is hard, From seed accounts to an eligible inventory, Distillation, lightweight network and deep network, Offline embeddings and approximate search, Two stages, value model and final rules, and What changes between versions and how to tune.

How long is Instagram Explore and what level is it?

It takes about 17 minutes to read and is rated Senior level.

Now design it yourself

Run this case as an interview in the System Design school: you make the decisions, the tutor challenges them and you see how your design scores.