Reputation: 715
I often confused with pubsub design pattern versus protocol like websocket. When new jargon come like reactive programming I became even more confused. To me it's like WebSocket is a kind of pubsub, but I don't know beyond WebSocket if I want to explore more about pubsub pattern.
if it's frontend I don't have to use external library to do pubsub, because my state management of any framework like react 'is' already pubsub in a way..
My question is what is pubsub in javascript and what's the practicality of it
Upvotes: 3
Views: 4633
Reputation: 4214
Think of WebSockets as a transportation method, like a plane. It solves the problem of getting the client and server to talk in real-time (e.g. chat applications, notifications, etc). There are other methods like long-short polling (bus), or server-sent events (train).
PubSub is a design pattern on how pieces of a system communicate. It's like the subway/airplane system (think JetBlue, Delta Airlines, NYC Subway System, etc). Common tools to handle PubSub today are Kafka and Redis. Some Backend engineers can build an entire career out of designing well-architected, reliable PubSub systems. It can be a very difficult problem.
Reactive programming (RxJS) is a programming style, similar to how procedural/functional/declarative programming are all unique styles. It's usually used in highly interactive apps where the client needs to update in real-time based on multiple events (e.g. an online Bitcoin trading platform, or adding hotkeys to a webapp).
Upvotes: 4