0

I have read a number of articles describing how websockets and pub sub architectures work at a high level.

I get that with websockets a connection is persisted between a client and a server to send and receive messages bidirectionally.

I also understand that with a pub-sub architecture, a sub can subscribe to a topic and receive messages that a pub publishes to that topic.

However, how does a subscriber or in the case of a websocket connection the server/client know when a new message is received? Are the server and client constantly checking for new messages using something like short polling over that connection? Does a subscriber constantly poll the topic? I haven't found a resource yet that explains this underlying functionality and how it works.

1 Answer 1

0

Publish/subscribe is an architecture pattern that can be implemented in different ways, both with subscribers that "pull" or with publishers that "push" (in some cases even both.. e.g. with Apache Kafka the producer will push messages to the topic, and subscribers pull new messages from the topic).

Websockets are a specific transport, a technical protocol, that can be used in different ways, not only for publish/subscribe. A websocket connection is a long-lived, bi-directional connection between two parties, where both ends are listening. There is no polling involved here, both sides can send frames to the socket and receive frames from it at any time while the connection is alive.

You'll find all the details about how the communication works in RFC 6455, and a detailed description on Wikipedia.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.