6

In the observer pattern, and similar, is there a meaningful difference between "subscribers" and "observers" in the wild, or in the lit? With RxJS and (functional) reactive programming, are the terms interchangeable?

5
  • 1
    If you say "subscriber" people will assume a pub-sub system. If you say "observer", they won't.
    – AakashM
    Nov 10, 2022 at 15:21
  • 2
    And how do both of those relate to ‘listeners’?
    – gidds
    Nov 10, 2022 at 19:12
  • 1
    Listeners also same, at least in Observer pattern Nov 10, 2022 at 19:45
  • @gidds In plain English, observation is active whereas listening can be done passively. One could argue that an observer is the one who actively observes (i.e. keeps open the link to the observed target), whereas a listener passively waits for the target to transmit the message (meaning that the target is the one who maintains the link to the listener). However, I very much doubt that people make such a subtle distinction in everyday communication.
    – Flater
    Nov 10, 2022 at 23:46
  • Just for clarification and for the sake of the question. Are you asking in RxJS context only or in general? If it's only in RxJS context, I think @Benjamin already answered Subscriber - Implements the Observer interface and extends the Subscription class.. If not, I found the answers to be a bit opinionated because they differ from framework to framework (see @Karl's answer)
    – Laiv
    Nov 11, 2022 at 13:17

3 Answers 3

11

Nearly all words used in programming are plain English terms that still retain all of their original semantics (or as much of it as applies to programming), since their purpose is to help English speakers explain technical concepts to other English speakers.


Example definitions of each term:

Subscriber (noun)

  • "a person, company, etc., that subscribes, as to a publication or concert series."
  • "a homeowner, apartment dweller, business, etc., that pays a monthly charge to be connected to a television cable service".
  • "a person who promises to donate a sum of money, purchase stock, etc."

Observer (noun)

  • "someone or something that observes."
  • "a delegate to an assembly or gathering, who is sent to observe and report but not to take part officially in its activities."

The definition leading to Observe (verb) has the following example definitions:

  • "to see, watch, perceive, or notice"
  • "to regard with attention, especially so as to see or learn something"
  • "to watch, view, or note for a scientific, official, or other special purpose"

The differences between the terms in English are that subscription tends to be either more deliberate, focused or proactive around a subject. Observation might involve less focus or be a more passive activity.


These terms clearly have overlapping semantics in English, with the term 'observe' being far more general and abstract. As Karl points out in his answer, they are often used interchangeably in contexts where any minor semantic differences between them aren't important, such as the example given in the question with ReactiveX.

In some specific contexts, there are more obvious reasons for choosing one term over the other, for example, the Publish-Subscribe messaging pattern uses 'subscriber' to convey the importance of each recipient needing to deliberately express an interest in receiving messages.

While a 'subscriber' could easily be described as an 'observer' in this pattern, the term has weaker connotations and intent. i.e. For a person described as an 'observer', it may simply not be important whether or not that person has actually expressed any particular interest in receiving some information. However, in the context of the messaging pattern, 'expression of interest' is an important, distinguishing feature.

As always, naming things is a hard thing to do - people who choose between names like Observer or Subscriber need to think long and hard about context. A word which is too general just risks losing the audience through lack of clarity or purpose. A word which is already loaded with specific connotations risks misleading the audience if those connotations don't match the technical concept.

5
  • I also have the feeling that the term "subscriber" is used more often in contexts where there is a central messaging system (EventBus, MessageBus) where one can subscribe to messages/topics/events, while observer is more often used in cases where observers are attached to an observed entity directly.
    – Polygnome
    Nov 10, 2022 at 11:13
  • Is there not a difference in delivery guarantee where a subscriber is a sub-set of all observers with that specific guarantee of delivery? A subscriber is guaranteed to 'see' all observable events for the duration of the subscription. An observer without a subscription has no such guarantee. I'd liken it to visiting a comc store and picking up the comic you've subscribed to every week but sometimes missing an issue of one you're not subscribed to. In tech that might translate to a connection failure meaning an observer misses an event but a subscriber would have that event queued.
    – melkisadek
    Nov 10, 2022 at 12:08
  • @melkisadek Each person's expectations may be different, but personally I wouldn't expect an 'Observer' abstraction to be forced into taking responsibility for missed events, since that implies they would need to be involved in correcting the problem, possibly even communicating back to the event's origin (therefore no longer 'just' being an observer). That seems like a Leaky Abstraction; where I'd hope a lower-level detail elsewhere would already have it covered, allowing the observer to remain fairly passive. Nov 10, 2022 at 20:41
  • I was thinking more about the English Language difference between Observer & Subscriber. Both are essentially passive but a subscription needs setting up and I would expect access to the thing subscribed to for the duration of the subscription (magazine issues or Sky TV channels). An Observer would only expect to see what was available at the moment of observation (e.g. Library books that haven't been loaned out or Freeview TV channels). As @Laiv mentions in his comment on the question, once you bring actual framework implementations into it, it quickly becomes opinionated.
    – melkisadek
    Nov 11, 2022 at 16:06
  • @melkisadek That's what I mean by "expressing an interest" being of importance in the context of the publish-subscribe pattern. However for the concept of an observer, whose dictionary definitions are pretty abstract and highly context-dependent, I don't personally see any clear link or connotation with reliability -- that seems to me like something which would depend entirely on specific context and not something belonging to the general observer concept. Nov 11, 2022 at 17:23
6

The terms are mostly interchangeable, but there are subtle differences in specific implementations. For example, a Monix Subscriber is described as "an Observer with an attached Scheduler." I don't believe that's a universal distinction, though, just one of those difficult naming problems of programming where it's more convenient to use a synonym than an annoying compound name like ObserverWithScheduler.

1

In Rx speak an Observer is something that can get notifications from a data source and a Subscriber is an observer that can also unsubscribe from that source.

Subscriber - Implements the Observer interface and extends the Subscription class. While the Observer is the public API for consuming the values of an Observable, all Observers get converted to a Subscriber, in order to provide Subscription-like capabilities such as unsubscribe. Subscriber is a common type in RxJS, and crucial for implementing operators, but it is rarely used as a public API.

That's just Rx terminology - in a regular programmer discussion the terms are interchangeable even if they have slightly different but similar meanings a bit like arguments and parameters.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.