Back to KB
Difficulty
Intermediate
Read Time
8 min

Swiggy Improves Search Autocomplete Using Real Time Machine Learning Ranking

By Codcompass TeamĀ·Ā·8 min read

Architecting Real-Time Learning-to-Rank Autocomplete with OpenSearch and Feature Stores

Current Situation Analysis

Search autocomplete is often treated as a simple prefix-matching problem, but in production environments with large catalogs, it is a high-stakes ranking challenge. Users expect suggestions within milliseconds, yet the relevance of those suggestions directly impacts conversion rates and user retention.

The industry pain point lies in the tension between latency constraints and ranking complexity. Traditional heuristic approaches—such as lexicographical sorting, static popularity boosts, or TF-IDF scoring—fail to capture dynamic user intent. They cannot react to real-time trends, such as a sudden spike in demand for specific items due to weather, events, or inventory changes.

This problem is frequently misunderstood as purely an infrastructure challenge. Engineering teams often assume that simply adding a machine learning model will solve relevance issues. However, deploying ML in autocomplete requires a specialized architecture that decouples candidate retrieval from scoring, manages feature freshness, and enforces strict latency budgets. Without real-time signals, models quickly become stale, ranking items based on historical data that no longer reflects current user behavior.

Data from production search systems indicates that heuristic ranking can degrade relevance metrics (NDCG) by 15-20% compared to models utilizing real-time interaction signals. The critical insight is that feature velocity matters as much as model accuracy. A slightly simpler model fed with fresh, real-time features often outperforms a complex model relying on batch-updated data.

WOW Moment: Key Findings

The following comparison illustrates the trade-offs between common autocomplete strategies. The data highlights why real-time Learning-to-Rank (LTR) architectures are becoming the standard for high-performance search, despite their implementation complexity.

ApproachP99 LatencyRelevance (NDCG@10)Adaptability to TrendsEngineering Overhead
Heuristic/Static< 15msLowNoneLow
Batch ML Ranking40-80msMediumDaily/HourlyMedium
Real-Time LTR< 50msHighInstantMedium-High

Why this matters: Real-Time LTR achieves the "sweet spot" where relevance is maximized without violating the sub-50ms latency threshold typical for autocomplete. The ability to adapt instantly enables systems to prioritize items based on live signals, such as clicks in the last 5 minutes or current inventory levels, which batch systems miss entirely. This approach transforms autocomplete from a static lookup into a dynamic, context-aware recommendation engine.

Core Solution

Building a real-time LTR autocomplete system requires a decoupled architecture that separates candidate generation from ranking. This design allows each component to scale independently and optimizes for latency by parallelizing I/O and computation.

Architecture Overview

  1. Candidate Generation: A fast retrieval layer (e.g., OpenSearch) fetches potential matches based on the user's input prefix. This step focuses on recall and speed, returning a superset of candidates (e.g., top 50-100 items).
  2. Feature Enrichment: A feature store retrieves real-time signals for each candidate. Features include user context (location, device), item context (price, category), and dynamic signals (click-through rate, conversion rate, inventory status).
  3. Ranking: An LTR model scores the enriched candidates. The model can be deployed as a plugin within the search engine or as a sidecar service.
  4. Response Assembly: The top-K ranked candidates are formatted and returned to the client.

Technical Implementation

The following TypeScript example demonstrates the orchestration logic. This implementation e

šŸŽ‰ Mid-Year Sale — Unlock Full Article

Base plan from just $4.99/mo or $49/yr

Sign in to read the full article and unlock all 635+ tutorials.

Sign In / Register — Start Free Trial

7-day free trial Ā· Cancel anytime Ā· 30-day money-back