All topics
RxJSbeginner

Observable Fundamentals

Explain what an Observable is, how it differs from a Promise, and the producer/consumer/subscription model.

An Observable represents a stream of values over time — it can emit zero, one, or many values, synchronously or asynchronously, and can error or complete — which makes it a fundamentally more general tool than a Promise, which can only ever resolve to exactly one value (or reject once) and can't be cancelled once started. Interviewers ask about this comparison constantly because Angular leans on RxJS pervasively (HttpClient, the Router, reactive forms' valueChanges, and more all return Observables), so genuinely understanding the model — not just copy-pasting .subscribe() calls — is foundational.

A Promise is like a vending machine that dispenses exactly one snack after you press a button, and you can't get your money back once it's dispensing. An Observable is like a live radio broadcast — it can play multiple songs over time, you can tune in (subscribe) whenever you want, and you can always turn off the radio (unsubscribe) without affecting other listeners tuned into their own receivers.

Key Concepts

1
An Observable is lazy: nothing happens when you create one — no HTTP request is sent, no timer starts — until something calls .subscribe() on it. Each subscription independently triggers the Observable's producer logic from scratch (unless the Observable is explicitly made "hot"/multicast, a distinction covered under Multicasting), which is different from a Promise, where the underlying async work has typically already started the moment the Promise object was created, and every .then() attached to it shares that same single, already-in-flight result.
.subscribe().then()
2
Subscribing returns a Subscription object with an .unsubscribe() method, which is how you tell the Observable's producer to stop doing work and clean up — critical for avoiding memory leaks with long-lived or infinite streams (a Subject, a fromEvent, an interval), though it's unnecessary for Observables that complete after one emission on their own, like most HttpClient requests.
Subscription.unsubscribe()SubjectfromEventinterval
3
A thorough answer distinguishes the three notification types an Observable can emit to its subscribers — next (a value), error (a terminal failure, after which no more notifications occur), and complete (a terminal success signal, after which no more notifications occur either) — and notes that unlike a Promise's fixed resolve/reject dichotomy, an Observable can emit any number of next values before eventually erroring or completing (or neither, if it simply runs forever).
nexterrorcomplete