LESSON 06 · Fast suggestions

Serve a predictable read path

Keep lookup short while handling misses and regional context deliberately.

SYSTEM VIEW

The suggestion path

Diagram view
Reads—
Hit rate—
Store reads—

Watch a prefix become a versioned cache key, see what reaches the Snapshot store when the cache misses or restarts cold, then key the cache by prefix alone.

  1. The Client types “foot”. The Query API checks length and context, then reads the entry at key v812:en-GB:GB:foot from the Prefix cache, in memory or a shared Redis. It filters the entry and returns a top 5. Replicated query nodes keep the path available.

    Key
    v812:en-GB:GB:foot
    Returns
    top 5

    What changed

    • “foot” sent
    • Key v812:en-GB:GB:foot
    • Prefix cache hit, top 5 returned
  2. The next reader types “footw”, an example of a rarer prefix, and its key misses. On a miss, the Query API reads the v812 list from the persistent Snapshot store and fills the Prefix cache, so the next reader of “footw” hits.

    Prefix
    “footw”
    Cache
    miss, then filled

    What changed

    • “footw” misses
    • 1 Snapshot store read
    • “footw” list in the Prefix cache
  3. At an example 5,600 reads a second, a 95% hit rate answers 19 of every 20 reads from the Prefix cache. The Snapshot store sees the other 5%, 280 reads a second, well under the 1,000 a second it is sized for.

    Reads
    5,600/s
    Hit rate
    95%
    Store sized for
    1,000/s

    What changed

    • 5,600 reads a second
    • 95% answered by the Prefix cache
    • 280 store reads a second
  4. The Prefix cache restarts empty, so nearly every read misses at once: a cache stampede. Almost all 5,600 reads a second fall through to the Snapshot store, sized for 1,000 a second, and it falls over.

    Store sized for
    1,000/s
    Arriving
    nearly 5,600/s

    What changed

    • Prefix cache restarts empty
    • Nearly every read misses
    • Snapshot store overloaded, down
  5. Instead, warm the restarted Prefix cache before it takes traffic: load broad prefixes such as “f” and “s” from the Snapshot store, which keeps the last-good snapshot. Reads then start near the 95% hit rate, and the store sees about 280 a second.

    Warmed
    “f”, “s” …
    Store reads
    about 280/s

    What changed

    • Broad prefixes loaded before traffic
    • Hit rate back near 95%
    • Snapshot store stays up
  6. Three readers miss on “footb” at the same moment. The Query API coalesces the misses: one request fetches the list from the Snapshot store and fills the Prefix cache while the other two wait, so the store gets one read instead of three.

    Misses on “footb”
    3 at once
    Fetches
    1, two wait

    What changed

    • 3 misses on “footb” at once
    • 1 store read, 2 requests wait
    • “footb” list in the Prefix cache
  7. Include prefix, locale, region and version where each changes the answer; each splits the cache and lowers its hit rate. Try both keys: the full key returns the GB list, while “foot” alone gives a GB reader the US list. Personal lists need private caching or none.

    Full key
    v812:en-GB:GB:foot
    Prefix only
    foot

    What changed

    • Key: prefix, locale, region, version
    • Personal lists stay out of shared caches
    Cache key

Space plays · ← → step · Home resets

THE IDEA

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.

DECISION POINT

Two countries should see different top results for “football.” Why is a cache keyed only by prefix unsafe?

Write a sentence or two to unlock the guidance. Committing first is what makes it stick.

Keep in mind

  • A versioned, context-aware key prevents mixing results.
  • Shared edge caches suit public stable lists; personal results require isolation.
CHECK YOUR UNDERSTANDING

Put it into practice.

1 OF 3
DiagnoseQUESTION 01

After adding a Canadian French locale, French speakers in Canada sometimes get English suggestions from the cache. What is wrong?

Choose an answer. You’ll see the explanation once you get it right.

Next lesson

0 of 3 checkpoints answered correctly to complete this lesson.