Skip to main content
Dilectus
Data & ML Systems · ML system design

Designing a Recommendation System: pipelines, features, training, and serving

Learn how recommendation systems are built end to end: candidate generation, ranking, feature pipelines, model training, online serving, and trade-offs.

AI-generated explainer by Dilectus · · 7 min read

A recommendation system helps a product decide what to show each user next: a video, product, post, song, or job. The hard part is not just predicting what a user might like, but doing it fast, with fresh data, and at a scale where millions of users can get different results in real time.

The core design problem is balancing three things at once: relevance, latency, and freshness. A good recommender usually combines offline training pipelines, online feature retrieval, candidate generation, and a ranking model served under tight latency budgets.

What a recommendation system must do

At a high level, the system needs to answer: “Given this user, what are the best items to show right now?” That sounds simple, but in production it usually means filtering millions of items down to a few hundred candidates, then ranking those candidates with a model.

A typical recommender has these goals:

  1. Personalize results for each user.
  2. Handle scale: large item catalogs and high request volume.
  3. Stay fresh: react to recent clicks, searches, purchases, or skips.
  4. Serve quickly: often within ~50–200 ms end to end, depending on the product.
  5. Measure impact: use offline metrics and online A/B tests.

A useful mental model is a two-stage system:

  • Stage 1: Candidate generation — retrieve a small set of likely items.
  • Stage 2: Ranking — score those items more carefully and sort them.
User request
    |
    v
[User context + recent events]
    |
    v
[Candidate generation]
    |  -> 100s to 1000s of items
    v
[Ranking model]
    |  -> top N items
    v
[Business rules + diversity filters]
    |
    v
[Response to app]

The main building blocks

A production recommender is usually a pipeline of several systems, not one model.

1) Event collection

The system records user behavior: impressions, clicks, watch time, add-to-cart, purchases, skips, dwell time, and searches. These events are the raw material for training and evaluation.

2) Feature pipelines

Features are signals used by the model, such as:

  • user age of account
  • recent categories viewed
  • item popularity in the last hour
  • user-item interaction history
  • embeddings from text, images, or behavior

Some features can be computed offline and stored in a warehouse. Others must be fetched online from a low-latency store.

3) Feature store

A feature store keeps feature definitions consistent between training and serving. This reduces a classic problem called training-serving skew, where the model sees one version of a feature during training and a different version in production.

4) Training pipeline

The training job pulls labeled examples, joins them with features, trains a model, validates it, and registers the model version. This often runs daily or hourly, depending on how quickly user behavior changes.

5) Online serving

The serving layer receives a request, fetches live features, runs candidate retrieval and ranking, and returns recommendations with low latency.

A practical architecture

Here is a common architecture for a large-scale recommender.

          +-------------------+
          |  App / Web / API  |
          +---------+---------+
                    |
                    v
          +-------------------+
          |  Rec request API  |
          +----+---------+----+
               |         |
               |         +----------------------+
               |                                |
               v                                v
   +---------------------+           +----------------------+
   | Online feature store |           | Candidate index      |
   +----------+----------+           +----------+-----------+
              |                                 |
              v                                 v
   +---------------------+           +----------------------+
   | Ranking model       |           | Retrieval models     |
   +----------+----------+           +----------------------+
              |
              v
   +---------------------+
   | Business rules      |
   | diversity / safety  |
   +----------+----------+
              |
              v
          +-------------------+
          |  Ranked items     |
          +-------------------+

Offline side:
Events -> warehouse -> feature jobs -> training set -> model registry

The offline side builds training data. The online side serves the latest features and model. They must be aligned as closely as possible.

Candidate generation vs ranking

These two stages solve different problems.

AspectCandidate generationRanking
GoalFind likely items fastOrder those items accurately
Input sizeLarge catalog, often millions of itemsSmall set, often 100–1000 items
Model complexityUsually simpler and fasterUsually richer and more expensive
LatencyVery lowLow, but can be slightly higher
Common methodsCollaborative filtering, embeddings, ANN searchGradient-boosted trees, deep models, cross features
OutputBroad shortlistFinal top-N list

Why split the system? Because scoring every item with a heavy model is too slow. For example, if a catalog has 10 million items and each score takes only 1 ms, a full scan is impossible in real time. Candidate generation narrows the search space first.

A common pattern is:

  1. Retrieve 500 candidates using nearest-neighbor search over embeddings.
  2. Fetch user and item features.
  3. Rank those 500 items with a more expressive model.
  4. Apply business constraints like deduplication or category caps.

Training data and labels

Recommendation models are only as good as the examples they learn from.

The tricky part is that the system must learn from implicit feedback. Users rarely rate items directly, so the system infers preference from behavior:

  • clicked = weak positive signal
  • purchased = stronger positive signal
  • skipped after impression = negative or neutral signal, depending on context
  • long watch time = positive signal for some products

Example training flow

  1. Log every impression with user, item, position, timestamp, and context.
  2. Join impression logs with later actions, such as clicks or purchases.
  3. Build labels with a time window, for example: “clicked within 24 hours.”
  4. Generate features using only data available before the impression time.
  5. Train and validate the model.

This time-awareness matters a lot. If you accidentally use future data, the model looks great offline but fails in production.

Serving, freshness, and latency trade-offs

Serving a recommender is mostly an exercise in managing trade-offs.

ChoiceBenefitCost
More online featuresBetter personalizationHigher latency and more failure points
Heavier modelBetter accuracySlower inference, more compute
More frequent retrainingBetter freshnessMore pipeline cost and operational complexity
Cached recommendationsVery low latencyCan go stale quickly
Real-time user signalsReacts to latest behaviorHarder engineering and consistency challenges

A common approach is to mix batch, near-real-time, and real-time features:

  • Batch: long-term user preferences, historical popularity
  • Near-real-time: recent clicks in the last hour
  • Real-time: current session actions, page context, device type

For example, a shopping app may update “recently viewed categories” every few minutes, while session clicks are updated instantly. This gives most of the freshness benefit without making every feature a streaming problem.

When to use it (and when not to)

Use a recommendation system when:

  • the catalog is large enough that manual curation does not scale
  • user preferences differ significantly from person to person
  • the product benefits from personalization, discovery, or re-engagement
  • you can log interactions and measure outcomes reliably

Do not start with a complex recommender when:

  • the item set is tiny and static
  • you have little or no interaction data
  • the business goal is simple sorting by popularity or recency
  • you cannot measure whether recommendations help

A practical rule: if you have weak data and a small catalog, begin with rules, popularity, or simple heuristics. Move to ML only when you can clearly define labels, features, and success metrics.

Operational concerns that matter in production

Recommendation systems fail in subtle ways.

Cold start

New users and new items have little history. Common fixes include:

  • use context like location, device, or onboarding preferences
  • fall back to popular or trending items
  • use content-based features for new items

Feedback loops

If you only show popular items, you keep collecting data on popular items and ignore the rest. This can reduce diversity and make the model overly conservative. Diversity rules, exploration, or re-ranking can help.

Monitoring

Track more than just model loss:

  • CTR, conversion rate, watch time, retention
  • latency and error rate
  • feature freshness
  • distribution shifts in user behavior
  • missing features or fallback rates

Safety and business rules

Even a good model can recommend duplicates, unsafe content, out-of-stock items, or items that violate policy. A final rules layer is often necessary.

How this comes up in interviews

Interviewers usually probe whether you can turn a vague product goal into a working system.

They may ask:

  • How would you design recommendations for a news feed, e-commerce site, or video app?
  • How do you handle cold start?
  • How do you reduce latency while keeping recommendations relevant?
  • How do you avoid training-serving skew?
  • What metrics would you use offline and online?

A strong answer usually follows this structure:

  1. Clarify the product goal: click-through, watch time, purchases, or retention.
  2. Define the scale: users, items, QPS, latency target.
  3. Split the system into retrieval and ranking.
  4. Explain data collection, labels, and feature pipelines.
  5. Cover online serving, caching, and fallback behavior.
  6. Mention evaluation, monitoring, and A/B testing.

Good interview answers also include trade-offs. For example, if the interviewer asks whether you would use a deep model, do not answer “yes” or “no” directly. Explain the data, latency budget, and operational complexity that would justify it.

Key takeaways

  • Recommendation systems are usually two-stage: retrieve candidates first, then rank them.
  • The hardest parts are not just modeling, but data freshness, latency, and training-serving consistency.
  • Feature stores help keep offline training and online serving aligned.
  • Implicit feedback and time-aware labeling are central to building good training data.
  • Cold start, feedback loops, and monitoring are production issues, not edge cases.
  • In interviews, clearly explain goals, scale, trade-offs, and evaluation metrics.

Frequently asked questions

Why do recommendation systems usually have both retrieval and ranking?
Because scoring every item with a heavy model is too slow at scale. Retrieval quickly narrows millions of items to a manageable shortlist, and ranking then applies a more accurate model to that shortlist.
What is training-serving skew in a recommender?
It happens when the model sees different feature values or feature logic during training and production. That mismatch can make offline metrics look good while online results degrade, so teams use shared feature definitions and feature stores to reduce it.
How do you build labels for recommendation models if users do not rate items?
Most systems use implicit feedback such as clicks, purchases, skips, dwell time, or watch time. The key is to define labels using only events that happen after an impression, with clear time windows and careful negative sampling.
What is the biggest trade-off in recommendation system design?
Usually it is relevance versus latency versus freshness. More online features and more complex models can improve quality, but they also increase response time, cost, and operational complexity.