-
Communication Client → Server
-
Communication Server → Client
- Push notifications - Apps
- Long-polling
- WebSockets
- GraphQL pub/sub - another mullet
- Server Sent Events
-
Push notifications
- Apps - mobile
- Browsers
- Can be disabled
- Not event-driven
-
Long-polling
- Old technic
- Not performative
- Can increase costs
- Not event-driven
-
WebSocket
- New protocol
- Bi-directional
- Event driven
- Proxy problems - enterprise firewalls
-
Server Sent Events
- Based on HTTP
- Event driven
- Reconnection and event id by default
- No problems with proxy and firewalls
- Just one direction - Server → Client
- Only UTF-8
Examples:
- WebSockets
- Chat
- Multiplayer games
- Collaborative editing and coding
- SSE
- Stock ticker streaming
- Notifications
- Twitter feed updating
Disclaimers:
- Almost everything can be done on both, WebSockets and SSE
Let's code...
- Ping example - https://v2-sse-mullet.vercel.app/ping
- Notifications example
- Client: https://v1-sse-mullet.vercel.app/
- Send notifications: https://v1-sse-mullet.vercel.app/send-notification
- Notifications smarter example
- Client: https://v2-sse-mullet.vercel.app/
- Send notifications: https://v2-sse-mullet.vercel.app/send-notification