Glossary
Observer Pattern
An object that keeps a list of interested parties and tells them when something changes. Every event listener, event emitter and reactive UI framework is a version of it, and so is the callback a chat SDK fires when a message arrives.
General definition
Observer Pattern is one of the original “Gang of Four” design patterns. A subject exposes methods to attach and detach observers; when the subject’s state changes it iterates over its observers and calls each one, usually passing the new state or a description of the change. The subject depends only on the observer interface, so new observers can be added without modifying it, and observers can be removed when they no longer care, which also prevents leaks. The pattern is in-process, synchronous by default and one-to-many.
You use it constantly without naming it:
addEventListeneron a DOM element andEventEmitterin Node.js are observer registries keyed by event name- RxJS Observables, Kotlin Flow and Swift Combine are the pattern generalised into streams with operators for mapping, filtering and merging
- React state:
useStateanduseEffectmake a component an observer of its own state, anduseSyncExternalStorelets a component observe a store that lives outside React; see React hooks. Libraries such as Redux and Zustand are subjects whose observers are components - Database change streams and
MutationObserverapply it to data and to the DOM
The pattern is often confused with pub/sub, and the difference is the middleman. In observer, the subject holds direct references to its observers and calls them itself. In pub/sub, publishers send to a topic on a broker and never see subscribers; delivery is asynchronous, usually across processes or machines, and can be persisted and retried. Observer is the right tool inside one program, pub/sub between programs. Many systems chain them: a message arrives from a broker over a socket, and an in-process emitter notifies the UI.
Two things go wrong in practice. Observers that are never detached keep the subject from being garbage collected and keep reacting to a screen the user has left, which is why React effects return a cleanup function. And observers that do heavy or asynchronous work inside the notification make the subject slow or reentrant; the fix is to schedule the work rather than run it inline.
Working in React? The open-source Ethora React chat SDK adds real-time messaging, group chat and file sharing to a web app.
In the Ethora ecosystem
A chat SDK is an observer registry in front of a network connection. In Ethora’s React and React Native components, the client holds a WebSocket connection to the XMPP server; incoming stanzas for messages, reactions, read receipts, typing and presence update the component’s state, and React re-renders the rooms and message lists that depend on it. The native iOS and Android SDKs follow the same shape with the platform’s own callback and delegate conventions. Your application works one level up, through the component’s props and configuration and the REST API, rather than by wiring XMPP listeners yourself.
Server-side consumers of the same events, for example an AI agent attached to a room or your own backend receiving moderation reports, are the pub/sub half of the design: delivered asynchronously, persisted and retried. Keeping the two halves distinct is what lets the UI stay responsive while the heavy work happens elsewhere.