RxJS interview questions and answers for frontend developers
RxJS interview questions test whether you think in streams: an Observable is lazy and can emit many values over time, operators build a new stream without running anything, and every subscription must end somewhere. Expect questions on hot versus cold sources, Subject types, sharing one HTTP call between subscribers, where to catch errors, and how to find a leak. Many interviews also ask you to build a tiny Observable by hand.
By Evin JohnPublished 7 min read
How RxJS shows up in interviews
RxJS is asked most in Angular roles, but also for frontend work with real-time data, NgRx or redux-observable, and some Node.js services. Framework details such as change detection and the async pipe are on Angular interview questions. This page is the library itself. Interviewers usually start with a concept question, then show a pipe and ask what it emits and when, then give a bug: duplicate HTTP calls, a stream that stops after one error, or memory that grows as users navigate.
- ConceptsWhat an Observable is, how it differs from a Promise, and what subscribing actually starts.
- Read a pipePredict the output of a chain of operators, including timing and completion.
- Fix a streamStop duplicate requests, keep a polling stream alive after an error, or plug a leak.
- Build oneImplement a minimal Observable or a custom operator to show you understand the contract.
RxJS fundamentals questions
| Question | What it tests | What a strong answer shows |
|---|---|---|
| How is an Observable different from a Promise? | Core model | A Promise is eager, settles once and cannot be cancelled. An Observable is lazy, can emit zero to many values, and can be cancelled by unsubscribing, which runs its teardown. |
| What happens when you call pipe but never subscribe? | Laziness | Nothing runs. pipe returns a new Observable description. The producer starts only on subscribe, once per subscriber for a cold source. |
| What is the observer contract? | Grammar | Any number of next calls, then at most one error or one complete, after which nothing more is delivered. |
| What does unsubscribe do? | Teardown | It stops delivery and runs the cleanup the producer returned, such as clearing a timer or aborting a request. |
| What is the difference between of and from? | Creation | of emits its arguments as they are. from converts an array, Promise or iterable into a stream, emitting each item of an array separately. |
| Is an Observable always asynchronous? | Timing | No. of(1, 2, 3) emits synchronously during subscribe. Code after subscribe runs after those values, which surprises people who assume async. |
| Why do many codebases end stream names with a dollar sign? | Convention | It is a naming habit that marks a variable as an Observable, such as user$. It has no effect on behavior. |
| What is a Subscription and how do you group them? | Lifecycle | The handle returned by subscribe. You can add child subscriptions to one parent and unsubscribe them together, though operator-based completion is usually cleaner. |
Build an Observable from scratch
A popular senior question is to write a tiny Observable. It shows laziness, the cold source, operators as functions from one Observable to another, and teardown in one place.
class Observable {
constructor(producer) {
this.producer = producer;
}
subscribe(observer) {
let closed = false;
let teardown;
const sub = {
unsubscribe() {
if (closed) return;
closed = true;
teardown?.();
},
};
teardown = this.producer({
next: (v) => { if (!closed) observer.next?.(v); },
complete: () => { if (!closed) { observer.complete?.(); sub.unsubscribe(); } },
});
if (closed) teardown?.(); // closed during a synchronous emit
return sub;
}
pipe(...ops) {
return ops.reduce((source, op) => op(source), this);
}
}
const map = (fn) => (source) =>
new Observable((o) => {
const inner = source.subscribe({ next: (v) => o.next(fn(v)), complete: o.complete });
return () => inner.unsubscribe();
});
const interval = (ms) =>
new Observable((o) => {
let i = 0;
console.log("timer started"); // runs once per subscriber: the source is cold
const id = setInterval(() => o.next(i++), ms);
return () => { clearInterval(id); console.log("timer cleared"); };
});
const ticks = interval(10).pipe(map((n) => n * 10)); // nothing runs yet: lazy
const seen = [];
const sub = ticks.subscribe({
next: (v) => {
seen.push(v);
if (seen.length === 3) sub.unsubscribe();
},
});
setTimeout(() => console.log(seen), 200); // timer started, timer cleared, [ 0, 10, 20 ]- Why does the map operator return a function? An operator takes a source Observable and returns a new one. That is why pipe can simply reduce over the list of operators.
- Why does map's teardown unsubscribe from the source? Unsubscribing from the outer stream must reach the producer at the bottom of the chain, or the timer keeps running with nobody listening.
- What would a second subscriber see? Its own timer starting from zero, because the producer function runs again. Making it hot means sharing one producer between subscribers.
Subjects and sharing questions
| Question | What it tests | What a strong answer shows |
|---|---|---|
| Hot versus cold Observable? | Producers | Cold creates its producer per subscriber (an HTTP call, a timer). Hot shares one producer, so late subscribers miss earlier values (DOM events, a WebSocket). |
| Subject versus BehaviorSubject? | State | A Subject only passes on values sent after you subscribe. A BehaviorSubject needs an initial value, keeps the latest, and gives it to every new subscriber, so it suits current state. |
| When would you use ReplaySubject or AsyncSubject? | Replay | ReplaySubject replays a set number of past values, for example the last few messages. AsyncSubject emits only the final value, and only on completion. |
| Why do two async pipes fire the same HTTP request twice? | Cold sources | Each subscription runs the cold request. Share it with shareReplay or restructure so one subscription feeds both places. |
| share versus shareReplay? | Multicasting | share multicasts to current subscribers and, by default, resets when they all leave. shareReplay also replays recent values to late subscribers, which suits cached lookups. |
| What is the risk of shareReplay without refCount? | Leaks | The shared source can stay subscribed after every consumer has gone, keeping timers or sockets alive. Setting refCount to true lets it tear down. |
| Why expose a Subject as an Observable from a service? | Encapsulation | Callers should not be able to call next on your state. Keep the Subject private and expose asObservable() or a derived stream. |
Operators and error handling questions
import { catchError, EMPTY, retry, shareReplay, switchMap, timer } from "rxjs";
const prices$ = timer(0, 30_000).pipe(
switchMap(() =>
http.get<Price[]>("/api/prices").pipe(
retry({ count: 2, delay: 1000 }),
catchError(() => EMPTY) // handled inside: the outer stream lives on
)
),
shareReplay({ bufferSize: 1, refCount: true })
);- Why does catchError placement matter? An error ends the stream it reaches. Catching on the outer pipe replaces the whole polling stream after the first failure. Catching inside the inner request lets the outer stream continue.
- What does catchError need to return? A replacement Observable: EMPTY to skip, of(fallback) to substitute a value, or throwError to rethrow a cleaner error.
- combineLatest, withLatestFrom, zip or forkJoin? combineLatest emits when any input changes once all have emitted. withLatestFrom samples other streams only when the main one emits. zip pairs values by index. forkJoin waits for every input to complete and emits their last values, like Promise.all.
- Why does forkJoin sometimes never emit? One input never completes (a BehaviorSubject or an interval) or completes without emitting. Add take(1) or first() where a single value is meant.
- debounceTime versus throttleTime versus auditTime? debounceTime waits for silence, throttleTime lets the first value through and ignores the rest for a window, auditTime emits the latest value at the end of each window.
- How do you write a custom operator? Compose existing ones in a function that returns pipe(...), such as a reusable retry-with-backoff. Build a new Observable by hand only when composition cannot express it.
- What does takeUntil need to avoid leaks? It should usually be the last operator in the pipe, so later flattening operators cannot keep inner subscriptions alive after the notifier fires.
Senior RxJS and scenario questions
| Scenario | Likely cause | What to say you would check |
|---|---|---|
| Memory grows each time a user opens and closes a page. | Unclosed subscriptions | Manual subscribe calls with no completion, takeUntil placed before a flattening operator, or shareReplay holding a source. Use heap snapshots and count subscriptions. |
| Search results sometimes show an older query's data. | Race between requests | mergeMap lets slower old responses arrive last. switchMap cancels the previous request when a new term arrives. |
| A save button submits the same form twice on a double click. | Flattening choice | exhaustMap ignores clicks while a save is in flight; concatMap would queue both. |
| A dashboard combines five streams and flickers. | Glitches | combineLatest emits for every input change. Debounce, distinctUntilChanged on derived values, or move synchronous derived state to signals or computed values. |
| Tests with timers are slow and flaky. | Virtual time | Use TestScheduler marble tests, where frames are virtual, instead of real waits. |
| A teammate wraps every HTTP call in a Subject. | Over-engineering | A single request is already an Observable, and many one-shot calls read more simply as a Promise with async and await. Keep streams for values over time. |
Fictional example
- Interviewer
- This stream polls prices every 30 seconds. After one server error the page never updates again. Why?
- Candidate
- Because the error reached the outer stream. The catchError sits after switchMap, so when one HTTP call fails, the error travels up, the timer stream terminates, and catchError swaps in a fallback that completes. An errored Observable never emits again. I would move error handling inside switchMap, onto the inner request, with a small retry and then EMPTY or a cached value, so one failed poll is skipped and the timer carries on. I would also share the result with shareReplay using refCount, so two components reading prices do not each start their own poller, and add a marble test that sends an error on one frame and checks the next poll still emits.
RxJS practice plan
- Day 1: type out the tiny Observable above from memory, then add a filter operator and a take operator to it.
- Day 2: write the same search box with switchMap, mergeMap, concatMap and exhaustMap and note what each does with a slow response.
- Day 3: break a polling stream with an error on purpose, then fix it by moving catchError.
- Day 4: write three marble tests with TestScheduler, including one with an error frame.
- Day 5: explain hot versus cold and the Subject types aloud, each in under a minute, with an example from a real app.
For the language underneath, see JavaScript interview questions and TypeScript interview questions. Testers who script API checks will find the same JavaScript habits in Postman interview questions.
Stream questions are about timing, and timing is hard to describe cleanly while talking. Natively, an AI interview assistant for Mac and Windows, transcribes a practice round on your computer so you can read back how you walked through a pipe, value by value. It can take a screenshot of an operator chain or a marble diagram and suggest what it emits, and with Pro or the free trial it shapes its hints around the résumé and job description you provide. The transcript and notes stay saved for review.
Questions people ask
What RxJS questions are asked in interviews?
Observable versus Promise, hot versus cold sources, Subject, BehaviorSubject and ReplaySubject, share versus shareReplay, flattening operators, combineLatest versus forkJoin, where to put catchError, and how to avoid subscription leaks.
What is the difference between an Observable and a Promise?
A Promise starts at once, settles a single time and cannot be cancelled. An Observable is lazy, can emit many values over time, and can be cancelled by unsubscribing.
What is the difference between Subject and BehaviorSubject?
A Subject passes on only the values sent after you subscribe. A BehaviorSubject starts with an initial value, remembers the latest one and gives it to each new subscriber, which makes it a fit for current state.
Are RxJS questions only asked for Angular jobs?
Mostly, but not only. Frontend roles with real-time data, NgRx or redux-observable, and some Node.js services also ask about streams and operators.
Where to go next
Practice with the same assistant you would use on a call: it listens, transcribes and suggests answers from your own resume and the job description.
Facts on this page were last checked on . Product details come from the Natively app itself; if something here is out of date, tell us at hello@heynatively.com.
