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. 教育用モデルです。数値は挙動を示すためのもので、ベンチマークではありません。

コンセプト

関連する課題

参考資料