Full answer
All four combine several Observables, but they decide differently when to emit.
forkJoin([a$, b$]): waits until every source completes, then emits one array with the last value of each, then completes. If any source errors, the result errors. If a source completes without emitting, nothing is emitted. Use it for "run these independent requests and continue when all are done". It does not suit streams that never complete.combineLatest([a$, b$]): emits the first time every source has emitted at least once, then emits again each time any source emits, using the latest values of all. Use it for derived state from several live inputs, such as a filter, a sort order, and a list. It completes when all sources complete.zip([a$, b$]): pairs the nth value from each source. It emits only when each source has produced its nth value, so the slowest source sets the pace. Use it rarely: for lock-step pairing such as questions with answers.source$.pipe(withLatestFrom(other$)): the source drives the emissions. When it emits, the latest value ofother$is attached. Changes inother$alone emit nothing. Use it for "when the user clicks save, send the form together with the current user".
Rules to remember:
forkJoinrequires completion. For HTTP this is automatic.combineLatestemits nothing until all sources have a value. UsestartWithto unblock a source that may not emit.- Dictionary form is more readable:
forkJoin({ user: user$, courses: courses$ }). - With signals,
computedreplacescombineLatestfor state that already lives in signals.
The script below uses timers to make the timing visible. Output is the same every run.
typescript
import { combineLatest, forkJoin, interval, lastValueFrom, map, of, take, timer, toArray, withLatestFrom, zip } from 'rxjs';
const slow$ = timer(30).pipe(map(() => 'slow'));
const fast$ = timer(10).pipe(map(() => 'fast'));
// forkJoin: one emission after both complete.
console.log('forkJoin ', await lastValueFrom(forkJoin({ a: slow$, b: fast$ })));
// combineLatest: emits after each source has a value, then on every change.
const letters$ = interval(20).pipe(take(3), map((n) => 'ABC'[n]));
const numbers$ = interval(35).pipe(take(2), map((n) => n + 1));
console.log('combineLatest', await lastValueFrom(combineLatest([letters$, numbers$]).pipe(toArray())));
// zip: pairs by position, so the third letter has no partner.
const left$ = of('a', 'b', 'c');
const right$ = of(1, 2);
console.log('zip ', await lastValueFrom(zip(left$, right$).pipe(toArray())));
// withLatestFrom: the source drives. Changes of the other stream alone emit nothing.
const clicks$ = timer(50, 45).pipe(take(2), map((n) => `click${n + 1}`));
const user$ = timer(0, 30).pipe(take(4), map((n) => `user${n}`));
console.log('withLatestFrom', await lastValueFrom(clicks$.pipe(withLatestFrom(user$), toArray())));Tested with RxJS 7 under Node 22.18 or newer (`node main.ts`, package.json with `type: module`), run twice with identical output.
Key points
- `forkJoin`: once, after all complete. Good for parallel HTTP.
- `combineLatest`: on every change, latest of each. Good for live derived state.
- `zip`: pairs by position. `withLatestFrom`: sampling driven by the source stream.
- `combineLatest` waits for every source to emit once. Use `startWith` where needed.
Common mistakes
- Using `forkJoin` with a stream that never completes, such as `valueChanges`, so nothing is ever emitted.
- Expecting `combineLatest` to emit before every source has a value.
- Using `combineLatest` where `withLatestFrom` is needed, so a change in the second stream triggers an unwanted action.
Follow-ups
- How would you load a user and their courses in parallel and show both?
- What does `zip` do if one source is much faster than the other?
- How would you replace `combineLatest` with signals?
Tips
- Use the HTTP example for `forkJoin` and a filter UI example for `combineLatest`.
- Mention the completion requirement of `forkJoin`. Interviewers ask about it.
- Give the dictionary form, because it is more readable.
Evaluation rubric
- Explains emission rules of all four.
- Matches each to a realistic use.
- Knows pitfalls (completion, initial emissions).