Repository navigation
Description
I want to propose moving Observable back to the original per-subscription behavior:
Every call to
subscribe()starts a new execution of the Observable's subscription logic.
Sharing/multicasting would still be possible, obviously. It just wouldn't be implicit behavior of Observable itself.
I think the work in #170, #178, #198, and now #216 has actually been really useful here. The ref-counted design was trying to solve a real problem @esprehn brought up: accidentally duplicating expensive work, requests, listeners, etc.
But I think what we've learned since then is that implicit sharing creates another class of problems that are harder to see, because they're based on timing and on what other subscribers happened to do.
@jakearchibald's examples in #216 make that pretty clear.
take(3) is a simple example
Consider:
const firstThree = source.take(3);
firstThree.subscribe(a);
// Later:
firstThree.subscribe(b);I think most people would read firstThree as something like:
"An Observable that gives me the first three values from
source."
But with the shared model, if b subscribes after a already received one value, b can only get the remaining two before take(3) completes.
So now the semantics of take(3) depend on when some other subscriber happened to show up.
That's the same basic issue Jake found with fetch:
previous execution already completed:
subscribe B → new execution
previous execution still running:
subscribe B → joins existing execution
The exact same subscribe() call means something different depending on invisible timing/state elsewhere.
Cold has a footgun too, but it's at least a simple rule
The old behavior has one invariant:
Every subscription starts an execution.
That absolutely has a footgun.
If this Observable creates a fetch:
request.subscribe(a);
request.subscribe(b);then you might accidentally make two requests when you meant to share one.
But there's an opposite footgun too: maybe the second subscriber wanted fresh data, and instead it gets attached to an old or hung request.
The big difference to me is that the cold behavior is explicit:
subscribe A → execution A
subscribe B → execution B
It doesn't change depending on whether another request happened to finish 10ms earlier.
I think the discussions have basically found the abstraction boundary
There have been a bunch of really good observations across these issues:
- @esprehn called out the real production cost of accidentally duplicating work.
- Ref Counted Observable discussion #178 explored ref-counting as a way to solve that.
- @Jamesernator pointed out in Alternative to both ref-counted and current proposal - force strategy selection at creation time #198 that sharing, replay, eagerness, and lifecycle are actually different policies.
- @jakearchibald showed that implicit sharing creates timing-dependent behavior.
- @bakkot separated setup, becoming active/inactive, and actual completion into different lifecycle concerns.
- @acutmore pointed out that the original per-subscription Observable is the more general primitive, because sharing can be built on top of it.
I think that's a pretty useful result from trying the ref-counted model.
The model that falls out of all of that is really simple:
Observable = reusable execution plan.
Subscription = stateful execution.
Sharing/replay/lifetime = explicit policy.
This is also how I think about the relationship with async generators:
new Observable(subscriber => {
// execution plan
})is much closer to:
async function* values() {
// execution plan
}than it is to the AsyncGenerator returned by calling values().
Calling the async generator creates the stateful thing that eventually ends.
Calling subscribe() does the same thing on the push side: it starts an execution. That execution can end without the reusable plan itself becoming permanently dead.
Sharing should still be easy
I don't think we need to design share() in this issue.
But I do think #178/#198/#216 have shown us that sharing comes with real policy decisions:
- replay previous values?
- close when subscriber count reaches zero?
- close/reset after error?
- close/reset after completion?
- delay closing?
RxJS ended up with a pretty configurable share() API because these turned out to be genuinely different concerns.
I definitely don't think we should copy that API directly. It's pretty library-ish and not particularly friendly.
If we eventually add sharing to the platform, I'd rather it read more like:
source.share({
previousValues: 1,
closeOnZeroSubscribers: false,
closeOnError: false,
closeOnComplete: false,
});Something you can mostly understand by looking at it.
But that's a separate issue.
The important thing here is that those are sharing semantics, not Observable semantics.
Proposal
So my proposal is pretty small:
Calling
subscribe()starts a new execution of the Observable. Completion/error ends that execution, not the Observable itself.
I don't think this means the work in #170/#178 was a mistake.
Actually, I think it was useful because we now have concrete examples of what happens when sharing is pushed down into the primitive. #198 and #216 surfaced things that were much harder to see before we had that model to reason about.
To me that feels like incubation doing its job.
We know more now than we did when the ref-counted behavior was added. I think what we've learned points back toward keeping Observable small and predictable, and making shared execution something we ask for explicitly.
Just to try to consolidate the different options that have been presented, as I understand them. Listed with their features and footguns:
1. Observable — cold by default
| Features / benefits | Footguns / issues |
|---|---|
| Lazy | Consuming twice executes twice, and can therefore sometimes create multiple side effects |
| Every consumption gets a fresh execution | |
| Reusable derived Observables | |
| Simple, deterministic execution contract | |
| Strong local reasoning | |
| Sharing/replay can be layered on explicitly | |
| Matches the established Observable contract and ecosystem | |
| Higher order composition is straight-forward and well-established |
Open questions
- Basically none at the primitive level.
- What so…
Activity
jakearchibald commentedon Aug 11, 2026
I feel we can do better than shipping something we know to be a footgun.
It's not really that though. If the source is an
EventTarget(which will often be the case), thenfirstThreeis "an Observable that gives me the next three values from theEventTargetassociated withsourcefrom the point that I callsubscribeor one of the other methods that triggers execution."…and I think that's really confusing. I can imagine developers thinking that execution happens at the time the observable is created, or when
takeis called. Like,takesounds much more like an 'execution' on the source thansubscribe.subscribesounds passive.In #216 (comment) I tried to sketch out a way to make the point of execution less of a mystery.
jakearchibald commentedon Aug 11, 2026
Compare to:
benlesh commentedon Aug 11, 2026
I don’t buy that we’re “shipping something we know to be a footgun.” The contract is explicit, well-established, and spelled out in the README: every call to
subscribe()creates a new subscription, and nothing executes before subscription. Beyond being spelled out in the README, it's also something that's used at massive scale in the ecosystem for more than a decade.If someone assumes
take()starts consuming immediately, where do those values go before there’s an observer—buffered, replayed, dropped? That introduces far more hidden policy.Honestly, the
firstThreeiterator example you posted is almost an indictment of the Iterator helpers design, more than anything else. They clearly should have been on the Iterables, which should have been a type.The iterator comparison is also the wrong layer.
nums.values()is already a stateful, one-shot execution—the analogue of a subscription, not an Observable. The reusable analogue is the generator function that creates it.And
execute()plus a newObservationtype doesn’t solve this. Ifexecute()starts work, synchronous sources can emit or complete beforesubscribe(). Ifsubscribe()starts work, we’ve changed nothing except adding another object. If the first subscriber starts shared work, we’re back to the same timing-dependent sharing problem.So we’d be inventing a brand-new exhaustible async abstraction at the last minute, diverging from the well-known Observable contract and from what this proposal has promised from the beginning. Explicit sharing belongs in an explicit sharing API.
jakearchibald commentedon Aug 11, 2026
I can't resolve
vs
Are you saying the footgun issues that @esprehn experienced aren't real?
Yeah, buffered. The process of taking starts when you call
take. Not when you start listening for taken items. But I see your point - that doesn't play well with multiple subscribers, as the second subscriber will miss buffered items (this is also a flaw with the current hot model).Right. My point was that
takeis on the equivalent of the 'subscription', not the 'Observable'. I see you personally disagree with that, but that behaviour is already part of JavaScript.jakearchibald commentedon Aug 11, 2026
A bunch of methods implicitly create subscriptions, so I don't think it's even that simple.
benlesh commentedon Aug 11, 2026
No, I’m not saying @esprehn’s experience wasn’t real. My wording there was imprecise.
Cold Observables have one basic footgun: if you consume one twice, it executes twice. But that follows directly from a simple, explicit contract: every consumption—whether through
subscribe()or a terminal operator—starts a fresh execution. That can bite someone who overlooks the rule, but it’s local, deterministic, teachable, testable, and easy for tooling to reason about.The alternatives being proposed introduce a very different class of footgun. Does this subscription join an existing execution or start another? Did that execution complete a millisecond ago? What was buffered before anyone subscribed? What does a late subscriber receive? Those answers depend on hidden state and timing elsewhere, not on the code at the call site.
That seems like a materially worse trade: replacing one predictable failure mode with several nonlocal, timing-dependent ones, plus brand-new lifecycle types with no established community knowledge or precedent. Observables have been widely used for well over a decade. If this alternative model solved a common need, I’d expect to see successful implementations of it already.
And “Iterator Helpers already work this way” doesn’t make that behavior desirable for Observable. The
firstThreeexample returning nothing the second time is itself a footgun. We cite Iterator Helpers as precedent for the operators, not as proof that a reusable Observable should inherit the lifecycle of a one-shot iterator.jakearchibald commentedon Aug 11, 2026
I think the difference is, if that behaviour is indeed unexpected, it's something you experience and learn pretty quickly during dev. I wouldn't really class that as a footgun.
My understanding of the issues @esprehn raised, is they were making their way to prod without anyone noticing. That's absolutely a footgun.
So yeah… I still feel that we shouldn't be shipping something we know to be a footgun.
benlesh commentedon Aug 11, 2026
I think we’re conflating sharing an underlying producer with sharing an Observable execution.
It’s completely fine for
EventTarget.when()to use one native event listener internally and fan events out to every subscription. That’s an implementation detail. Each subscription should still have independent operator state, cancellation, and completion. Two subscribers towhen("click").take(3)can share the same DOM listener while each getting their own three clicks.Cold Observables have one basic footgun: consuming one twice may duplicate work. But that follows from one explicit, deterministic rule: every consumption starts an execution.
Trying to eliminate that one footgun introduces several worse ones:
take(), completion, errors, and cancellation may become shared or exhaustible state.execute()starts synchronous work beforesubscribe(), values must be lost or buffered.And that last point recreates the original “footgun” anyway:
Does calling
createObservation()start new work every time, or does it return a cached/shared execution? The type cannot tell you.() => Observation<T>reveals no more about its captured producer than() => Promise<T>, a callback-taking function, or an Observable does.If it creates a new execution every call, we’ve recreated the exact duplicate-work footgun we were supposedly eliminating. If it returns shared work, we still have all the timing, lifetime, and late-subscriber ambiguity. We’ve just moved the problem behind another abstraction.
Observable is a primitive, like a function. One call means one function execution. One subscription means one Observable execution. What that execution does internally—including whether it uses a shared listener, cached request, or other shared producer—is an implementation detail.
That is one simple contract. Replacing it with more types and hidden temporal state seems like a much worse trade.
stipsan commentedon Aug 25, 2026
@jakearchibald as someone who writes observable code with rxjs every day I'll take the "footgun" I know over "hidden temporal states" any day of the week.
From the "User needs":
If the browser primitives deviates on such a fundamental level as not adhering to

cold-by-defaultthen my fear is we'll end up with this instead:Changes to timing behavior means we have to be extremely careful when migrating, as TS or linters can't detect issues statically 😅
jakearchibald commentedon Aug 25, 2026
Both
obj1andobj2represent asynchronous data sources, and both have methods namedtake,drop,map,filteretc etc. This issue is proposing those methods behave very differently between the two objects.I think appeals to consistency are kinda low value here because consistency with one means inconsistency with another - and that should be justified.
@stipsan I get that, as someone who writes observable code with rxjs every day, you'd like consistency with rxjs, but not everyone writes observable code with rxjs every day. Also, in many cases, like above, developers will be encountering these objects without feeling like they asked for an observable.
I think we need to have pretty strong reasoning for making the platform inconsistent in this way. Although, since async iterator helpers haven't shipped yet, one solution may be to block them in favour of observables.
bakkot commentedon Aug 25, 2026
Oh man, please no. They've been coming along; It's been taking me a while because of having a kid but I've been able to put a lot of work in over the last year. I think the design ends up being quite natural and useful.
jakearchibald commentedon Aug 25, 2026
@bakkot I'm interested in your take on this. Is there a consistency issue here between async iterable methods and observable methods (assuming cold observables), or am I worrying over nothing?
stipsan commentedon Aug 25, 2026
@jakearchibald it's more that the current ecosystem around observables has such high interop, which is one of its best features. For example we have a large legacy codebase built on rxjs, that we've been able to re-use in newer code that uses state machines using xstate's observable actors. I could cite example after example, the point is that the vast majority of observable code written today is written this way.
The cost of using different semantics, as @benlesh already explained in great detail why they're problematic, is that the ecosystem will be fragmented around two very different observable primitives.
We've already been through a similar fragmentation in the ecosystem when nodejs decided to implement esm with different semantics than bundlers, before eventually coming full circle with
require(esm).In my opinion a fragmented ecosystem will do more harm than good, and I fear far more harm than having less consistency between native observables and async iterable methods, especially since the semantic differences can't be caught with static analysis.
For example, the difference in how unsubscribes are done with the current ecosystem being something like:
Versus this proposal
These are changes that are fairly easy to adapt to.
The timing differences are not, and while I understand the concern for the DX of folks encountering observables "without asking for them" (like
.whenmethods and what not), the proposal here is calling out eliminating massive amounts of JS down the wire as a huge win:If the native observable primitive can't be adopted in these codebases without a high risk of regressions (as this absolutely would be due to the lack of static analysis being able to catch changes in behavior that would regress production) then this proposal will fail to deliver on that goal.
If there is a massive win that could justify the behavior change, I can't think of a "real" example of what that would be, but lets say it could do something that userland implementations can not (like how
requestIdleCallbackcan't be shimmed in userland since it requires lower level access to scheduling), then I could understand the reasoning.As it is now, consistency with with async iterable methods doesn't feel like it's worth fragmenting the ecosystem and forgoing the JS bundlesize reduction we would see from having native primitives that would be low-risk to adopt (native promises for example were a no-brainer to adopt and it was quite easy to get rid of bluebird, even though that proposal also had a lot of debates and spicy discussions around how to cancel pending promises).
bakkot commentedon Aug 25, 2026
I don't think it's any different from how
.mapon an iterator produces a new one-shot iterator whereas.mapon an array produces a new array you can consume as many times as you like. Some types are one-shot, others aren't. There is an inconsistency here, and you do need to learn which is which, but that's already true and is really a fact about the world (some underlying data sources are one-shot!) so it's not fundamentally avoidable.More generally, my feeling is that async iterators are pretty different from Observables, and these kinds of differences are the reason they're different types - if the mechanics of async iterators were what we wanted, we would just be using those. The whole point of adding a new type is that it has different mechanics.
I don't think this necessarily argues for or against any particular design for Observables, and I haven't made up my mind about the specific proposal in this issue; just, I would recommend figuring out what the desirable mechanics are for Observable based on how we expect or want it to be used, and then not worrying if that ends up different from async iterators or async iterables.
All that said, regarding the
takeexample in the OP, I don't share @benlesh's feeling that this example has any one obvious behavior. You really can't know what's going to happen there without knowing how that type behaves. We have discussed all of.subscribe()call.subscribe()call, then it will see them againBoth "independent" and "shared" are totally reasonable IMO. "independent" is how you'd represent data at rest (e.g. an array in memory, a file on disk, etc). "shared" is how you'd represent a sequence of events in the world that happen whether or not anyone is watching (e.g. clicks). You cannot know just from looking at the
takecode snippet which of these it's supposed to be."shared-but-lazy" is a little surprising; I can see the rationale but I'd have to remember that quirk every time. This is how you'd represent a sequence of events in the world where you are implicitly kicking off the sequence by starting to pay attention to it (basically
fetchs; I don't see any other case where this is natural).If I've understood correctly, the current proposal does "shared-but-lazy-and-restarting". I think that is very surprising; I would not expect anything to work like that.
jakearchibald commentedon Aug 26, 2026
That's fair. Although, in the cases where it isn't one-shot, like
array.map, there aren't side-effects to multiple-shots. That seems to be where the observable footgun is - developers don't realise it's multi-shot, and the consequences of that end up live.Yeah, agreed.
60 remaining items
markerikson commentedon Nov 6, 2026
I'm highly amused that Redux is one of the largest "observable-compat" libraries in that list :) However, I'd recommend completely discounting it from any stats comparisons here.
There's two hypothetical ways that people might treat a Redux store as an observable: using the
redux-observablemiddleware (which integrates RxJs into a middleware for side effect behaviors), or the built-inSymbol.observableinterop field on the store itself.Ran some checks, and
redux-observabledownloads are <1% of Redux core numbers today, and well behind more common side effects addons likeredux-thunk,redux-saga, or RTK's owncreateListenerMiddleware.Some searching for likely uses of the store itself as an observable only found a relative handful of results.
Also, I'm pretty sure that the
Symbol.observablecompat was added way back in 2015ish within a few months of Redux being created (back when there was a lot more discussion about "side effects" anyway), and no one has ever put any thought into the intended semantics.So, technically yes a Redux store is observable-compatible, but in practice no one uses it that way and it shouldn't be a factor in this discussion.
keithamus commentedon Nov 6, 2026
I don't disagree with either of you, I just took what was in the readme. I was a little surprised to see signal-like libraries and things like redux, but gave it the benefit of the doubt as it doesn't really change the central point which is that userland seems quite split, even excluding Redux, Solid, and so on - we're still left with two models with a 50/50 split and neither exactly like what's proposed.
Perhaps as a new task from this issue, is we can shrink the list of userland libraries in the README if we don't think they fit the category of Observable.
benlesh commentedon Nov 7, 2026
Every library that's listed in the README, at one point or another, for a long period of time, had a type that had an observable signature. Hot or cold, it doesn't matter, they had a subscribe function that takes a callback and generally returned a teardown mechanism of some sort. I don't see the point in removing them. In multiple cases, there's even specific SHA links to lines of code that show the type.
Not all of those libraries exposed that type as some externally consumed thing. But they were at least using that signature internally for some period of time. Or at least around the time of the authoring of that README. It was investigated and then reviewed.
keithamus commentedon Nov 7, 2026
We can't claim that those libraries are irrelevant to the above data because they're fundamentally not Observables, but relevant for demonstrating the need for the Observables. Those are contradictory statements.
Regardless, we're deviating from the actual point I was making: userland is very clearly split, so the issue isn't as simple as moving back to cold. Let's focus on this. So the first foundation to get us to is: do you acknowledge what the data shows? Or do you refute it? If you refute it, do you have counter evidence?
Once we get past that, we can again ask; do we decide hot-or-cold by fixed design, by producer, or by consumer. What ramifications does this have?
benlesh commentedon Nov 7, 2026
I agree with your main point. Some projects need hot or shared Observables, others need cold, and plenty will need a mix of both. I think that’s pretty clear from the data, and I appreciate you putting it together.
The interesting thing is that we’re a little constrained by how these things compose. You can take a cold Observable and make it shared, but you can’t take a shared Observable and make it cold again without access to the underlying producer.
So I think that gives us a pretty important requirement: whatever we standardize needs to support both.
And I think Jake’s point in #216 actually reinforces that. We need to be able to get independent executions when we want them, just as much as we need to be able to share work when that’s appropriate.
That’s really why I keep coming back to cold-by-default with explicit sharing. Not because everything should be cold, but because it gives us a foundation that can support both models without taking either option away.
benlesh commentedon Nov 7, 2026
@keithamus I've been thinking about your design a bit more:
I'm not fundamentally opposed to this. I like that you're trying to give the producer control over sharing. It's just a pretty different model, and I'd like to understand the lifecycle better.
A few questions:
When does each callback run? I'm assuming the constructor callback runs once, and
onSubscriberuns for each subscription? Is the constructor callback eager, or does it wait for the first subscriber?What happens with completion and errors? What's the difference between
subscription.complete()andcontroller.complete()? Same question for errors. Can the controller become permanently terminal?How does retrying work? This is probably my biggest question. We don't have a
retry()operator in the proposal, but we do havecatch(), which can be used to implement retry by resubscribing to the source.For example, conceptually:
If the source errors, can we subscribe to it again and actually restart the work? What happens if the controller itself has errored or completed?
Retrying is a really important part of Observable's usefulness. In fact, retrying failed operations was the first thing I needed RxJS for back at Netflix in 2014, before I ever worked on the library.
How would you implement sharing and ref counting? The example above seems to handle cold execution pretty naturally. But what's the recommended pattern for a shared source? Would the producer maintain shared state through a closure, or is the controller responsible for managing that? Does the controller track subscriber counts and handle starting/stopping the shared execution when the count goes from 0 to 1 or 1 to 0? And can it start again when another subscriber arrives?
I'd be interested in seeing the same source implemented both ways, cold and shared/ref-counted, to understand what the API actually buys us.
Can subscriptions fail or cancel independently? If two subscribers are observing the same source, can one fail, cancel, or retry without affecting the other? Is there per-subscription teardown as well as controller-level teardown?
How does this work with higher-order composition? For example, if
switchMap()selects the same Observable again after a previous subscription completed or errored, does it get a fresh execution? Can we still freely reuse derived Observables?I think the main thing I'd want to establish is that this supports the same retrying, resubscription, sharing, and composition patterns we have today.
Do you have a more formal design I could review? Even some pseudocode describing the lifecycle would help.
I'm interested in exploring this. I just want to make sure we understand these cases before going too far with it.
keithamus commentedon Nov 7, 2026
Thanks for getting us back on track @benlesh.
This seems like a good requirement.
I agree. You can't get from shared back to cold without access to the underlying producer. I think this is another important requirement. The producer has access to the underlying producer, so it can offer different options.
I can see how that makes sense but I want to stress that Jake's examples are real gotchas, so I think we also have additional requirements.
So personally I see the following requirements:
subscribe()call should mean the same thing regardless of timing. Whether it joins or restarts shouldn't depend on whether a previous execution finished a few milliseconds earlier. Supporting evidence: Jake's "fetch race" and yourtake(3)example.This could be a good foundation to move forward with, but I think we should explicitly acknowledge these, so I'd ask if you agree with these 4 requirements. If not, let's discuss why, let's find counter-evidence, and let's try and build a different set of requirements. If you have other requirements you think I've missed, I'd like to hear them, but I'd encourage we follow the format of providing supporting evidence so we can ground them in truth rather than opinion (this isn't an accusation, I've not seen you present opinions as fact, but I think it's useful to explicitly call out the supporting evidence as I've done above).
With that said, assuming you agree with these requirements, I think cold-by-default with explicit sharing meets 1, and could meet 3 depending on if/how
share()is designed. However it doesn't meet 2 because duplicate work stays silent until someone remembersshare(), and as Jake pointed out the person callingshare()often isn't the person consuming the Observable. It also only partly meets 4: a producer can keep shared state in a closure, but the platform gives them no tools for it, so each library ends up rolling it's own policy (see the above tables).I also think Jake's design of
share()vsrestart()doesn't meet the requirements; it meets 1 and probably 3, but not 2 nor 4 (fundamentally).I'd like to stress that I'm not wedded to my proposal, it's really just a strawman to pursue the idea of "what does Observable look like if it had an eager revealing constructor just like the other primitives in the platform: Promises, Streams, etc". I haven't really thought that much past it, but...
The callback given to the constructor runs eagerly, once.
onSubscribe()would run with each new.subscribe()call, synchronously. Anything passed tocontroller.next()before there's a subscriber is dropped, the same as an event dispatched before you calladdEventListener.The
controlleris multicast, socontroller.complete()calls.complete()on every subscription, runs the controller's teardwon, and the controller is done. Any later.subscribe()completes immediately, much like a settled Promise.subscriptionis unicast, sosubscription.complete()ends just that subscriber. Errors work the same way.I haven't thought that far, but I think it depends on where you error:
subscription.error()only errors that subscription, sosource.catch(() => source)resubscribes,onSubscribe()runs again, and you get a fresh execution. Retrying works as it does today.controller.error()would multicast to all subscribers or so. Maybe resubscribing gets the error again? Then I guess to retry you'd call whatever made the Observable again:socketMessages(url).catch(() => socketMessages(url)). That's how you retry a Promise today.Maybe this is a bad design? Maybe it's okay, I'm not sure. I think it's has some interesting semantics but again that's just me kind of shooting from the hip. Happy to hear if it's bad.
Here's the same source both ways. Cold, which is the current subscriber callback nested one level down:
Shared and ref-counted, connecting on the first subscriber and closing on the last:
So developers have the expressive capabilities they (hopefully) already know, with closures and hoisted assignments. The refcounted example closes and completes when it reaches zero subscribers and later subscribers get an immediate completion, but if a producer wants to, it could instead reconnect with something like:
Initially I said I didn't think this was needed, but again this is a strawman, so, sure
subscription.addTeardown()could be added. This way a single subscriber aborting, erroring or completing doesn't touch the others.I guess "it depends" on how the source Observable was constructed. If I'm completely honest I think 5-10 years ago I had a good idea in my head what "higher-order composition" means but time is a cruel mistress so maybe I'm about to provide an incorrect answer...
I guess in this model higher-order operators like
mapwould be be implemented by making its own Observable, something like this:I think I'd need a minute to come up with what
switcMapwould look like. But anyway, as you can imagine this isn't explicitly introducing sharing, which only exists at the producer. So e.g.take(3)is per subscription, so on a cold source each subscriber gets the first three, and on a shared source each gets the next three from when it subscribed. Neither depends on what other subscribers do, but they do depend on what the producer does (if that makes sense...). And then subscribing to a derived Observables subscribes to upstream again, sofnruns per consumer. Whether that's a fresh execution is again up to the produce, not the operator.Woof, okay, that's a wall of text. Let me try to summarise:
benlesh commentedon Nov 7, 2026
Thanks for expanding on this, Keith. I think I have a better understanding of what you're proposing now, particularly the distinction between the controller broadcasting to everyone and individual subscriptions notifying their own observers.
I can see how this allows for both shared and independent execution. It's an interesting approach, but I do have some concerns about the added complexity.
A few questions:
controller.next/error/complete()andsubscription.next/error/complete()? It seems like getting that wrong could introduce some pretty subtle bugs, especially around termination.My bigger concern is what we're actually trying to solve here.
At the end of the day, #170 is a developer mistake. Someone subscribed twice to a cold Observable without realizing that would execute the producer twice. That's a predictable, well-established behavior, but it's also something people can get wrong.
I don't want to minimize that problem. We should absolutely try to make APIs harder to misuse. But I also think there's a point where trying to prevent one kind of mistake can introduce more complexity and create entirely new ways to get things wrong.
We're considering a significantly more complicated Observable model to address a "you're holding it wrong" class of bug. Now developers need to understand two notification scopes, different termination semantics, and how shared and independent execution interact. If the original model was confusing to some developers, I'm not convinced this one will be easier to understand.
The existing footgun is at least well understood, predictable, and relatively straightforward to address with sharing. My worry is that we could trade that for several new, more subtle footguns that nobody has encountered yet because this model hasn't had years of real-world use.
I'm not saying this approach can't work, and I appreciate the effort you're putting into exploring it. I'm just not convinced yet that we're reducing the opportunities for mistakes rather than moving them around.
keithamus commentedon Nov 7, 2026
Yeah I think your concerns are all valid. It pushes a lot more of the effects onto whoever is writing the producer.
I want to draw us back to the table above which shows that the current semantics aren't what developers expect, and if we go with one particular model we're not addressing the split. Sorry if this sounds circular but this seems important, and hasn't been refuted.
I think we're trying to find a design which eliminates some of the currently observed pit-falls so we can move this proposal forward. This is a lot of complexity to add to the platform and if we get it wrong, we sacrifice a large amount of engineering effort for something no one can use.
Perhaps we can get to the 4 requirements in my above comment? Do you think these hold?
benlesh commentedon Nov 7, 2026
I think we're mostly in agreement. I'd just qualify a couple of these:
Support both models: Agreed. Both cold and shared execution are important.
Consumers shouldn't have to opt into sharing: Agreed, but cold-by-default doesn't prevent this. The producer can share before handing the Observable to consumers.
Consistent
subscribe()semantics: I agree they should be predictable, but timing necessarily matters for shared sources, especially with refcounting. I think well-defined behavior is the more important requirement.Producer chooses policy: Generally agree. The producer knows the resource best, but downstream code should still be able to share an Observable without modifying its source.
I do think we need to consider more than these four, though.
I've been working on an inventory of Observable requirements and use cases. It's up to 93 items, although not all of those are hard requirements. Obviously that's far too much to dump into this thread.
There are some pretty important things we'd need to account for: synchronous cancellation, independent teardown, retry, higher-order composition, replay, framework integration, RxJS interoperability, etc.
I think we could boil those down to a much smaller set of requirements to evaluate designs against.
One thing I'd question about the table is whether it demonstrates that developers expect different semantics, or just that different libraries have chosen different policies for different use cases. I think that's an important distinction.
I'd really like us to make sure we're evaluating the whole design, including potential new footguns, rather than focusing too narrowly on the ones we already know about.
keithamus commentedon Nov 7, 2026
Yeah I agree. This is one thing we'll have to carefully thread: we need something which aligns with users expectations, while also ensuring we don't encode problematic patterns just because they're established. Super easy 😅.
I think your requirements list would be great to see.
jakearchibald commentedon Nov 8, 2026
Exactly. Especially as we know that "long established" hadn't resulted in folks knowing and getting used to the quirks of the design.
Like I said at TPAC, paving the cow paths is bad when we can see the path is on a cliff edge and the cows keep falling off.
benlesh commentedon Nov 8, 2026
I agree that established behavior isn't automatically good behavior. But I want to push back on the "cows keep falling off a cliff" characterization.
I've spent over a decade working with RxJS, maintaining it, and helping developers debug their applications. I've absolutely seen accidental duplicate subscriptions cause problems. But in my experience, it's not a particularly common bug. I haven't run across one of those bugs in years, personally.
Of course, that's anecdotal evidence too. And that's exactly my point.
We have conflicting anecdotal experiences, but no reliable evidence establishing how prevalent this problem actually is across the ecosystem.
I've tried to find that evidence, and so far I haven't found anything that supports treating this as a widespread, systemic failure of the Observable model. That doesn't mean it isn't happening. It means we haven't established the scale of the problem.
Meanwhile, the proposed alternatives introduce their own failure modes, some of which may be considerably harder to recognize or debug.
I'm not arguing that we should ignore known problems just because the behavior is established. I'm arguing that we should evaluate whether changing that behavior actually improves things overall.
I think Keith's suggestion to agree on requirements and evaluate the designs against them is the right direction. I'll work on polishing the requirements list I've put together, so we can iterate on it and come to some agreement, then use it to help adjust the design.
jakearchibald commentedon Nov 8, 2026
Everyone I've spoken to who works on large Rx codebases says they see folks get caught out by it. And, like you saw in the room at TPAC, folks unfamiliar with observables are really surprised by it.
I realise that's more anecdata, but by adding it to the platform we're pushing it to a large audience of folks that aren't already familiar with its footguns.
benlesh commentedon Nov 10, 2026
I've come up with a different proposal, #221. It's working off of some of the ideas @keithamus had. Apologies for the length, but I spent a long time trying to address every issue that we've brought up, as well as anything else I could think of, from my experience.