๐๐ฑ๐ฑ ๐๐ถ๐๐ฒ ๐ก๐ผ๐๐ถ๐ณ๐ถ๐ฐ๐ฎ๐๐ถ๐ผ๐ป๐ ๐๐ถ๐๐ต ๐ฆ๐ฆ๐
Stop using WebSockets for simple notifications.
Most teams do it out of habit. You write too much code for reconnections. Server-Sent Events (SSE) work better for one-way alerts. You finish the feature in an afternoon.
SSE handles reconnections for you. The browser sends the last seen ID. The server sends missed alerts. This is free durability.
Make it production ready with these steps:
- Store every notification in a database.
- Use Redis to send alerts across servers.
- Send heartbeats every 15 seconds.
- Disable buffering in Nginx.
- Limit connections per user.
SSE is not for everything. It sends data one way. Use WebSockets for chat apps. Use SSE for alerts.
Source: https://dev.to/137foundry/how-to-add-live-notifications-to-a-web-app-with-server-sent-events-38o7