Production Architecture for a Scalable Recommendation System
- pranavsankar
- 2 hours ago
- 25 min read

A recommendation model can look impressive in a notebook and still fail the first production review. It may assume the full catalog fits in memory, use features calculated after the prediction time, rank items the user cannot access, rebuild once per day while inventory changes every minute, and measure clicks without recording what was actually shown.
The difficult part is not choosing one algorithm. It is designing a decision system that can consistently transform a changing catalog, evolving user intent, business constraints, and biased feedback into useful recommendations within a strict latency and availability budget.
A scalable architecture usually needs several algorithmic roles:
collaborative filtering to capture co-behavior relationships;
content representations to understand new or sparse items;
two-tower models and vector indexes to search very large catalogs;
lightweight pre-ranking to control cost;
learning-to-rank to order a production candidate pool;
reranking to enforce list-level diversity and policy; and
exploration to learn about users and inventory the existing system rarely exposes.
Around those models sit event contracts, streaming and batch pipelines, catalog services, feature computation, indexes, model deployment, online experimentation, security, observability, fallbacks, and ownership.
Architecture verdict: treat recommendation as a multi-stage platform with four coordinated planes online serving, data and features, learning and experimentation, and governance/control. Keep candidate generation broad, ranking contextual, policy deterministic, and feedback observable. Scale each stage independently, version every decision dependency, and design degraded modes before the personalized path becomes business-critical.
Executive Architecture Blueprint
At request time, a production recommender should answer five questions:
What is eligible? Resolve tenant, entitlement, geography, inventory, lifecycle, and safety boundaries.
What might be relevant? Retrieve candidates from complementary sources.
What is best now? Score the candidate pool with user, item, context, and cross-features.
What should the final list look like? Apply deduplication, diversity, quotas, layout, and hard policies.
What happened afterward? Record delivery, exposure, examination, actions, and negative outcomes.
The system loop is:
catalog + user/session context + policy
|
v
eligibility and request routing
|
v
multi-source candidate generation
|
v
merge, deduplicate, pre-rank
|
v
feature hydration and full ranking
|
v
calibration, constraints, reranking
|
v
delivery and exposure logging
|
v
evaluation, experimentation, learning
|
+------> new artifacts and policies
Google’s published YouTube recommendation architecture describes the fundamental two-stage split between candidate generation and ranking. Enterprise systems commonly add routing, pre-ranking, objective composition, slate construction, and explicit policy stages around that core.
The four planes
Plane | Primary responsibility | Critical artifacts |
online serving | produce a safe recommendation within latency | request context, candidate pool, features, scores, slate, fallback |
data and features | represent catalog, events, profiles, and point-in-time state | event schemas, catalog contract, aggregates, embeddings, indexes |
learning and experimentation | train, validate, deploy, and causally evaluate changes | datasets, models, policies, experiments, metrics, lineage |
governance and control | authorize, configure, audit, observe, and recover | access policy, SLOs, versions, approvals, alerts, runbooks |
The planes should share contracts but not become one tightly coupled deployment. Catalog ingestion can scale independently from online ranking. A candidate index can refresh without rebuilding every user feature. A policy change can be promoted without retraining the model. This separation reduces blast radius and iteration time.
Define the Product Decision Before the Technology
The phrase “recommend items” hides materially different decisions:
select six substitutes for an unavailable industrial part;
order a home feed of videos;
choose next-best actions for account managers;
recommend jobs to candidates;
rank courses for a learner’s current skill goal;
assemble a cross-sell module at checkout; or
identify documents an employee is authorized to access.
Each requires a different surface, horizon, feedback signal, latency, safety policy, and level of personalization.
Write a decision contract:
For principal P, in context C, choose an ordered slate of K eligible items from corpus I, optimizing O within latency L and guardrails G, using only information available before time T.
An example:
For an authenticated procurement user viewing an out-of-stock pump, return eight in-region substitutes from approved suppliers, preserving voltage and connection compatibility, optimizing expected qualified purchase and delivery confidence, with p95 under 180 milliseconds and no cross-account inventory exposure.
That contract determines whether you need semantic similarity, compatibility rules, collaborative signals, two-tower retrieval, a ranker, or merely a database query. It also makes architectural reviews concrete.
Convert Business Requirements Into System SLOs
Functional requirements
recommendation surfaces and response sizes;
anonymous, authenticated, household, or account personalization;
catalog eligibility and policy boundaries;
new-user and new-item behavior;
required explanations or reason codes;
negative feedback and user controls;
experimentation and editorial override; and
data deletion, regional, and audit requirements.
Non-functional requirements
Requirement | Example target | Design implication |
endpoint latency | p95 under 150 ms; p99 under 300 ms | limits feature fan-out and ranker cost |
availability | 99.95% monthly | requires fallback, timeouts, isolation, and capacity headroom |
traffic | 25,000 peak requests/second | requires partitioning, batching, caching, and autoscaling |
catalog size | 75 million active items | favors factorized retrieval and ANN indexing |
freshness | session events under 30 seconds; new items under 10 minutes | requires streaming or incremental paths |
data correctness | zero unauthorized final results | policy must be deterministic and tested |
model freshness | approved model deployed within one hour | requires automated validation and staged promotion |
observability | decision trace for every displayed item | requires versioned, privacy-aware logging |
recovery | RTO 15 minutes; RPO appropriate to event and catalog stores | drives replication and rebuild strategy |
cost | bounded cost per 1,000 recommendation requests | makes candidate and feature budgets explicit |
Avoid a single “real-time” requirement. Break freshness down by state:
current request context: milliseconds;
session profile: seconds;
inventory and eligibility: seconds to minutes;
item embeddings: minutes;
collaborative relationships: minutes to hours;
ranking model: hours to days; and
long-term user aggregates: hours.
Each state can use a different update mechanism.
Reference Architecture: From Events to Final Slate
1. Edge, authentication, and request routing
The recommendation API receives the principal, surface, request ID, device or channel, locale, current seed or query, and allowed context. It should:
authenticate or assign a bounded anonymous session;
authorize the surface and tenant;
normalize the request;
choose region, model bundle, policy, and experiment treatment;
set a shared deadline; and
attach trace and decision identifiers.
Do not let downstream services independently invent user identity or experiment assignment. Request identity and routing must be consistent across the decision.
2. Eligibility resolver
Eligibility removes items that must not be considered. Typical constraints include:
tenant and account ownership;
geographic market;
inventory and lifecycle;
subscription and entitlement;
age, safety, or regulatory status;
contract and supplier approval;
language or format support; and
prior consumption or explicit blocking.
Some constraints can route to a smaller index. Others become retrieval filters. All must be rechecked before response because upstream metadata can be stale.
3. Candidate orchestration
The orchestrator decides which sources to call, their deadlines, and their budgets. It should support partial success: if a collaborative source times out, content, two-tower, popularity, and editorial sources may still produce a valid pool.
Each source returns a common contract:
{
"request_id": "rec_01K...",
"source": "two_tower_home_v12",
"items": [
{
"item_id": "item_4821",
"source_score": 0.762,
"source_rank": 1,
"reason_code": "behavioral_embedding_match"
}
],
"source_version": "tower-v12-index-20260820-04",
"latency_ms": 17,
"partial": false
}
Raw source scores are not assumed comparable.
4. Candidate merge and deduplication
Merge by canonical item or parent-product identity. Preserve all source memberships, ranks, scores, support, and reason codes as downstream features. Apply source quotas only when justified; a fixed quota can waste ranker capacity if one source is weak for a request.
Remove:
duplicate variants not suitable for separate display;
already consumed items according to surface policy;
blocked or unavailable items;
stale IDs; and
candidates below minimum source confidence, when calibrated.
5. Feature hydration
Fetch user, item, context, and cross-features in batches. Precompute item-only features. Read user/session state once per request where possible. Calculate pairwise features vectorized across the candidate set.
Feature services need:
point-in-time offline definitions;
online freshness and latency SLOs;
schema and unit contracts;
default and missingness behavior;
owner and lineage;
privacy classification; and
load-shedding behavior.
6. Pre-ranking
If the merged pool is too large for the full ranker, a lightweight model reduces it while preserving source and cohort recall. Pre-ranking may use source score, user-item affinity, quality, freshness, and simple cross-features.
Measure which final positives are lost at this stage. A cheap pre-ranker that removes the winners makes the full ranker irrelevant.
7. Full ranking
The full ranker scores the remaining candidates with richer cross-features and objectives. Gradient-boosted learning-to-rank, wide-and-deep models, DLRM-like interaction models, or neural sequence rankers can operate here.
The companion learning-to-rank guide covers LambdaMART, group construction, bias correction, and ranking evaluation.
8. Calibration and objective composition
If the product combines click, purchase, value, retention, quality, or return risk, bring predictions onto interpretable scales before composing utility. Keep hard constraints out of a soft score.
9. Reranking and slate construction
Construct the final list with awareness of interactions among items:
parent and near-duplicate removal;
category, creator, brand, supplier, or topic diversity;
novelty and controlled exploration;
contractual or editorial slots;
sponsored-item policy and disclosure;
page layout requirements;
quality thresholds; and
safety and authorization recheck.
10. Response and decision logging
Return item IDs and user-facing reason codes. Log candidate provenance, versions, scores, policy changes, final positions, response time, and fallback state. Link later impressions and outcomes through the request and item identifiers.
The Online Request Sequence
The request should be deadline-aware rather than waiting indefinitely for every dependency.
client -> recommendation API: request(surface, context)
API -> identity/policy: principal, tenant, experiment
API -> profile store: recent + long-term state
API -> candidate orchestrator: request + eligibility scope
orchestrator -> candidate sources: parallel calls with budgets
candidate sources -> orchestrator: partial candidate sets
orchestrator -> merge/filter: canonical pool
merge/filter -> feature service: batch hydration
feature service -> pre-rank/full rank: feature matrix
ranker -> slate service: scored candidates
slate service -> catalog/policy: final validation
API -> client: recommendations + reason codes
API -> event stream: decision and delivery event
client -> event stream: impression, examination, action
Deadline propagation
Assign each stage a budget within the end-to-end SLO. Downstream calls receive the remaining deadline. Cancel or ignore late work. Avoid independent retries that multiply tail latency.
Example for a 150 ms p95 target:
Stage | Budget |
routing and policy | 8 ms |
profile/context | 12 ms |
parallel candidate retrieval | 35 ms |
merge and eligibility | 8 ms |
feature hydration | 28 ms |
pre-rank and rank | 28 ms |
slate construction | 12 ms |
serialization, network, and reserve | 19 ms |
Budgets are not averages. Measure tail behavior and shared dependency contention.
Candidate Generation Is a Portfolio
No candidate method covers every user, item, and context state. A portfolio improves recall and resilience.
Collaborative filtering
Collaborative filtering uses interaction structure rather than item descriptions. Item-based neighborhoods are often efficient and explainable for “because you viewed X.” User-based methods can model meaningful peer relationships when histories are dense and stable.
Use the detailed guide to user-based versus item-based collaborative filtering for graph construction, similarity, sparsity, and production trade-offs.
Architecture role: offline or nearline neighbor tables; fast online aggregation from recent user items; behavioral coverage for mature inventory.
Failure boundary: new items and short histories; popularity feedback; stale neighborhoods.
Content-based retrieval
Structured metadata, sparse text vectors, dense embeddings, and multimodal representations retrieve items based on their content.
Architecture role: new-item coverage, semantic similarity, catalog search, and explainable attribute relationships.
Failure boundary: metadata quality, overspecialization, semantic-but-incompatible matches, and content manipulation.
The content-based recommendation guide provides the full item-representation and ANN design.
Two-tower retrieval
A query tower embeds the user/session context while a candidate tower embeds each item. Precomputed item vectors support ANN retrieval across very large catalogs.
Architecture role: personalized high-recall retrieval at large scale.
Failure boundary: sampling bias, vector/index compatibility, new-item representation, ANN recall, and multi-interest compression.
See two-tower recommendation models for candidate retrieval for training, negatives, index lifecycle, and evaluation.
Popularity and trending
Contextual popularity is a durable fallback and candidate source. Segment by locale, category, time, surface, and eligibility. Use shrinkage and minimum support.
Failure boundary: head-item concentration and self-reinforcing exposure.
Editorial, contractual, and rules-based sources
Editorial collections, required items, compliance guidance, and contractual inventory sometimes need explicit inclusion. Preserve their provenance and validate eligibility.
Failure boundary: stale lists, overuse, and hidden commercial influence.
Exploration
Exploration deliberately gathers evidence on new or uncertain items and user interests. It must operate inside eligibility, quality, and risk boundaries.
Failure boundary: user harm if exploration is unconstrained; biased learning if no exploration occurs.
The Data Plane: Events, Catalog, Identity, and State
Event taxonomy
At minimum, distinguish:
recommendation decision generated;
item eligible;
item retrieved by source;
item scored;
item removed or moved by policy;
response delivered;
item rendered;
item visible or examined;
user action such as click, save, purchase, completion, hide, or return; and
operational outcome such as timeout or fallback.
A click without an exposure record cannot establish what alternatives the user could have chosen.
Event contract
{
"event_id": "evt_01K...",
"event_time": "2026-08-20T08:41:32.445Z",
"event_type": "recommendation_impression",
"request_id": "rec_01K...",
"principal_key": "pseudo_7bf...",
"tenant_id": "tenant_204",
"surface": "home_recommended",
"item_id": "item_4821",
"position": 3,
"candidate_sources": ["two_tower", "item_cf"],
"model_bundle": "home-rec-v18",
"policy_version": "home-us-v9",
"experiment": {"id": "exp_391", "arm": "treatment"},
"consent_scope": "personalization_allowed"
}
Use event time and ingestion time. Enforce idempotency, schema evolution, source authentication, bot detection, and late-event handling.
Canonical catalog
The catalog must provide:
canonical and variant identity;
taxonomy and content;
supplier or creator ownership;
availability and market state;
entitlement and policy attributes;
lifecycle and deletion timestamps;
source provenance and confidence; and
representation/index status.
The recommendation platform should not reconcile conflicting product IDs inside the online request.
Identity and profile state
Separate durable user identity, account/household identity, anonymous session, and device signals. Do not merge them casually. Profiles may include:
recent session events;
long-term aggregated interests;
negative feedback and exclusions;
seen/consumed history;
exploration state;
declared preferences; and
confidence and freshness.
Profiles are derived personal data. Apply retention, deletion, access, and purpose controls.
Storage by access pattern
Do not choose one database for every recommender workload.
Access pattern | Suitable logical store |
immutable high-volume events | append-only stream and analytical object/table storage |
current catalog and policy | authoritative transactional/catalog store plus serving cache |
recent user/session state | low-latency key-value or profile store |
offline features | point-in-time analytical feature tables |
online features | bounded low-latency feature service/store |
item neighbors | key-value adjacency lists |
content and two-tower vectors | embedding store plus vector/ANN index |
model artifacts | immutable registry/object storage |
experiment assignments | consistent configuration or assignment service |
decision audit | privacy-aware event/log store with retention |
The physical technologies can vary. The contracts and access patterns are the durable architecture.
The Feature Platform and Point-in-Time Correctness
Features connect data to retrieval and ranking. They are also a major source of production incidents.
Feature classes
Class | Examples | Update path |
static item | taxonomy, language, product family | catalog change pipeline |
dynamic item | inventory, price, quality, trends | stream or frequent aggregation |
long-term user | category affinity, price band | scheduled or incremental aggregation |
session | recent clicks, active query, current seed | online or streaming state |
cross | user-category affinity, distance, compatibility | online vectorized computation or cached table |
candidate-source | source score, rank, support | request-scoped from retrievers |
policy | entitlement, blocklist, market | authoritative online lookup/cache |
Offline and online parity
Training features must represent the value known at decision time. Current aggregates joined to historical rows leak the future. Maintain event timestamps, effective-dated dimensions, time-aware windows, and reproducible transformations.
Parity means semantic equivalence, not necessarily one physical store. Validate offline recomputation against shadow online values.
Feature contracts
Every production feature needs:
name and definition;
entity keys;
type and unit;
timestamp semantics;
freshness and latency target;
default and missingness behavior;
owner and source lineage;
privacy classification;
training and online transformations; and
deprecation plan.
Avoid silent defaults. A missing value can be informative, operational failure, or both. Log the cause where possible.
The Learning Plane: Build Reproducible Decision Artifacts
Dataset construction
Build examples from the state available before a decision. Preserve:
request/group ID;
user/session state;
eligible and retrieved candidates;
candidate source and source score;
display and examination opportunity;
item/catalog state;
model, index, feature, and policy version;
outcome and attribution window; and
sampling or propensity probability.
Temporal splits
Train on the past and validate/test on future periods. Add item-cold-start and user-cold-start splits when those are product requirements. Random interaction splits can leak later user and item behavior backward.
Baselines
Keep durable baselines:
eligible popularity;
recent/trending;
item co-occurrence;
structured or lexical content similarity;
simple matrix factorization or pooled embeddings;
two-tower retrieval; and
pointwise boosted ranking.
Architecture complexity must earn incremental value over these baselines.
Artifact graph
A production release is not just model.pkl. It may include:
candidate-generation model;
item vector index or neighbor table;
query model;
pre-ranker and full ranker;
score calibrators;
feature contract;
policy and slate configuration;
category/locale routing table;
fallback configuration; and
evaluation and approval record.
Represent compatibility explicitly. A new query tower cannot serve against an old candidate index just because vector dimensions match.
Automated gates
Before promotion, check:
schema and feature compatibility;
temporal offline metrics;
full-catalog candidate recall;
ANN recall against exact retrieval;
ranking and slate metrics;
new-user, new-item, locale, category, and supplier slices;
data leakage and label maturity;
safety, entitlement, and tenant isolation;
model size, memory, and latency;
missing/default feature behavior;
robustness under dependency failure; and
rollback compatibility.
Model and Index Deployment
Immutable versioned releases
Never mutate a production model or index in place without traceable versioning. Use immutable artifacts and an atomic routing pointer.
Shadow
Run candidate artifacts on live requests without changing user-visible results. Compare candidates, ranks, features, policy effects, latency, and resource use.
Canary
Route a small safe cohort. Verify SLOs, errors, score distributions, candidate coverage, policy actions, and early guardrails.
Experiment
Assign a statistically valid cohort and measure the complete final slate. A model that wins offline may lose online because it changes exposure, latency, or downstream behavior.
Rollback
Rollback must restore a compatible bundle, not merely a model file. Keep stable artifacts warm and verify rollback during normal release exercises.
The underlying discipline is covered in CI/CD for machine learning and continuous training and automated retraining pipelines.
Freshness Architecture
Batch
Batch pipelines are appropriate for stable item relationships, long-term profiles, expensive embeddings, and scheduled model training. They are simpler to reproduce and govern.
Nearline or streaming
Use streaming for session state, trending signals, high-value inventory changes, exposure counts, and rapid item insertion when the business needs it.
Online learning
Online parameter updates can reduce adaptation latency but increase correctness, reproducibility, and rollback risk. The Monolith research describes a production-oriented real-time recommendation system and explicitly examines reliability trade-offs in online learning.
Do not adopt online learning merely to call the system real-time. First ask whether streaming features and more frequent batch retraining meet the outcome.
Hybrid freshness pattern
A common design combines:
daily or weekly model training;
hourly collaborative/table refresh;
minute-level new-item embeddings and index insertion;
second-level session profiles and trends; and
request-time context, inventory, and policy.
Measure source-to-serving lag for each artifact.
Scaling Embeddings and Vector Retrieval
Recommendation workloads can be memory- and bandwidth-heavy because high-cardinality categorical features use large embedding tables. Meta’s DLRM paper discusses recommendation-specific architectures and parallelization across embedding and dense components. Its accompanying systems research highlights why recommendation workloads differ from conventional dense neural inference.
Capacity estimate
Raw item-vector storage is:
Memory
vectors=N×d×bytesPerValueMemoryvectors=N×d×bytesPerValue
For 75 million items at 256 dimensions with 4-byte floats, raw vectors require 76.8 GB before index graphs, quantization tables, item IDs, filters, allocator overhead, replicas, and parallel versions.
Index choices
exact flat search for small filtered corpora and quality reference;
HNSW for strong recall-latency performance with memory trade-offs;
IVF to search selected partitions;
product quantization or lower precision to reduce memory; and
category, tenant, region, or locale partitioning where boundaries are stable.
Measure exact-versus-ANN Recall@K under real filters. Index latency without recall is not a quality metric.
Hot items and embedding tables
Popular IDs create cache and shard hot spots. Use balanced partitioning, hot-key replication, local caches, batching, and capacity tests based on real traffic distributions.
Multiple versions
Capacity planning must include current, shadow, and rollback indexes. A design that fits one index but cannot stage the next version is not deployable safely.
Ranking, Multi-Objective Utility, and Reranking
Rank on context-rich features
Candidate scores capture source-specific evidence. The ranker adds:
request and user state;
item quality and freshness;
user-item cross-features;
source membership and support;
business and risk predictions; and
context such as surface, locale, and session.
Calibrate before composing objectives
Suppose the product considers click, conversion, value, and return risk:
The terms need compatible interpretations. A raw ranking score cannot be safely combined with currency or probability.
Keep policies explicit
Hard constraints must not rely on a model’s learned negative weight. Reranking should expose which rule moved or removed each item.
Optimize the slate
Independent item scores miss redundancy. Final list construction may use category caps, maximal marginal relevance, submodular selection, constrained optimization, or dedicated slate models. Start with transparent rules and measure relevance loss from every constraint.
Industrial ranking work such as Google’s multi-task recommendation research demonstrates the reality of competing objectives and selection bias in large systems.
Feedback Loops, Exploration, and Causal Evaluation
The recommender changes its future data
Ranking determines exposure. Exposure influences interactions. Those interactions train the next model. Without intervention, the system can amplify popularity, narrow user interests, and underlearn new inventory.
Record the entire decision funnel
Distinguish:
eligible
-> retrieved
-> merged
-> ranked
-> policy-adjusted
-> delivered
-> rendered
-> examined
-> acted upon
The distinction supports propensity estimation and diagnoses where opportunity was lost.
Exploration strategy
Exploration can be:
a small randomization inside a safe top set;
uncertainty-aware candidate allocation;
explicit new-item slots;
contextual bandits;
randomized pair swaps; or
source-level traffic allocation.
Log assignment probabilities. Guard quality, safety, tenant, and regulatory boundaries.
Offline evaluation
Use temporal splits and layer metrics:
candidate-source Recall@K and coverage;
exact and ANN retrieval recall;
ranking NDCG, MRR, Precision, and calibration;
final-slate relevance, diversity, novelty, and policy compliance;
cohort performance; and
latency and cost.
Online evaluation
Use A/B tests for causal product evidence. Netflix’s published recommender-system paper describes combining offline experimentation with A/B tests tied to business and member outcomes (ACM).
Predeclare primary metrics, guardrails, randomization unit, duration, power, novelty effects, and rollback conditions.
Observability: Trace One Recommendation End to End
Technical telemetry
request volume, error rate, p50/p95/p99 latency;
stage deadlines, timeouts, retries, and fallbacks;
dependency and cache performance;
candidate counts before and after each stage;
feature latency, freshness, and missingness;
model inference time and resource use;
index age, shard health, and ANN recall; and
policy removals and empty-slate rate.
ML telemetry
input distributions and schema;
embedding norm and centroid;
neighbor and top-KK churn;
source score and source mix;
rank-score distribution;
candidate-to-display survival;
calibration and outcome rates;
catalog, category, supplier, and item-age coverage; and
cold-start and fallback performance.
Decision telemetry
For each displayed item, retain enough privacy-safe data to reconstruct:
request and experiment;
candidate sources and versions;
feature/model bundle;
base and final ranks;
policy actions;
reason code;
delivery and examination; and
subsequent outcome.
Distributed tracing
Use consistent trace and request identifiers across services. The current OpenTelemetry semantic-convention specification provides common conventions for traces, metrics, logs, resources, and related telemetry. Recommendation-specific attributes should be low-cardinality where metrics require it and privacy-reviewed before collection.
Resilience and Graceful Degradation
A recommendation endpoint should remain useful when personalization components fail.
Degradation ladder
full multi-source candidates, online features, personalized ranking, and slate policy;
cached long-term profile if session state fails;
available candidate sources if one retriever times out;
lightweight ranker if full feature hydration fails;
context-specific popularity or editorial inventory;
deterministic eligible defaults; and
omit the module when no safe result exists.
Isolation patterns
timeout and circuit-breaker per candidate source;
bulkheads for expensive surfaces or tenants;
bounded candidate and feature fan-out;
concurrency limits and backpressure;
stale-but-safe cache policies;
load shedding for optional sources;
asynchronous noncritical logging; and
independent health for model, index, and policy bundles.
Never degrade authorization
Fallback can reduce personalization. It must not weaken tenant, safety, entitlement, or legal checks. If policy state is unavailable and cannot be safely cached, fail closed.
Test failure, not only success
Inject slow feature reads, missing shards, corrupt candidates, stale indexes, model-load errors, event-stream outages, and partial regions. Verify user response, logs, alerts, and recovery.
Multi-Region and Disaster-Recovery Design
Regional serving
Keep latency-sensitive profiles, indexes, models, policy caches, and feature stores close to serving traffic. Route requests consistently enough that session state does not oscillate between regions without replication.
State classification
State | Recovery approach |
immutable model artifacts | replicate and verify checksums |
vector indexes and neighbor tables | replicate or rebuild from versioned embeddings/data |
online profiles | replicate according to freshness and privacy requirements |
event log | durable multi-zone stream and downstream replay |
experiment assignments | deterministic hashing or strongly consistent assignment |
policy and entitlement | authoritative replicated service with safe cache/fail-closed semantics |
catalog | authoritative replication plus change-log replay |
RTO and RPO by component
Not all state needs zero data loss. Losing seconds of anonymous session history differs from losing entitlement updates. Define recovery targets per state and test regional failover.
Rebuildability
Indexes, profiles, and features should be reproducible from source events and versioned catalog snapshots where practical. Measure rebuild time; a theoretically rebuildable 80-million-item index that takes three days may violate the recovery objective.
Security, Privacy, and Governance
Threat model
Consider:
cross-tenant data or item leakage;
unauthorized profile access;
catalog poisoning and metadata manipulation;
event spoofing or bot amplification;
inference of sensitive interests from embeddings;
model artifact tampering;
debug-log exposure;
supply-side manipulation of popularity; and
unsafe exploration or fallback.
Defense in depth
authenticate producers and consumers;
authorize every request and final item;
isolate tenants or enforce verified filters;
encrypt events, profiles, features, artifacts, and indexes;
minimize and pseudonymize user data;
sign or checksum artifacts;
validate catalog provenance;
rate-limit and detect abuse;
redact sensitive telemetry;
separate duties for model and policy promotion; and
audit access and final decisions.
Data lifecycle
Define retention and deletion for raw events, derived profiles, feature snapshots, training datasets, embeddings, checkpoints, logs, and backups. A user deletion workflow must propagate beyond the serving database.
Fairness and exposure governance
Recommendations allocate attention among consumers and suppliers. Measure exposure, quality, and outcome by relevant user and item groups. Research on joint multisided exposure fairness illustrates why provider and consumer perspectives can both matter.
Human governance
Document:
intended use and prohibited use;
primary outcome and counter-metrics;
data sources and limitations;
known cold-start and cohort weaknesses
policy owners and escalation;
experiment approval boundaries;
rollback authority; and
review cadence.
Cost and Capacity Planning
Cost centers
event ingestion and long-term storage;
stream and batch computation;
feature materialization and online reads;
embedding-table training;
candidate embedding generation;
ANN memory, replication, and index builds;
model inference;
network fan-out;
decision and exposure logging;
shadow traffic and experiments; and
observability retention.
Unit economics
Track:
cost per 1,000 recommendation requests;
cost per million candidates retrieved;
cost per million candidates ranked;
cost per active user profile;
cost per catalog item represented;
model training and index-build cost per release; and
incremental outcome per infrastructure dollar.
Capacity formula
At a high level:
PeakWork = PeakQPS × CandidatesPerRequest × FeatureAndScoreCostPeakWork = PeakQPS × CandidatesPerRequest × FeatureAndScoreCost
This hides fan-out and tail behavior, so load testing must use real candidate distributions, hot users/items, selective filters, cache misses, and experiment overhead.
Optimize the pipeline, not one model
A 20% faster ranker may not matter if online feature hydration consumes 60% of latency. A compressed index may save memory and force larger over-retrieval. A new candidate source may improve recall and double ranking cost. Evaluate system-level quality-cost Pareto frontiers.
Worked Architecture: Marketplace With 80 Million Items
Consider a multi-region marketplace with 80 million active item variants, 12 million monthly users, anonymous and authenticated traffic, rapidly changing inventory, and home, search-adjacent, product-detail, and checkout surfaces.
Requirements
18,000 peak recommendation requests/second;
p95 under 160 ms;
99.95% availability;
item searchable within eight minutes of catalog approval;
inventory and market eligibility within 30 seconds;
no cross-market or restricted-item exposure;
support for new users, new items, and long-tail suppliers; and
online experiments without separate serving stacks.
Data and state
Client and server events enter a durable stream with request, exposure, and outcome contracts. Catalog changes flow through canonicalization, variant grouping, taxonomy validation, policy classification, and content processing. Recent session state is maintained in a regional key-value profile service. Long-term features are built from event-time-correct pipelines.
Candidate portfolio
The home surface calls in parallel:
a two-tower ANN service for personalized retrieval;
item-based collaborative neighborhoods seeded by recent activity;
content embeddings for cold and semantically related inventory;
region/category trending;
curated campaigns; and
a bounded exploration source for new qualified items.
The product-detail surface changes the source mix: item-based, content, substitutes, and complements receive larger budgets; durable user personalization receives less.
Ranking path
The orchestrator requests about 1,800 total candidates. Canonical merge reduces this to 1,250. Eligibility and parent-product deduplication leave 900. A small pre-ranker preserves 500 candidates. The full LambdaMART ranker uses source, user, item, session, content, price, quality, and user-item cross-features. Calibrated purchase and return-risk models adjust utility. The slate layer produces 30 items with brand and category diversity, exploration limits, and final inventory validation.
Freshness
request context: immediate;
session profile: under five seconds;
inventory/eligibility cache: under 30 seconds;
new item content embedding and index insertion: under eight minutes;
item collaborative neighbors: hourly incremental plus nightly clean build;
two-tower and ranker retraining: daily candidate, promoted only after gates;
long-term profile aggregates: hourly.
Reliability
Each candidate source has a 30 ms deadline and circuit breaker. Failure of one source does not fail the request. If the feature platform exceeds its budget, a compact model uses source and cached features. If personalization is unavailable, market/category trending plus editorial inventory is served after eligibility. Authorization never degrades.
Deployment
The two-tower query model and item index are promoted as one compatible bundle. Ranking artifacts include feature contract, calibrators, and slate policy. Shadow traffic validates the whole candidate-to-slate path. A canary precedes user-level A/B testing.
Measurement
Dashboards separate candidate recall, ANN recall, pre-rank survival, ranking NDCG, policy displacement, final diversity, latency, fallback, qualified conversion, returns, and supplier coverage. The team can identify where a relevant item disappeared.
The result is an evolvable platform. Algorithms can improve without rebuilding the identity, event, policy, and experimentation foundation each time.
Architecture Failure Modes
Symptom | Architectural cause | Evidence | Corrective action |
model performs well offline but not online | leakage, biased exposure, or candidate mismatch | temporal replay and experiment results | point-in-time joins, exposure logging, production-like groups |
relevant items never reach ranking | candidate portfolio or pre-rank recall failure | stage-level Recall@K | improve sources, budgets, merge, or pre-ranker |
p99 latency spikes | fan-out, retries, hot shards, or per-item feature calls | distributed trace and cohort latency | deadlines, batching, bulkheads, shard/cache redesign |
new items are absent for hours | slow content/embedding/index pipeline | source-to-searchable lag | fast-path validation, encoding, and insertion |
recommendations violate inventory or entitlement | stale filters or policy delegated to model | policy rejection and incident audit | authoritative final validation and fail-closed behavior |
results are repetitive | one source dominates and ranking ignores slate | source mix and diversity | source blending, slate reranking, exploration |
popularity continually increases | exposure-feedback loop | exposure concentration over model generations | correction, exploration, coverage objectives |
model/index launch causes random results | incompatible embedding spaces | bundle-version trace | atomic compatibility enforcement |
feature outage breaks all personalization | no defaults, cache, or lightweight ranker | feature missingness and fallback logs | degraded path and dependency isolation |
regional failover serves stale or unsafe items | unclear state RPO and cache policy | failover exercise | per-state recovery targets and policy-safe replication |
ranker gain disappears after policy | excessive or conflicting reranking rules | base-to-final displacement | simplify, optimize constraints, assign policy ownership |
one supplier gets excessive exposure | popularity/source/metadata bias | provider exposure dashboards | calibration, quotas, fairness review, exploration |
deletion does not propagate | derived-state inventory not mapped | lineage and deletion audit | artifact lifecycle and reprocessing workflow |
incident cannot be reconstructed | versions and stage decisions not logged | missing trace fields | versioned decision records and retention |
infrastructure cost grows faster than value | unchecked candidates/features/versions | unit-cost dashboard | quality-cost budgets and source/model rationalization |
An Evolution Roadmap From Baseline to Platform
Stage 1: trustworthy baseline
instrument decisions, exposures, and outcomes;
canonicalize catalog and eligibility;
launch contextual popularity and simple item relationships;
build deterministic fallbacks;
define latency, availability, freshness, and safety SLOs; and
establish temporal offline and online experiment baselines.
Stage 2: multi-source candidates
add item-based collaborative filtering;
add structured and content similarity for cold items;
preserve source provenance;
implement parallel orchestration, merge, deduplication, and partial success; and
measure candidate recall by source and cohort.
Stage 3: personalized large-catalog retrieval
train a two-tower model;
build exact evaluation and ANN infrastructure;
version query/item spaces and indexes together;
add session and long-term profiles; and
create new-item embedding and index SLOs.
Stage 4: contextual ranking and slate quality
build point-in-time feature contracts;
add pointwise and LambdaMART rankers;
calibrate multi-objective predictions;
add diversity, quotas, and policy-aware slate construction; and
measure full candidate-to-display survival.
Stage 5: continuous and governed optimization
automate retraining and index promotion gates;
add controlled exploration and bias-aware learning;
operate shadow/canary/experiment workflows;
measure user and supplier outcomes;
add multi-region recovery and chaos testing; and
manage unit cost alongside incremental business value.
Do not skip data and policy foundations to reach Stage 4 faster. The later models multiply the consequences of weak instrumentation and governance.
CTO Architecture Review Checklist
Product and decision
[ ] Each surface has an explicit principal, context, corpus, objective, top-KK, and guardrails.
[ ] Candidate generation, ranking, and slate policy have distinct responsibilities.
[ ] Primary metrics and counter-metrics reflect user and business value.
[ ] Cold-user, cold-item, anonymous, and low-confidence behavior is defined.
Online serving
[ ] The request carries consistent identity, tenant, experiment, deadline, and trace IDs.
[ ] Candidate sources run in parallel with bounded budgets and partial success.
[ ] Merge preserves source provenance and canonical deduplication.
[ ] Features are batch-hydrated and cross-features are vectorized.
[ ] Authorization and safety are checked after final reranking.
[ ] A tested degradation ladder ends in safe deterministic behavior.
Data and features
[ ] Decision, retrieval, display, examination, and outcome events are distinct.
[ ] Catalog identity, variants, provenance, lifecycle, and policy fields are authoritative.
[ ] Offline datasets and features are point-in-time correct.
[ ] Online features have owners, freshness, latency, default, and privacy contracts.
[ ] Profiles, embeddings, datasets, and logs participate in deletion workflows.
Models and indexes
[ ] Every complex model is measured against durable baselines.
[ ] Candidate-source recall and final ranking quality are evaluated separately.
[ ] Exact retrieval is the ANN quality oracle.
[ ] Model, feature, calibrator, index, and policy compatibility is enforced.
[ ] Current, shadow, and rollback artifacts fit capacity.
[ ] New-item and new-user cohorts have explicit release gates.
Deployment and experiments
[ ] Artifacts are immutable, versioned, and traceable to data and code.
[ ] Automated tests cover data, model, security, latency, and failure behavior.
[ ] Shadow and canary precede material rollout.
[ ] Online experiments have power, duration, guardrails, and rollback criteria.
[ ] Retraining is triggered by evidence and still requires validation.
Reliability and operations
[ ] p50/p95/p99 latency is decomposed by stage and dependency.
[ ] Freshness, availability, coverage, and fallback have SLOs.
[ ] Traces correlate technical stages with model and policy versions.
[ ] Failure injection validates timeouts, isolation, safe fallback, and recovery.
[ ] RTO and RPO are defined per state, not only for the endpoint.
[ ] Cost per request, candidate, item, and model release is visible.
Security and governance
[ ] Tenant and entitlement boundaries are enforced and adversarially tested.
[ ] Data collection and derived profiles follow purpose, retention, and access policy.
[ ] Catalog and event poisoning controls exist.
[ ] Consumer and provider exposure outcomes are monitored.
[ ] Human override, escalation, audit, and rollback ownership is assigned.Frequently Asked Questions
What are the main components of a production recommendation system?
A production system normally includes event and catalog pipelines, identity and profile state, multiple candidate generators, candidate orchestration, merge and eligibility, feature hydration, pre-ranking, full ranking, calibration, slate reranking, a recommendation API, exposure/outcome logging, experimentation, MLOps, monitoring, security, and fallbacks.
Why use multiple candidate-generation algorithms?
Different sources cover different failure modes. Collaborative filtering captures behavior, content models support new items, two-tower models retrieve personalized candidates from very large catalogs, popularity supports new users and fallback, and exploration gathers missing evidence. A portfolio improves recall and resilience.
When do we need a two-tower model?
Use it when the catalog is too large for exhaustive personalized scoring and query-item relevance can be approximated by separately computed embeddings. Smaller or heavily filtered catalogs may be served by exact retrieval or direct ranking.
Is a vector database the recommendation system?
No. A vector index is one retrieval component. It does not define user context, eligibility, candidate-source blending, ranking, slate policy, experimentation, or feedback quality.
What is the difference between ranking and reranking?
Ranking assigns relevance or utility scores to individual candidates. Reranking constructs the final list while considering duplicates, diversity, quotas, layout, sponsorship, safety, and interactions among selected items.
How fresh must recommendations be?
Freshness is state-specific. Session intent may need seconds, inventory seconds or minutes, new-item embeddings minutes, collaborative tables hours, and core models daily or weekly. Tie each SLA to measurable product value.
Batch or real-time recommendation which should we choose?
Most mature systems are hybrid. Batch provides reproducible models and long-term aggregates. Streaming updates session state, trends, exposures, inventory, and new items. Online learning is justified only when its incremental value outweighs reliability and governance cost.
How do we prevent feedback loops?
Log exposure, distinguish examination from non-interaction, use controlled exploration, correct bias where possible, track popularity and supplier concentration, preserve content/editorial sources, and evaluate long-term diversity and coverage.
How should recommendation services fail?
Use deadlines, partial candidate success, cached profiles, lightweight ranking, contextual popularity, curated safe defaults, or removal of the module. Never weaken authorization, safety, or tenant isolation during degradation.
How do we measure a recommender end to end?
Measure candidate recall, ANN recall, ranking quality, final-slate relevance and diversity, policy compliance, latency, freshness, coverage, negative outcomes, and causal online business metrics. Keep stage metrics separate so failures are diagnosable.
Should we build one ranker for every surface?
Share infrastructure and features, but use separate models or routing when surfaces have materially different candidate distributions, intent, outcomes, latency, or policies. A universal model is beneficial only when transfer gains exceed interference and operational complexity.
How much does a scalable recommendation platform cost?
Cost depends on traffic, catalog size, feature complexity, embedding dimensions, index replicas, candidate counts, model inference, freshness, regions, experimentation, and telemetry. Estimate unit costs and compare each architecture increase with incremental outcome value.
What should a production proof of concept include?
It should use a real event and catalog contract, at least two candidate sources, point-in-time features, an eligibility layer, a ranking baseline, a final slate, exposure logging, temporal evaluation, latency/load testing, a safe fallback, and a path to controlled online measurement. A notebook metric is not sufficient.
Build the Platform Around the Decision, Not the Algorithm
A scalable recommendation system is an operating model for decisions. Candidate generation supplies breadth. Collaborative filtering captures shared behavior. Content representations give new and sparse items a chance. Two-tower models search large catalogs. Learning-to-rank combines contextual evidence. Reranking turns independent scores into a useful, diverse, and policy-compliant slate.
Those algorithms create sustainable value only when the architecture also provides trustworthy events, canonical catalog data, point-in-time features, versioned artifacts, compatible indexes, deadline-aware serving, graceful degradation, causal experimentation, observability, security, and accountable governance.
The best first architecture is not the most elaborate diagram. It is the smallest design that meets the current decision contract while leaving clear boundaries for the next candidate source, ranker, region, policy, or freshness requirement.
Codersarts helps enterprise teams design and implement production recommendation platforms across data architecture, collaborative and content-based retrieval, two-tower models, vector search, learning-to-rank, slate optimization, deployment, evaluation, and monitoring. Explore our machine learning development services, machine learning deployment services, and MLOps services.
Planning a scalable recommendation platform or redesigning a system that has outgrown its first model? Discuss your recommendation-system architecture with Codersarts.
Primary References
Covington, P., Adams, J., and Sargin, E. “Deep Neural Networks for YouTube Recommendations.” RecSys, 2016. Google Research.
Gomez-Uribe, C. A., and Hunt, N. “The Netflix Recommender System: Algorithms, Business Value, and Innovation.” ACM TMIS, 2015. ACM DOI.
Naumov, M., et al. “Deep Learning Recommendation Model for Personalization and Recommendation Systems.” 2019. arXiv.
Gupta, U., et al. “The Architectural Implications of Facebook’s DNN-based Personalized Recommendation.” 2019. arXiv.
Liu, Z., et al. “Monolith: Real Time Recommendation System With Collisionless Embedding Table.” 2022. arXiv.
Yi, X., et al. “Sampling-Bias-Corrected Neural Modeling for Large Corpus Item Recommendations.” RecSys, 2019. Google Research.
Kumthekar, A. A., et al. “Recommending What Video to Watch Next: A Multitask Ranking System.” RecSys, 2019. Google Research.
Mitra, B., et al. “Joint Multisided Exposure Fairness for Recommendation.” SIGIR, 2022. Google Research.
OpenTelemetry. “Semantic Conventions.” Official specification.



Comments