Angular

Advanced RxJS Patterns

Higher-order observables, multicasting, share operators, error recovery, retry strategies, backpressure, custom operators

22 interview questionsยท
Senior
1

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.

2

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.

3

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.

4

Which operator should be used to automatically cancel an ongoing search when the user types new input?

5

How does exhaustMap differ from switchMap in handling critical requests?

+19 interview questions

Master Angular for your next interview

Access all questions, flashcards, technical tests, code review exercises and interview simulators.

Start for free