What is the difference between hot and cold Observables, and what does shareReplay do?

Angular HTTP, RxJS and state · Experienced

Model answer

A cold Observable starts a new execution for each subscriber, like an HTTP call: two subscribers make two requests. A hot Observable shares one source among subscribers, like mouse events or a WebSocket.

shareReplay turns a cold stream into a shared one and replays the latest values to late subscribers, so several parts of the app can use one HTTP result. Be careful with its refCount option and cache invalidation, or you can keep stale data or leak a subscription.

Learn this topic

Angular Tutorial: Beginner to Advanced .

Sign in to add your own answer.

More questions