Lesson 4 of 15
34. Design Search Autocomplete (Typeahead)

34.3 What are the doors?

3 min read+10 XP

Step 3: API and data model (10 minutes)

GET /v1/suggest?q=dat&limit=5 returns: 200 { "prefix": "dat", "suggestions": ["data science", "database internals", "data structures", "dating advice", "data analytics"] } headers: Cache-Control: public, max-age=300 (same answer for everyone)
  • GET with the prefix in the URL, so responses are cacheable by the browser and the CDN (Chapter 26).
  • Lowercase and trim the prefix on the client and server, so "Dat", "dat " and "dat" share one cache key.
  • The client debounces (waits ~100 ms after the last keystroke), cancels in-flight requests when a new one starts, and keeps a small local cache so backspacing doesn't call the server again.