Advanced RxJS Patterns
Higher-order observables, multicasting, share operators, error recovery, retry strategies, backpressure, custom operators
1What is the main difference between switchMap and mergeMap when handling concurrent HTTP requests?
What is the main difference between switchMap and mergeMap when handling concurrent HTTP requests?
Answer
switchMap cancels previous requests when a new value arrives, while mergeMap maintains all active subscriptions simultaneously. In a search bar, switchMap automatically cancels ongoing requests on new input, preventing stale results. mergeMap is suitable for independent actions that must all complete, like parallel file uploads.
2When should concatMap be used instead of mergeMap to process a queue of user actions?
When should concatMap be used instead of mergeMap to process a queue of user actions?
Answer
concatMap guarantees execution order by waiting for each inner observable to complete before processing the next, while mergeMap processes all actions in parallel without order guarantee. Use concatMap for critical operations requiring strict ordering, like sequential bank transactions or chat message sending. mergeMap is suitable for independent actions that can run in parallel.
3What is a higher-order observable and why does it require a flattening operator?
What is a higher-order observable and why does it require a flattening operator?
Answer
A higher-order observable is an observable that emits other observables. For example, a click observable that emits an HTTP request observable for each click. Without a flattening operator (switchMap, mergeMap, concatMap), you get a nested Observable<Observable<T>> structure unusable directly. Flattening operators automatically subscribe to inner observables and emit their values in the main stream.
Which operator should be used to automatically cancel an ongoing search when the user types new input?
How does exhaustMap differ from switchMap in handling critical requests?
+19 interview questions
Other Angular interview topics
TypeScript Basics
TypeScript Advanced
Angular Fundamentals
Components & Lifecycle
Services & Dependency Injection
Angular Modules Organization
Angular CLI
Directives & Pipes
Routing & Navigation
Reactive Forms
Template-driven Forms
RxJS Fundamentals
RxJS Operators
HttpClient & API Calls
Basic State Management
Change Detection
Angular Signals
Standalone Components
Angular Unit Testing
End-to-End Testing
Build & Optimization
NgRx Fundamentals
NgRx Advanced
Angular Architecture
Performance Optimization
Security & Best Practices
Angular Universal & SSR
Angular Micro-frontends
Master Angular for your next interview
Access all questions, flashcards, technical tests, code review exercises and interview simulators.
Start for free