📡 You're offline — showing cached content
New version available!
Quick Access
Python Advanced

System Design: Design Google Search Autocomplete

Design search autocomplete for 10M QPS — Trie in memory, Redis caching, query aggregation pipeline, and personalization layer.

EzyCoders Admin November 12, 2025 14 min read 0 views
System Design Google Search Autocomplete
Share: Twitter LinkedIn WhatsApp

System Design: Search Autocomplete

Google serves 8.5 billion searches/day with autocomplete appearing within 100ms of the first keystroke.

Architecture

User types → Debounce 300ms → Cancel previous request
    |
    v Load Balancer (sticky by prefix first char)
    |
    v Autocomplete API Cluster (100+ nodes)
         L1: in-process LRU cache (hottest prefixes)
         L2: Redis cluster (warm prefixes, 5min TTL)
         L3: Trie in memory (full lookup, ~10GB)

Data Collection:
  Every query → Kafka → Aggregation service (Flink)
  Score = 0.7 * recent_count + 0.3 * all_time_count
  Update Trie every 15 minutes

Redis-Backed Suggestions

import redis
r = redis.Redis()

def get_suggestions(prefix: str, limit: int = 10) -> list:
    key     = f"suggest:{prefix.lower()}"
    results = r.zrevrange(key, 0, limit-1)
    if results:
        return [r.decode() for r in results]

    suggestions = trie_service.get(prefix, limit)
    if suggestions:
        pipe = r.pipeline()
        for term, score in suggestions:
            pipe.zadd(key, {term: score})
        pipe.expire(key, 300)
        pipe.execute()
    return [t for t, _ in suggestions]

Q: How would you personalize autocomplete?

Add a per-user layer: store each user's recent/frequent searches in Redis hash. At query time merge global suggestions with user-specific ones, weighting user history higher. Requires user identification and a personalization microservice. Test with A/B experiment vs global suggestions.

EzyCoders Admin
Written by
EzyCoders Admin

Team Lead and Full-Stack Developer with experience in PHP, JavaScript, SQL, DSA, and System Design. Passionate about software engineering, scalable web technologies, and helping developers prepare for coding interviews and tech careers through practical tutorials and professional guidance.

Comments (0)

No comments yet. Be the first!

Leave a Comment