Video in progress

Explain the trade-offs between moving WebSocket connections into a separate "edge" layer (such as Centrifugo or Pushpin) and holding them in the Spring app itself.

A separate edge layer makes backends stateless, decouples deploys from connections, and gives many teams one platform. The cost is a new component, coupling to its protocol and limits, and one more hop when debugging.

📖 Answer

There are two models.

Inside the app. The Spring app itself holds the connections with @EnableWebSocketMessageBroker. The good side is that everything is in one place: the security context, @MessageMapping, transactions. It's the fastest path for a small or mid-size system.

The problems show up at scale. Every time you deploy the app, all connections are cut. The app's memory profile now carries two kinds of load: business logic and connections. Scaling the app should be about CPU, not connections, but the two become tied together.

Separate edge. The gateway holds the connections, and backends say "send this to that channel" over plain HTTP or gRPC. The backend is stateless and is deployed like an ordinary REST service. Incoming messages from the client reach the backend through the gateway as HTTP requests.

Criterion Inside the app Separate edge
Deploy impact every deploy means a reconnect backend deploys don't touch connections
Number of teams convenient for one team can be shared as a platform
Flexibility full control limited by the gateway's capabilities
Operational load low one more system, and its upgrades

When picking an off-the-shelf solution I check three things: whether history/offset is supported on reconnect; how auth is done (JWT, proxy request); and what happens if the gateway goes down, whether clients can move to another node and recover their state.

Writing your own is also an option, but a "simple proxy" quickly grows into presence, history, rate limiting and metrics. Once two or three teams need real-time, I usually propose moving to a separate layer. With one team and one app, I keep it inside Spring.