Log in deeper to WebSockets and their role in Customer server communication | by Clara Chong | Feb, 2025

How website performance works, its trading, and how to design the messaging app in real time

Real time communication throughout the area – live chatbots, data distribution, or instant messages. WebSockets with a powerful power of this, but when should you use it? How do they work, and how do they differ from traditional HTTP applications?
This article was inspired by the latest conversation of app – “Create real messaging app” – where I stumbled. Now that I have finished the depth, I like to have a share, to avoid the same mistakes.
In this article, we will examine how websites we get into the main photo of customer service. We will discuss what they do well, where they fell, and – yes – how to designate real-time messaging app.
Its spine, customer service delivery for information from two structures: client and server.
Data client requests, and the server processes these requests and returns the answer. These roles do not specially – services can serve as a customer and server at the same time, according to context.
Before you enter information of WebSockets, let's take a step back and check the big picture of customer communication methods.
1. Short voting
A short ballot is a simple, caring way.
The client also sends http applications to time period (eg every few seconds) to look at new data. Each application is one and one code (client → server).
This method is easier to set but can spill app when the server is rarely with new data. Use it for critical applications for a little time when voting from time to time is sufficient.
2. The long vote
A long ballot is a short polling, which is designed to reduce the amount of unnecessary applications. Instead of the immediate response of a client request, server keeps the connection open until the new data is available. When the server has detail, sending a response, and the client is quick-establishing new communication.
Voting is too long with what they including One-handed (Client → server).
The standard example is a Red-Hainding riding system, where the client is waiting for the parallel or booking update.
3. The Book
Webook inserts the script by making the server first. The server sends HTTP Post Requests for the endpoint specified by clients in which certain incidents occur.
Each request independent and does not rely on continuous connection. Webooks also One-handed (client server).
Weapon are widely used with asynchronous notices, especially when includes third party services. For example, billing systems use Webooks to inform clients in the form of change changes.
4. Server-sentences to events (SSE)
SSES are a Protest HTPT Center Allowselp servers to push real time updates to customers inside one, Continuous Communication.
SSE works using EventSource
API, makes it easy to use modern web applications. It is One-handed (client server) and ready for situations where the client only needs to get updates.
SSE is ready for proper use of applications such as trading platforms or live sports updates, when the server draws data as a stock price or score. The client does not need to send data back to the server in these cases.
But what about two ways in connectioning?
All the above methods focus on one bathroom. With real exchange, real time, we need a different way. This is where websocket are shone.
Let's get in.
Websites that empower Real-Time, Bidirectional CommunicationYou made them organize apps such as chat apps, live notifications, and online play. Unlike the HTTP Response model, websocket created a persistent Communication, where both clients and server can send messages independently without waiting for the application.
The first connection as a regular HTTP application and developed in the WebSocket connection with work together.
Once created, using one TCP connection, which works in the same ports and HTTP (80 and 443). Messages sent over websocockets are small and lightweight, and make them function properly with low latency, highest use charges.
WSSocket connection Follow some URI format: ws://
by a regular connection and wss://
Safe connections, crucified.
What is handaged treatment?
Supply is a process of It starts to contact between two plans. On websites, starting with HTTP to request from the client, ask for the Protocol Development. This ensures compatibility with HTTP infrastructure before converting to the ongoing WebSocket connection.
- The client sends a request, and the topics are:
GET /chat HTTP/1.1
Host: server.example.com
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
Origin: http://example.com
Sec-WebSocket-Protocol: chat, superchat
Sec-WebSocket-Version: 13
Upgrade
– Signals Application to change the protocolSec-WebSocket-Key
– Randomly produced, base64 string used for shipping verificationSec-WebSocket-Protocol
(Optional) – List of subprotocols support clients, allowing server to select one.
2. The server reply
If the server supports websockets and agree to the development, responding with Transformation Policies The situation. The articles of the example:
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=
Sec-WebSocket-Protocol: chat
Sec-WebSocket-Accept
– Base64 is installed by the client hashSec-WebSocket-Key
with a guid. This ensures that manual management is secure and permissible.
3. Handshake Verification
By 101 Switching Protocols
The answer, the Web connection is successfully established and both clients and server can begin to exchange messages at the real time.
This connection will always be open until the closest of which party is.
If there is a code other than that 101
Returns, Client should end in connection with the WebSocket exploitation will fail.
Here is a summary.
We talked about how websites we give to the last time, BidirectionCational communication, but that's still the best time. Let's submit certain real examples.
WebSockets are widely used in real-time cooperation tools and conversational programs, such as Exceridraw, Telegraph, WhatsApp, Google Maps, Live Live Live Stream or Tiktok Live Streak.
1. Having a plan of cash fall if communication is terminated
WebSockets are not recovering automatically when communication is terminated due to network problems, server crash, or other failure. The client should see clearly shortcut and attempt to reset communication.
Vote of long often used as a backup while the WebSocket connection is trying to reinstate.
2. Not provided to broadcast audio and video data
Websocket messages are designed to send Small, organized, orderly messages. Spreading large media data, technology such as WebRTC is better suited for these conditions.
3
WebSockets senselesswhich means the server must preserve effective connections to all clients. This makes horizontal measures more complicated compared to HTTP, where the server can handle a client request without keeping the state.
You will need additional layer of PUB / SUBs to do this.
Let us now consider how this applied to the system's construction. I've covered a simple (informal) solution and a horizontal scale.