The Real Fullstack

Design Search Autocomplete

Every keystroke runs SELECT … WHERE name LIKE 'sho%'. What should the architecture look like instead?

工程师12 分钟架构构建器
redisopensearchkafkacdn

此挑战尚未翻译为简体中文,你正在阅读英文版本。

任务:Build an architecture that serves suggestions from caches and a search index, keeps the index fresh from change events, protects the endpoint and stays within budget.背景 · 学习目标 ▾

Hollow Basket's search box asks the main database for suggestions on every keystroke. At peak it adds 40,000 queries per second, the database slows down for checkout, the index is rebuilt by a nightly job, and a scraper hammers the endpoint.

任务: Build an architecture that serves suggestions from caches and a search index, keeps the index fresh from change events, protects the endpoint and stays within budget.

学习目标

  • Separate read-heavy search from the transactional database.
  • Cache popular prefixes at the edge and in memory.
  • Feed the index from change events instead of nightly rebuilds.
模拟模拟数据
search box → CDNsearch box → suggest APICDN → suggest APIsuggest API → prefix cachesuggest API → search indexsuggest API → main databasemain database → change eventschange events → indexerindexer → search indexnightly rebuild → search indexsuggest API → rate limitersearch boxCDNsuggest APIprefix cachesearch indexrate limitermain databasechange eventsindexernightly rebuild

选择组件和连接。键盘操作:使用示意图下方的列表。

运行模拟

运行模拟以查看输出。

简化说明

Costs are abstract units. Real autocomplete also needs debouncing in the client and ranking signals. 教学模型——数字用于说明行为,并非基准测试。

概念

相关挑战

参考资料