All Challenges
1 PointBasic
00:00

MEAN Stack: Angular & RxJS Debounced Autocomplete Search Engine

Build an Angular & RxJS search manager with debouncing, distinct query caching, TTL eviction, and request cancellation.

### Problem Overview In modern MEAN stack frontend architecture, building a performant, flicker-free autocomplete search input is one of the most frequently asked machine coding interview questions. Naive implementations fire an HTTP request on every keystroke, causing severe network flood, out-of-order responses (race conditions), and unnecessary server load. ### Functional Requirements 1. **`search(query: string): Promise<SearchResult[]>`**: - Debounce incoming queries by configurable `debounceMs` (default: `300ms`). - Discard consecutive duplicate queries. - Cancel previous in-flight HTTP requests if the user types a new character (`switchMap` behavior). 2. **In-Memory TTL Caching**: - Cache results in memory with a configurable Time-To-Live (default: `60,000ms`). - If a cached entry is valid, resolve immediately without calling the backend fetcher. 3. **Empty / Whitespace Query Handling**: - Immediately return an empty array without making network calls or caching empty results. 4. **Error Resiliency & Fallback**: - If the remote fetcher fails (HTTP 500/Network error), catch the error gracefully, emit an empty array, and allow subsequent queries to proceed without breaking. 5. **Cache Management**: - Provide `clearCache()` and `getCacheSize()` helper methods.
AI Review Rubric Dimensions (1–10 Points):
  • Debounce timing
  • TTL cache invalidation
  • In-flight cancellation
  • Error boundary recovery
solution.tsTYPESCRIPT
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
39 lines•792 characters•
AI Review Ready