Realtime event delivery via service worker
Realtime event delivery via service worker and BroadcastChannel
Section titled “Realtime event delivery via service worker and BroadcastChannel”The app needed realtime event surfacing (toasts + sounds) when new events arrive via the API. We considered SSE from SvelteKit, polling from the browser, and WebSocket from Hono. We chose to extend the existing Web Push infrastructure: the service worker receives push notifications (already delivered per-event), then broadcasts event data to the main app via BroadcastChannel instead of building a new delivery channel.
Why not SSE/polling/WebSocket: Adding a new realtime channel would require cross-process fan-out (Hono to SvelteKit) and persistent connections per user. The service worker already receives every event via push. Reusing it avoids new infrastructure entirely.
Fallback for closed tabs: If no app tab is open when a push arrives and the device is configured for toast-only mode, the service worker falls back to showing a system push notification. This prevents lost events.
Status: accepted