Skip to content

Architecture case: search, suggestions, and eligible results

11 min reading

Separate exact identifiers, prefix candidates, ranking and visibility under versioned indexing.

Page details

Optional architecture cases · Lesson 23

Published · Sources · 11 min reading · Last edited:

Know first: Databases in Ten Minutes; Reading Architecture Diagrams.

Editorial correction:

Earlier design notes used unsupported universal performance or reliability claims. This revision explains conditional mechanisms and explicitly hypothetical examples; no author-run benchmark or production incident is asserted.

More
20px

Keep Northwind search and suggestions inside one access boundary

Outcome. After this optional chapter, you can define exact, tolerant and permission-aware query behavior.

Hypothetical scenario. Priya can search restricted supplier notes, but the public catalogue search box must not disclose those note titles in suggestions.

In short. Distinguish exact identity from tolerant discovery. Authorize suggestions and cached snippets before disclosure.

A fast search can still return the wrong record

Hypothetical scenario. An internal catalogue supports product search and suggestions while a person types. Exact part identifiers should work, misspelled names should be useful, and restricted items must stay hidden. A new search engine responds quickly but ranks an obsolete product above the current one.

This case separates indexing, candidate generation, ranking, eligibility and presentation. Scope includes text search, exact identifiers, bounded prefix suggestions, index updates and evaluation. A public web crawler and model training are excluded. The design begins with the user's query contract rather than choosing a search product and adopting all its defaults.

Search is a derived view. Its latency and relevance are not enough if source versions and permissions are wrong. Decide what delay is acceptable for new items, updates, withdrawal and access changes; these transitions can require different treatment.

One query operator cannot express every intent

A prefix search for a typed fragment, an exact identifier lookup and a multiword topical query have different semantics. Applying fuzzy matching everywhere can turn a precise identifier into an unrelated near-match. Applying exact matching everywhere can make ordinary wording unhelpful.

Normalization also changes meaning. Case folding, punctuation handling, tokenization and language rules may be useful for names but harmful for identifiers where characters distinguish products. Preserve fields with their intended search behavior rather than putting everything into one analyzed string.

PostgreSQL’s pg_trgm documentation describes trigram similarity and index support for matching text. Such a matching mechanism supplies candidates; the product still decides whether an approximate spelling match is acceptable for a given query.

Build a versioned search view

Ingestion preserves source identity, current version and visibility metadata. A transformation produces typed fields and searchable tokens under a named analyzer version. Updates and withdrawals carry ordered version evidence so retries do not restore obsolete state.

Query intent selects candidates before ranking and visibilityA versioned source index supports exact, prefix and topical candidate paths. A ranking and eligibility stage returns a bounded page with stable source identities.Versioned fieldssource + accessExact identifierPrefix suggestionTopical candidatesRank + eligibilitybounded results

Keep an exact path for structured identifiers. A prefix index or suitable ordered dictionary can support suggestions; an inverted index can retrieve documents containing query terms. A ranking function orders the selected candidates under an explicit query interpretation.

Perform the required eligibility checks before returning titles, snippets or suggestions. A restricted name leaked through autocomplete is still a disclosure even if clicking it later produces an access error. Cache keys must preserve scope and relevant index versions.

Work through keep Northwind search and suggestions inside one access boundary

Search is a projection of source records into a representation that supports specific query operations. PostgreSQL full-text and trigram matching are examples of concrete retrieval mechanisms; neither determines what an approximate match means to a customer. Separate exact product identity, tolerant spelling suggestions and ranked discovery so a missing identifier does not silently become a different confirmed item.

Suppose, hypothetically, fifty thousand users each make four search requests daily. The daily query count is 50,000 × 4 = 200,000. If the interface issues five suggestion requests while each search is typed, suggestions add 200,000 × 5 = 1,000,000 requests. The combined total is 1,200,000 requests per day before retries. These are illustrative interaction assumptions, not observed usage or a benchmark of any search engine.

A projection release should name the source revision, schema and analyzer settings that produced it. A new analyzer can change which terms are recognized; a new ranking policy can change the order even when the index bytes stay fixed. Evaluate the required query slices and record the selected release together, rather than referring to one timeless search index.

Suggestions need eligibility checks before text reaches the user. A result page that rejects a restricted document cannot undo a title already disclosed by an autocomplete cache. Carry the tenant and access context into every evidence-producing step, including suggestion generation and any shared cache. A current source permission decision must also have a defined relationship to a stale derived view.

Relevance and freshness need different evidence. Use known-item queries to check exact identity and representative discovery queries to compare ranking. Track publication and withdrawal separately so a useful mean score does not hide a source that was removed but remains suggestible. An opaque cursor should represent a defined ordering or result snapshot if the interface promises continuation across updates.

Derive index and suggestion work

Hypothetical scenario. Choose 100,000 source records with an average of 20 indexed term occurrences. The logical occurrence count is 100,000 × 20 = 2,000,000. At a chosen eight bytes per occurrence record, raw payload is 16,000,000 bytes, or 16 MB. Dictionaries, positions, skip structures, stored fields, allocation and replication are excluded.

Suppose 1,000 people each type a five-character query, issuing one suggestion request after every character. That creates 1,000 × 5 = 5,000 requests. If a deliberate client policy emits only two requests for each completed typing sequence in this example, demand becomes 1,000 × 2 = 2,000. This is a constructed event schedule, not a universal reduction from a particular debounce duration.

For candidate evaluation, choose 40 candidates and a maximum returned page of ten. If eligibility removes 12,28 remain, so a full ten-item page is possible. If eligibility instead removes 35, only five remain. Filling the page requires another bounded candidate fetch or an explicit shorter result; the original candidate budget cannot guarantee ten.

A relevance case has four labeled relevant records. The returned top five include three of them. Precision is 3 ÷ 5 = 0.6 and recall is 3 ÷ 4 = 0.75 at that cutoff. These measures depend on the labels and query, not only the index algorithm.

A backlog of 60,000 updates with 6,000 successful updates per minute and 3,000 new updates per minute drains at 3,000 per minute, requiring 60,000 ÷ 3,000 = 20 minutes. A withdrawal contract that cannot tolerate that delay needs another serving-side protection or prioritized update path.

In the wild: Keep Northwind search and suggestions inside one access boundary

PostgreSQL’s pg_trgm documentation specifies trigram similarity operations and index support for approximate text matching. Use that concrete mechanism to distinguish candidate retrieval from the product’s interpretation of a query.

Relevance and freshness need separate evidence

A ranking improvement can make popular queries better while damaging exact identifiers. Evaluate query families separately: known-item lookup, typo recovery, ambiguous names, rare terms and no-result behavior. Preserve the expected distinction between an exact match and a suggestion.

A stale index can rank its available records correctly while omitting the current source. Track ingestion lag and version coverage separately from relevance. Source and access changes may need serving-time verification even when a full reindex is still running.

When changing analyzers, build a compatible new collection and compare it against held-out queries. Query normalization and document normalization must agree. A same-sized index or an unchanged API response shape does not establish behavioral compatibility.

The autocomplete cache crosses an access boundary

Hypothetical scenario. An administrator searches for a confidential project. A shared cache stores the suggestion list under the query text alone. Another employee types the same prefix and sees the restricted name before submitting any search.

Scope suggestion eligibility and reuse to the authenticated reader's actual access contract. Avoid exposing sensitive query text through unrestricted logs or remote ranking services. A fast suggestion path must not bypass checks that the full result page enforces.

After a permission change, invalidate or revalidate affected derived results under the stated freshness rule. Record which cache and index version supplied the response so investigation can identify the failing boundary without assuming that the model or ranking function caused it.

Three search misconceptions

“An index makes every query cheap.” The supported operators, candidate count and filtering pattern determine work. A broad prefix can still produce many candidates.

“No results means no matching source exists.” Ingestion, normalization, eligibility and candidate limits can all hide a record. Diagnose the path before changing ranking.

“A relevant result is an eligible result.” Relevance and permission are different predicates, and snippets and suggestions need both.

Evolve the query contract carefully

Start with reliable exact lookup and a measured topical baseline. Add bounded suggestions where they help users choose a query. Introduce spelling correction or semantic retrieval only when failure cases justify the extra ambiguity and evaluation burden.

Monitor query latency, candidate volume, filter rejection, empty results, source lag and slice-specific relevance. Limit short-prefix work and abusive repeated queries. Keep rebuilds and live updates within resource budgets that preserve the intended serving path.

Reject a single blended relevance score as proof of exact-identifier quality. Reject unbounded wildcard expansion and global suggestion caching without scope. A good search design is explicit about which query it understood and what its index can currently establish.

Limits of keep Northwind search and suggestions inside one access boundary

The interaction multiplier is a hypothetical request model. Query cost also depends on operators, selectivity, index representation and access filtering. Evaluate identity queries and ranked discovery separately; neither one favorable mean score nor a fast suggestion response establishes a correct access boundary.

Check yourself: review search behavior

A part number has a close spelling match. Should the exact lookup silently substitute it?

Only if the product explicitly defines that behavior. Preserve exact identity and distinguish suggestions from a confirmed matching record.

The result page checks permissions but suggestions do not. Is the boundary complete?

No. Names and snippets can disclose restricted information. Enforce eligibility before every user-visible derived response.

A ranking change improves the overall mean but harms rare identifier queries. What should review inspect?

Slice-specific paired results and required query semantics. A favorable mean cannot establish that known-item lookup still satisfies its contract.

A restricted title appears in suggestions, but clicking it returns permission denied. Has the search boundary held?

No. The title was disclosed before the result-page check. Eligibility must govern the suggestion path and its cache keys before text reaches the user. A result-page denial is useful for that later boundary but cannot reverse an earlier disclosure. Test revocation and source withdrawal across both projections.

Northwind decision log

Distinguish exact identity from tolerant discovery.
Authorize suggestions and cached snippets before disclosure.
Version the source projection and evaluate query slices separately.

Go deeper into dictionaries and evaluation

Related blog: Vector Search Is Not Access Control: How RAG Leaks Documents and How to Stop It.