Urgent.News

What's breaking now, across thousands of outlets.

Tech

Server-Sent Events Across Multiple Pods: Redis Pub/Sub + Spring WebFlux

This article was originally published on Jo4 Blog . We replaced our notification-bell polling with Server-Sent Events. On a single pod, this is easy — Spring WebFlux + a Flux of events, done in 30 lines. On multiple pods, it gets interesting fast: a write that happens on pod A needs to reach a subscriber on pod B, and naively, it doesn't. Here's the full pattern: how the SSE endpoint is shaped,…

The article discusses implementing Server-Sent Events (SSE) across multiple pods using Redis Pub/Sub and Spring WebFlux. On a single pod, this is straightforward - a Spring WebFlux + Flux of events can handle it in just 30 lines of code. However, when dealing with multiple pods, the process becomes more complex as a write on pod A needs to reach a subscriber on pod B.

The authors outline the full pattern, starting with the SSE endpoint that emits the current unread count on subscribe and providing live updates whenever the count changes. The endpoint is defined with a GET mapping to "/stream" and produces text/event-stream data type. The initial emit on subscribe includes the current count, allowing clients to receive the answer immediately without a separate REST round-trip for first paint.

To keep the connection alive through any proxy/CDN idle timeout, the authors include heartbeat events every 30 seconds. They also set X-Accel-Buffering to "no" to prevent reverse proxies from buffering responses, which would defeat the purpose of the streaming approach.

The stream lives for 30 minutes before the server hangs up, forcing the client to reconnect with a fresh JWT. This handles mid-stream token expiry without requiring the authors to invent their own re-validation logic. The per-user sink is created lazily through the notificationEventBus.subscribe(userId) call, which returns a Flux of NotificationStreamEvent. New subscribers latch onto the same sink, and the sink is removed when the last subscriber unsubscribes.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Samsung Galaxy Buds 4 Pro Wins EISA Honor

Samsung Electronics’ wireless earphones, the ‘Galaxy Buds 4 Pro’, have been recognized for their technological prowess by the Expert Imaging and Sound Association (EISA).

  • Samsung Galaxy Buds 4 Pro wins EISA award for best in-ear headphones.
  • Galaxy Buds 4 Pro features high-fidelity sound, clear calls, and 20% larger speaker area.
  • Device utilizes real-time ear shape analysis and sensor fusion for enhanced call quality.

JDK 27 and JDK 28: What We Know So Far

JDK 27, the second non-LTS release since JDK 25, has reached its first release candidate phase featuring a final set of nine new features, in the form of JEPs, that can be separated into four…

More from Monday 24 August →