Pick the fix
Each keystroke runs SELECT ... WHERE q LIKE 'ab%' ORDER BY count DESC LIMIT 5 on Postgres, and p99 is 400 ms. Best direction?
Hint 1 of 1
What can be computed ahead of time?
Choose an answer, then open Show answer below to check it.
Show answer
Answer: A Precompute top-5 per prefix and serve from memory or Redis
Correct. One lookup per keystroke.
The suggestions for a prefix change slowly, so compute them ahead of time. Each keystroke then becomes one key lookup in memory instead of a LIKE scan and sort on the database.
Why not the others?
- B Add more Postgres replicas only. Still a sort per keystroke.
- C Remove the LIMIT. Returns more rows, slower.
- D Send a request every 10 ms. More load.