HLD Interview Question- Google

218
Sep 23, 2025

You are designing a cache system for query–catalog candidate scores.

Each query can have up to 5000 candidate IDs (CIDs).

Each candidate has a score and a frequency counter (how many times it has been accessed).

A key is defined as:

Query:version

A value is a set of (CID, score, frequency) pairs.

Requirements

  1. Insert / Update
  • When a candidate CID for a query comes in, insert or update its score.

  • If the CID already exists, update the score and increase its frequency.

  • If the query already has 5000 candidates, you must evict some using LFU (least frequently used).

  1. Lookup
  • Given a query and up to 1500 candidate IDs, return their scores.

  • The lookup should be 1 IOP (not O(N) in the number of candidates).

  • On every hit, increment the frequency counter for that CID.

  1. Eviction
  • Per-query eviction: when a query exceeds 5000 candidates, remove the least frequently used CIDs.

  • Global eviction: if the cache exceeds memory limits, evict entire queries using LFU or LRU.

Performance constraint

  1. Reads must always be 1 operation.

  2. Other operations (insert, eviction, update frequency) must be O(log N) or better.

  3. No operation should ever degrade to O(N).

Task

Design the high-level architecture and data structures for this system.

How would you store the data?

How would you efficiently support inserts, lookups, and evictions?

How would you enforce the per-query and global constraints?

Problem statement was to create a Data structure which will give us a high cache hit and with minimum iops.

Comments (2)