Why did you choose WebSocket instead of SSE? Why is two-way communication needed if the frontend does not send data to the server?
sobes.tech AI
Answer from AI
WebSocket was chosen over SSE because it provides full-duplex communication between the client and server. Even if the frontend is not currently sending data to the server, having a two-way channel allows for easy expansion of functionality in the future — for example, for acknowledgments, pings, sending commands, or requests from the client.
SSE (Server-Sent Events) is a one-way channel from the server to the client, which is suitable for simple notifications but does not support sending data from the client through the same channel. WebSocket, on the other hand, opens a persistent connection, allowing both parties to exchange messages in real-time without the overhead of establishing new HTTP connections.
Thus, WebSocket provides flexibility and scalability of the architecture, even if the frontend is not currently sending data to the server.