Preparing your design workspace

Loading the problem and your latest saved attempt…

Design a Backend Search Engine

Design a multi-tenant backend that ingests versioned documents and serves low-latency text search with filters, stable pagination, and safe index rebuilds.

Problem statement

A reported Elasticsearch-like interview led one candidate to discuss a write-ahead log, failover, redundancy, and Lucene. Those were the candidate's proposed design choices, not interviewer-required components.

For this exercise, assume application teams index versioned JSON-like documents into a multi-tenant backend search engine. Each document has a stable tenant ID, collection ID, document ID, monotonically increasing source version, text fields, bounded filterable attributes, and update time.

Producers can durably upsert or delete documents; delayed events with an older source version must not regress indexed state, and a delete tombstone must prevent an older retry from resurrecting a document.

Users search within one tenant and collection using a short text query plus bounded equality, range, and updated-time filters, and receive ranked document summaries.

Use lexical relevance as the initial ranking family, break equal scores by document ID, and bind each opaque cursor to the query and one index generation so pagination does not repeat or skip results while updates arrive.

Indexing may be asynchronous, but 99 percent of accepted updates should become searchable within 30 seconds and responses must expose an index watermark. Design for one billion retained documents across one hundred thousand tenants, fifty thousand document updates and twenty thousand searches per second at peak.

Common searches should complete within 250 milliseconds at p95, accepted update envelopes must survive a single-zone failure, and operators must rebuild one tenant or index partition without stopping reads or mixing partial generations. Enforce tenant isolation and explicit overload behavior.

Exclude semantic or vector search, autocomplete, recommendation ranking, model training, arbitrary joins, binary-object storage, and per-document authorization beyond tenant and collection isolation.

Post keyword search variant

For this exercise, a post is an existing versioned document in the caller's tenant and collection; no social publishing or feed service is added. Preserve the existing text-query API and its default lexical relevance behavior.

Add a structured search form with requiredTerms (one to eight entries), excludedTerms (zero to eight entries), and optional rankingMode. A request uses either the original text query or the structured form, never both.

Each structured entry must normalize to exactly one nonempty term under the index generation's recorded analyzer version; reject an entry that normalizes to zero or multiple terms. The same analyzer and token boundaries build postings and normalize query entries.

Deduplicate terms after normalization, and reject any normalized term that appears in both sets. These limits and normalization choices are practice assumptions.

A structured match contains every distinct required term (AND) and none of the excluded terms (NOT); excluded terms only filter. Omitted rankingMode keeps the existing lexical relevance default.

Explicit rankingMode=term_frequency ranks a matching document by the sum of its stored occurrence counts for the distinct required terms across all indexed text fields.

Each indexed token occurrence counts once in its field, with no length normalization or field weighting in this mode; repeated query entries do not add weight. Sort by descending frequency score, then ascending document ID.

Include normalized term sets, analyzer version and ranking mode in the query fingerprint, cache key and generation-bound cursor. A cursor cannot change those choices. Post updates, deletes and rebuilds update term membership and occurrence counts consistently for the same source version.

OR expressions, phrase queries and a free-form Boolean language are outside this structured variant; all prior scope exclusions remain.

What to build

  1. A producer can durably upsert or delete a versioned document without an older retry regressing indexed state.
  2. A user can search text and bounded filters within one tenant and collection and receive ranked summaries with stable pagination. The structured post variant intersects required-term postings, subtracts excluded-term postings, and supports an explicit term-frequency ranking mode while preserving default lexical search.
  3. Producers and readers can inspect update acceptance, searchable progress, and the index watermark instead of assuming immediate visibility.
  4. Operators can rebuild and promote a tenant or partition index generation while coherent reads continue on a prior generation.

At scale

  • For this exercise, assume one billion retained documents across one hundred thousand tenants, with peaks of fifty thousand document updates and twenty thousand searches per second.
  • For this exercise, target 250 milliseconds p95 for common searches and make 99 percent of accepted updates searchable within 30 seconds.
  • For this exercise, accepted update envelopes survive a single-zone failure, and delayed versions plus delete tombstones must never regress the logical document state.
  • For this exercise, one tenant or index partition can be rebuilt and atomically promoted without stopping reads or mixing partial index generations.