Building Search for a Mobile App Marketplace
Machine LearningModel answerLast updated
Design an end-to-end search system for a mobile app marketplace covering retrieval, ranking, personalization, cold start, abuse prevention, experimentation, and the path from heuristics to learned ranking.
You are asked to design the search feature of a mobile app marketplace, where people look for apps to install on their phones. Queries are short: a category-style phrase such as "photo editor", a need such as "budget tracker", or the exact name of an app. Results must be relevant and must come back quickly.
Walk through your design and cover each of these areas:
- Product requirements and how you would measure success
- Understanding the query (intent, normalization, expansion)
- Ingesting app metadata and building the index
- Retrieving candidates and ranking them
- Personalization
- Typos, synonyms, and queries in multiple languages
- Cold start for newly published apps
- Protection against abuse and spam
- Online experiments and production monitoring
- A realistic path from a rule-based ranker to a learned one
State your scale assumptions explicitly and discuss the trade-offs behind your choices.
Hints
Hint 1
Start by separating query intents (exact app name vs. category vs. feature request). A strong rule for exact-name matches does a lot of the work for perceived quality.
Hint 2
Use a multi-stage funnel: several cheap retrieval sources (lexical and embedding-based) feed a light ranker, then a heavier model on a few hundred candidates. Think about what each stage costs in latency.
Hint 3
Clicks are biased by position and installs can be gamed. Think about retention-aware objectives, propensity correction, exploration for new apps, and ranking-signal fraud detection.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
1. Requirements and metrics
Functional: short free-text queries (1-3 words) with three intents: navigational (an exact app name), categorical ("photo editor"), and feature-based ("budget tracker with bank sync"). Results must be filtered by storefront/country, device, OS version, age rating, and language. Autocomplete and spelling correction are expected.
Assumptions: about 2M apps, about 175 storefronts, about 1B searches/day (~12K QPS average, ~40K peak). Target p99 under 150 ms end to end, with roughly 20 ms for retrieval and 60 ms for ranking. Metadata edits become searchable within minutes, and new apps within about an hour of approval.
Metrics
- North star: installs from search that are still retained (for example active at day 7 or 30). Raw installs reward clickbait.
- Online: CTR@k, install rate per search, reformulation rate, zero-result rate, abandonment.
- Offline: NDCG@10 and MRR on human-judged queries, plus success@1 for navigational queries.
- Guardrails: latency, developer diversity, new-app exposure, uninstall and refund rates.
2. Ingestion and indexing
App approvals and edits go onto a stream. An enrichment job does language detection, translation of key fields, screenshot OCR, embedding generation, and spam scoring, then writes to a document store.
- Inverted index with field-weighted BM25 (title > subtitle/keywords > description), sharded by storefront/locale.
- ANN vector index (HNSW or similar) over app embeddings.
- Forward index for fast-changing signals (ratings, installs, crash rate) refreshed hourly or daily, separate from text so each can update independently.
- 2M documents fit in memory, so every replica can hold its shard fully. Scale QPS by replication.
- Cache non-personalized candidate lists for head queries (power-law traffic), and apply personalization on top.
3. Query understanding
- Normalization: Unicode normalization, case and diacritic folding, language-appropriate tokenization (CJK segmentation, German compound splitting).
- Spelling: generate candidates by edit distance over a vocabulary of app names and frequent queries, rank with a noisy-channel model trained on reformulation logs. Auto-correct only when confident, otherwise show "did you mean", and never correct a query that exactly matches a real app name.
- Synonyms: mined from query-install co-occurrence plus a curated list; expanded terms get lower weight than originals.
- Intent classifier: a small model predicts navigational vs. categorical and a target category. A confident title or alias match pins that app to position 1.
- Multilingual: detect query language (may differ from device locale), search localized and translated fields, and use a multilingual dual encoder so "editor de fotos" can retrieve English-only apps. Handle transliterated input.
4. Retrieval and ranking
Candidate generation (~1-2K candidates, union of):
- BM25 lexical match
- Two-tower semantic retrieval trained on query-install pairs with hard negatives
- Exact name / alias lookup
- Popular apps in the predicted category
Stage 1: a gradient-boosted tree over ~50 cheap features trims to ~200.
Stage 2: a heavier model (DNN or cross-encoder) with features on relevance (per-field BM25, embedding similarity, prefix/exact title match), quality (smoothed rating, crash rate, recency, uninstall rate), popularity (time-decayed, per storefront), context, and personalization.
Objective: multi-task prediction of P(tap), P(install | tap), and P(retained | install), combined as score = P(install) * (1 + a * P(retain)), with a tuned online. Train with a listwise loss targeting NDCG.
Bias correction: clicks depend on position. Use a position feature fixed at serving time, or estimate propensities from a small randomized slice, and weight examples by inverse propensity. Otherwise the model learns its own past output.
Post-ranking: policy filters, developer diversity, and clearly labeled ad slots.
5. Personalization
Use installed apps (show "Open" rather than re-promoting them), recent searches, category affinity, and device type. Feed a user embedding and affinity features into stage 2. Relevance should dominate: personalization breaks ties among relevant apps and must not override a navigational match. Apply a privacy-aware design with consent, short retention, and a non-personalized fallback.
6. Cold start
New apps have no engagement data. Use content-based retrieval (text and visual embeddings), a Bayesian prior for engagement features (for example the category average), and a bounded exploration budget, such as a small slot or boost with Thompson-sampling-style allocation. Track exposure so exploration is capped and measurable. Graduate to normal ranking as impressions accumulate.
7. Abuse and spam
- Metadata stuffing: penalize repeated or irrelevant keywords, cap keyword fields, and run classifiers at ingestion.
- Fake installs and reviews: anomaly detection on install velocity, device clusters, and review patterns. Discount suspicious signals rather than only banning.
- Impersonation: protect brand names and aliases, with review for lookalike titles.
- Query-side abuse: rate-limit scraping and bots, and exclude bot traffic from training logs.
- Use retention-based objectives, which are harder to fake than installs.
8. Experimentation and monitoring
- Run A/B tests randomized by user, with a holdback. Watch primary retained-install metrics and guardrails. Use interleaving for fast ranker comparisons.
- Offline gate: NDCG on judged sets and replay before any online test.
- Monitor p50/p99 latency, zero-result rate, index freshness lag, feature drift, and per-storefront and per-language slices, since averages hide regressions.
- Alert on sudden drops in navigational success@1.
9. From heuristics to learned ranking
- V1: BM25 with field boosts, an exact-name rule, and a hand-tuned popularity and rating blend.
- V2: log impressions and outcomes, train a GBDT ranker on those logs with position-bias handling, and keep rules as guardrails.
- V3: add the embedding retrieval and the multi-task heavy ranker, with personalization.
- V4: continuous retraining, exploration, and per-market tuning.
At each step, ship only if offline metrics and an A/B test both agree.
Common mistakes
- Optimizing raw installs or CTR rather than retention.
- Ignoring position bias and training on biased clicks.
- Skipping the navigational-intent shortcut.
- Auto-correcting valid app names.
- Mixing fast-changing signals into the text index, forcing reindexing.
- No plan for new apps or for manipulation of ranking signals.