Sub topic 3
Scaling and Operating a Search Service
Assume you know basic SQL, REST APIs, message queues, caching, and horizontal scaling. A search service must scale reads, absorb failures, and remain safe while its index changes.
Scaling with shards and replicas
A shard is a partition of an index. Documents are distributed across shards, often by document ID. A query runs on every relevant shard, then the service merges their results. More shards increase storage and write capacity, but they also increase coordination and merge work.
A replica is a copy of a shard. Replicas improve read capacity and allow searches to continue when a node fails. They also consume storage and make indexing more expensive.
Choose shard sizes and counts from measured document volume, query rate, and growth. Avoid creating many tiny shards. Keep related documents together only when the engine supports a useful routing strategy and the routing key does not create hot spots.
Reindexing safely
A mapping or analyzer change usually requires rebuilding the index. Create a new version, such as products_v2, and populate it from the source of truth. Validate document counts and representative queries. Then switch a stable alias from the old index to the new one. This makes the cutover quick and reversible.
Do not treat the search index as the primary database. Keep enough source data to rebuild it.
Failure modes and fallback behavior
Expect stale documents, failed indexing events, unavailable shards, and overloaded nodes. Retry transient failures with limits and a dead-letter queue. Monitor indexing lag and query latency. If search is optional, return a clear degraded response, such as popular items or database-backed exact matches. Do not silently show unauthorized results.
Autocomplete and permissions
Autocomplete often uses a separate prefix field or suggestion index. Keep suggestions small, rate-limit requests, and avoid indexing private terms. Apply tenant, ownership, and role filters to every query, including autocomplete.
Measuring relevance
Create a test set of real queries with expected results. Compare ranking changes offline, then monitor click-through, successful searches, empty-result rate, and query reformulation. Tune analyzers, boosts, and BM25 parameters only when measurements show a problem.
Exercise
Why use an alias when changing an index mapping?
Show answer
An alias lets you build and validate a new index before switching traffic atomically, with a quick rollback to the old index.