Building a Multi-Source Autocomplete System for Workplace Search
System DesignModel answerLast updated
Design the frontend and backend for a workplace search autocomplete that blends history, colleagues, files, applications, and filter chips in real time.
You're designing the autocomplete experience for a workplace search platform. When a user types into the search input, the interface displays live suggestions pulled from multiple data sources:
- Search history: queries the user has run before
- People: colleagues in the organization
- Documents: files the user can access
- Applications: internal tools and services
- Filter suggestions: scoped refinements (e.g., "modified:last-week", "type:spreadsheet")
Each suggestion type triggers different behavior when selected—some execute a search, others navigate directly to a resource, and filters modify the query scope.
Design both the client-side architecture and the supporting service layer. Your design should address:
- How the client manages typing input, network requests, and response ordering
- How suggestions from different sources are retrieved, ranked, and combined
- Permission enforcement so users only see resources they can access
- Latency targets and how to handle slow or failing data sources
- Accessibility requirements for keyboard and assistive technology users
- Caching strategy and observability
Assume organizations range from hundreds to tens of thousands of employees, with document counts in the millions per tenant.
Hints
Hint 1
Consider debouncing vs. throttling and when to cancel in-flight requests as typing continues
Hint 2
Think about how to handle a scenario where one data source is slow—should you wait or show partial results?
Hint 3
Each suggestion type may need different permission checks; search history is private, documents require ACL evaluation
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Requirements and Behavior
Start by clarifying what happens when each suggestion type is selected:
- History: Execute that previous query again
- People: Navigate to the person's profile page
- Documents: Open the document directly
- Applications: Launch or navigate to the app
- Filters: Insert the filter token into the query input and keep focus in the search box
Latency target: suggestions should appear within 150–200 ms on desktop networks; mobile or constrained networks may tolerate 300–400 ms. Show up to 8–10 suggestions total, grouped by type or interleaved by relevance score.
Client Architecture
Input Handling and Request Policy
Use debouncing (not throttling) to trigger requests. Wait until the user pauses typing for ~150 ms before firing a request; this balances responsiveness with request volume. For very fast typers, consider a hybrid: throttle at 200 ms intervals but always debounce the final input.
Maintain a request sequence number or use AbortController to cancel stale in-flight requests. When a new keystroke arrives, abort any pending fetch and issue a fresh one. On response arrival, check the sequence number and discard responses that correspond to outdated input.
Local Caching
Cache recent results keyed by prefix. For example, if the user types "design" and then "desig", serve the "desig" response from the cache of "design" filtered client-side (if the result set was complete). This avoids redundant network round trips.
Invalidate cache entries after 5–10 minutes or when the user selects a suggestion, since search history and document state can change.
Accessible Combobox
Implement the ARIA combobox pattern:
- The input has
role="combobox",aria-expanded,aria-controlspointing to the suggestion list - The suggestion list is
role="listbox"with each itemrole="option" - Arrow keys navigate suggestions; Enter selects; Escape closes
- Announce the number of results and current selection to screen readers using
aria-liveoraria-activedescendant
Backend Service Design
API Endpoint
GET /api/suggestions?q=<query>&limit=10
Response:
{
"query": "proj",
"suggestions": [
{"type": "history", "text": "project roadmap Q4", "id": "h1"},
{"type": "person", "name": "Priya Okonkwo", "title": "PM", "id": "u42", "avatarUrl": "..."},
{"type": "document", "title": "Project Charter.docx", "path": "/teams/eng", "id": "d88"},
{"type": "app", "name": "Project Tracker", "icon": "...", "id": "app3"},
{"type": "filter", "label": "type:project", "value": "type:project"}
],
"latencyMs": 145
}
Fan-Out and Aggregation
The suggestions service fans out in parallel to:
- History service: queries the user's personal query log (user-scoped, no permission check needed beyond authentication)
- People directory: prefix match on name, email, and title within the tenant
- Document index: full-text prefix match with ACL filtering
- App registry: static or lightly cached list of enabled apps for the tenant
- Filter suggester: rule-based or template-driven (e.g., common filters for the current context)
Set per-source timeouts: 100 ms for history and filters (fast, in-memory), 150 ms for people and apps (indexed, low cardinality), 200 ms for documents (high cardinality, permission checks). If a source times out, log the miss and return partial results rather than blocking the entire response.
Permission-Aware Document Suggestions
Documents must respect access control lists. Two approaches:
- Index-time ACL embedding: Each document in the search index includes a list of permitted user or group IDs. The query includes
user_idandgroup_ids[]as filters. This is fast but requires re-indexing on permission changes. - Query-time ACL check: Retrieve candidate documents, then check permissions via a separate authorization service before returning. This adds latency but reflects real-time permission updates.
Prefer index-time embedding with a short TTL refresh (e.g., every 10 minutes) for performance. Pair with a permission change event stream that triggers immediate re-indexing of affected documents.
Ranking and Blending
Each source returns scored results. Normalize scores to [0, 1] and apply type-specific boosts:
- History: 1.2× (recent, high intent signal)
- People: 1.0×
- Documents: 1.0× for exact title match, 0.8× for body match
- Apps: 0.9×
- Filters: 0.7× (lower priority, supportive)
Interleave top results by score, respecting a cap per type (e.g., max 3 history, 2 people, 3 documents, 1 app, 1 filter) to ensure diversity.
Scaling and Caching
- Edge or CDN caching: Not applicable; results are user- and permission-specific.
- Application-layer cache: Memcached or Redis keyed by
(user_id, query_prefix). TTL 5 minutes. Invalidate on user actions (e.g., new search, document access). - Database: People and apps fit in memory or a fast KV store. Documents require a distributed search index (Elasticsearch, Solr, or managed equivalent) partitioned by tenant.
Autoscale the suggestions service based on request rate. Monitor p50, p95, and p99 latency per source, and alert when any source exceeds its budget.
Common Mistakes
- No request cancellation: Displaying stale results out of order confuses users. Always cancel or ignore obsolete responses.
- Blocking on slow sources: One slow backend shouldn't delay the entire UI. Use timeouts and partial results.
- Ignoring permissions: Leaking document titles or names of people in private groups is a privacy and compliance risk.
- No keyboard support: Many power users navigate suggestions via keyboard; missing ARIA roles and key handlers breaks accessibility.
- Over-fetching: Requesting 100 suggestions per source when you show 10 total wastes bandwidth and backend CPU. Fetch ~3–5 per source and blend.
Observability
Emit metrics for:
- Client: debounce delay, request cancellation rate, cache hit rate, time-to-first-paint of suggestions
- Backend: per-source latency, timeout rate, result count, ranking score distribution, error rate
Log slow queries (>500 ms) with source breakdown for optimization.
This architecture balances low latency, permission safety, and graceful degradation, delivering a responsive and secure autocomplete experience across diverse workplace data sources.