How to Build Search for an Online Store

Stepan Rodionov13 Oct 2023

Problem

Vprok.ru is an online store inside X5 Digital: 10 regions and over 72 thousand products. Its search started on Laravel ORM queries, then Sphinx. Sphinx could only reload the whole index, scaled badly and left the master database serving every catalog request. After the 2020 load growth the team needed a new platform, and then had to keep prices and stock current in the index.

Example from the article: with a full catalog reload every four hours, a promotion on milk at 49 rubles could sell out or end while the index still showed it, and the customer saw the real price only on the receipt.

Solution in brief

The team chose Elasticsearch with a hand-written indexer and one Go application (Finder) for faceted and full-text search. The index holds all storefront data, with dictionary entities in separate in-memory indexes. Updates travel as signals (entity IDs) over a message bus, and a "Fake Monolith" service hides the split of the monolith from the indexer.

Questions this case answers
  • How to choose between building, buying and self-hosting a search engine for a mid-sized catalog when the team has a few quarters and no search specialists
  • How to keep a derived search index fresh when master data changes in many services and a full reload every few hours leaves stale prices and availability
  • How to rebuild a derived index from several services that cannot be bulk-downloaded on a schedule without losing data integrity
  • How to choose a search platform for an online store: build by hand, buy a SaaS search, or run Elasticsearch?

Tools and methods

  • Elasticsearch — search engine and data store, one independent cluster per data center
  • Apache Kafka — data bus carrying change signals from the master system to the indexer
  • Indexer and Finder (Go) — in-house services: loading the index and serving storefront queries
  • Painless scripts — partial reindexing of a piece of a document inside Elasticsearch
  • Fake Monolith — aggregating database that imitates the old monolith for the indexer
Continue reading — it's free

Google or a one-time email code. No password.