Scrivio Interview library
DesignIntermediate6 min read · updated 12 November 2026

Design product search for a catalogue of 20 million items with facets, typo tolerance and near-real-time updates, using Spring Boot services and Elasticsearch or OpenSearch.

The catalogue database stays the source of truth, and every change is published as an event, through a transactional outbox or change data capture, to an indexer service. The indexer builds denormalised product documents and writes them with bulk requests, using external versions so older events never overwrite newer ones, and index aliases let a full reindex build a new index and switch over without downtime. A search API uses query templates with fuzzy matching and facet aggregations, strict timeouts and caching of popular queries, and we monitor indexing lag and reconcile counts between the database and the index.

Why this question is asked

Product search is where customers decide whether they can find what they want, so it directly drives revenue. With 20 million items, facets such as brand and price, typo tolerance and the expectation that a price change shows up within seconds, a database query is no longer enough and a search engine becomes worth its cost. The hard part is not the query; it is keeping a second data store correct and fresh. Interviewers ask this to see whether we can design that pipeline reliably. In this answer, we will lay out the system, publish changes reliably, build documents in an indexer, handle out-of-order updates, reindex with aliases, design the search API, and monitor the whole thing.

1The Shape of the System

Four parts work together. The catalogue service and its database own products, prices and categories; nothing else is allowed to change them. A change stream carries every change as an event. An indexer service, a Spring Boot application, consumes the events and writes search documents to Elasticsearch or OpenSearch. A search API, another Spring Boot service, turns user queries into engine queries and returns results.

Separating these means search can be rebuilt from the source at any time, and a search outage never blocks catalogue edits.

Step throughSearch architecture
  1. Search APIquery templates, timeouts, cache for popular queries
  2. Elasticsearch or OpenSearchalias products -> products_v7
  3. Indexer servicebuilds documents, bulk writes, external versions
  4. Change streamKafka topics from outbox or CDC
  5. Catalogue databasesource of truth for products and prices

5 layers, from the top down. Step through them one at a time.

2Publishing Changes Reliably

The tempting shortcut is a dual write: the catalogue service saves to its database and then calls the search engine. If the second call fails, or the service crashes in between, search silently disagrees with the database. Instead, we use one of two reliable approaches.

With a transactional outbox, the catalogue service writes the change and an event row into an outbox table in the same database transaction; a relay publishes outbox rows to Kafka. With change data capture, a tool such as Debezium reads the database's write-ahead log and turns committed changes into Kafka events. Either way, an event exists if and only if the change committed, so nothing is lost or invented.

3The Indexer: Denormalised Documents and Bulk Writes

A search engine has no joins worth using at query time, so each document must contain everything a search needs: name, description, brand, category path, price, availability, rating. The indexer listens to product, price and stock events, loads the current state of the product, and builds one denormalised document.

JSON
{
"id": "p-1029384",
"name": "Trail Running Shoe X2",
"brand": "Northpeak",
"category": ["Sports", "Running", "Shoes"],
"price": 89.90,
"in_stock": true,
"rating": 4.6,
"updated_version": 1762412345123
}

Writes go out as bulk requests, many operations in one HTTP call, for example 1,000 documents or about 5 MB at a time, which is far cheaper than one request per document. With a refresh interval of one second, the default, new documents become searchable within about a second, which is what near-real-time means in these engines.

4Handling Out-of-Order Updates With External Versions

Events can arrive out of order: two quick price changes for the same product may be processed by different indexer instances, or a retry may deliver an old event after a newer one. If the indexer writes whatever arrives last, an old price can overwrite a new one.

External versioning solves this. Each event carries a version from the source, for example the row's update sequence number or a commit timestamp, and the indexer passes it with the write and version type external. The engine stores the version with the document and rejects any write whose version is not higher than the stored one, with a conflict error that the indexer simply ignores.

Java
client.index(i -> i
.index("products")
.id(doc.id())
.version(doc.updatedVersion()) // version from the source, e.g. 1762412345123
.versionType(VersionType.External)
.document(doc));
// stored version 1762412345123, late event with version 1762412300000 -> 409 conflict, ignored
Step throughA late event is rejected
Indexer AIndexer BSearch engine
price 79.90, version 20
ok, stored version 20
price 89.90, version 19 (late)
409 version conflict
ignore: newer data already indexed

5 messages in order. Play them, or step through them one at a time.

5Index Aliases for Zero-Downtime Reindexing

Sometimes we must rebuild the whole index, for example to change an analyser. Queries never use an index name directly; they use an alias, products, that points to the real index, products_v7. To reindex, we create products_v8 with the new mapping, fill it from the source, let it catch up with recent events, and then move the alias in a single atomic request. Users never see a moment without results, and if v8 has a problem, we move the alias back.

Java
POST _aliases
{
"actions": [
{ "remove": { "index": "products_v7", "alias": "products" } },
{ "add": { "index": "products_v8", "alias": "products" } }
]
}

6The Search API

The search API does not let clients send raw engine queries. It uses query templates, fixed query shapes with parameters, so every query is known, tested and safe. The template uses a multi_match query across name, brand and description with fuzziness AUTO, which tolerates one or two typos depending on word length, so runing shoe still finds running shoes. Aggregations on brand, category and price ranges produce the facets, the counts shown beside the results, in the same request.

Every engine call has a timeout, for example 300 ms, and the API returns partial results or a friendly fallback rather than hanging. Popular queries such as the top thousand searches are cached for 30 to 60 seconds, which takes a large share of load off the cluster during peaks. Deep pagination is capped, because asking for page 500 is expensive and almost never a real user.

7Monitoring Lag and Reconciling

Two numbers tell us whether search is healthy beyond query latency. Indexing lag is the time from a change committing in the database to it being searchable; we measure it from the event timestamp and alert if it exceeds, say, 30 seconds. Count reconciliation compares the number of active products per category in the database with the index every night, and samples documents to compare fields. Differences point to lost events or indexer bugs, and the reconciliation job reindexes the affected products.

8Follow-up questions

Why not just query the catalogue database with full-text search?

For 20 million items with facets, typo tolerance and high query volume, a search engine does the job much better and keeps search load off the transactional database. Database full-text search is fine for simpler needs.

What version should you use for external versioning?

Something that only grows for a given product and is assigned by the source, such as a row version incremented on every update or the database log position of the change. Wall-clock time from different services is risky because clocks can go backwards or disagree.

How do you update all documents when a category is renamed?

The indexer finds affected products, usually by a query on the category id, and reindexes them in bulk. Large fan-outs are rate-limited so they do not delay normal updates.

9Conclusion

In this answer, we kept the catalogue database as the source of truth, published changes through an outbox or CDC, built denormalised documents in an indexer that writes in bulk, protected against out-of-order events with external versions, used aliases to reindex without downtime, served queries through templates with fuzzy matching, facets, timeouts and caching, and watched indexing lag and reconciled counts.

What to say in the interviewAbout 70 seconds aloud

Open with

The catalogue database stays the source of truth, and I would never dual-write from the catalogue service to the search engine, because a failure between the two writes leaves search silently wrong.

Then, if they want more

Instead, changes go through a transactional outbox or CDC with Debezium into Kafka. A Spring Boot indexer consumes product, price and stock events, builds a denormalised document per product with everything search needs, and writes in bulk requests of around a thousand documents.

Because events can arrive out of order, each write carries an external version from the source, so the engine rejects anything older than what it has. Queries go through an alias, so a full reindex builds a new index, catches up, and then the alias moves atomically, with an easy rollback.

The search API uses query templates with multi_match and fuzziness AUTO for typo tolerance and aggregations for facets, a timeout of a few hundred milliseconds, and a short cache for popular queries. Finally I would monitor indexing lag from commit to searchable, alerting above about 30 seconds, and reconcile counts per category nightly to catch anything we missed.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Design product search for a catalogue of 20 million items with facets, typo tolerance...": https://scrivio-interview-library.netlify.app/architecture/backend-system-design/1878d10748/