Tuesday, February 23, 2021

System design | WebSockets | WebSockets Connector - Mule 4 | Google search | Images

Feb. 23, 2021

Introduction

It is important for me to read more about websockets. I like to be an architect one day. How can I do it without hands-on experience? I will figure out how to learn better by reading articles. 

WebSockets | WebSockets Connector - Mule 4

  1. Establishes bidirectional and full-duplex communication between a server and client
  2. Implements server push notifications

  3. Seamlessly works on top of an existing HTTP infrastructure

  4. Avoids the need for clients to regularly poll the server for new data

Keywords: bidirectional, full-duplex communication, HTTP infrastructure, on top of HTTP infrastructure, poll the server

Full-Duplex communication vs half-duplex (unidirectional) - request-response message exchange pattern 

In traditional HTTP, a connection is half-duplex (unidirectional) and works by using a request-response message exchange pattern:

  1. A client connects to a server and sends a request.

  2. The server processes the request and sends a response back. The connection ends after the client receives the response.

Traditional HTTP connections require vast overhead because the client app is blocked until it receives a response from the server. Also, with this type of connection, the client must always initiate the request. Therefore, the server cannot push notifications to multiple apps at one time.

When a client connects to a server using WebSockets, a persistent connection is established and kept open. Both the client and server can then send multiple messages to each other without needing to follow the HTTP request-response message exchange pattern.

A WebSocket is built on top of the existing HTTP infrastructure, making it easy to reuse infrastructure that is already in place for traditional HTTP.


Keywords: persistent connection, keep open, HTTP request-response message exchange pattern, client must always initiate the request, the server cannot push notifications to multiple apps at one time, the client app is blocked until it receives a response from the server

Chat Apps

In a chat app, as soon as a client sends a message to a chat group, subscribed participants want to receive that message immediately. If an app uses HTTP, the clients must constantly poll the server for available messages, which slows performance. With WebSockets, the server can push the available message to all subscribed users.

Stock Quotes Apps

Clients can open a WebSocket to a stock quote service, which continuously sends updated prices for a set of stocks. Because such prices change continuously, the ability to reuse the same connection and receive messages at random times make WebSockets an ideal solution for this problem. In this case, the client doesn’t send messages to the server after the connection has been established.


No comments:

Post a Comment