How it works
The client sends the current prefix to a query API. It validates length and context, reads a versioned prefix-to-candidates entry from memory or a shared cache such as Redis, filters it, and returns a bounded list. On a miss, the service can read persistent snapshot storage and fill the cache. Replicated query nodes behind health-aware routing protect availability.
Misses need a plan. A cache stampede happens when many requests miss the same entry at once and all hit the slower store. In an example with 5,600 reads per second and a 95% hit rate, the snapshot store sees 280 per second. After a cold restart, nearly all 5,600 arrive there, and a store sized for 1,000 per second falls over. Warm broad prefixes before taking traffic, and coalesce simultaneous misses so one request fetches while the others wait.
A public cache key must include normalized prefix, locale, region, and snapshot version whenever each changes the answer, as in v812:en-GB:GB:foot. Each added dimension splits the cache and lowers its hit rate, so include only those that change results. Browser or CDN caching, with a short lifetime, can help stable public lists. Account-specific suggestions require private caching or no shared cache. Keep a last-good snapshot available when a build or cache tier fails.
Two countries should see different top results for “football.” Why is a cache keyed only by prefix unsafe?
It mixes rankings. Include region and locale, as well as snapshot version, and avoid shared caching of personalized results.
Use this as a guide for self review; written answers are not graded.Keep in mind
- A versioned, context-aware key prevents mixing results.
- Shared edge caches suit public stable lists; personal results require isolation.