Scheduled websocket push with Springboot
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Scheduled WebSocket push in Spring Boot is a common pattern when clients need periodic updates without polling over HTTP. The usual design is simple: enable scheduling, publish messages on a schedule, and deliver them to subscribed clients through Spring's WebSocket messaging support. The real work is choosing the right destination structure and making sure scheduled jobs do not overwhelm connected sessions.
Configure WebSocket Messaging
The most common Spring Boot setup uses STOMP over WebSocket with a simple broker.
With this setup, clients can subscribe to destinations such as /topic/status.
Enable Scheduling and Push Periodic Messages
Next, use @Scheduled together with SimpMessagingTemplate to publish updates.
And enable scheduling in the application:
That is enough for periodic server push.
Keep the Payload and Destination Design Clean
Scheduled pushes often start small and then grow. A useful pattern is:
- use one topic per data family
- keep payloads compact and versionable
- avoid sending the same heavy message to everyone if only a few users need it
If updates are user-specific, consider destinations scoped by user or account rather than broadcasting globally.
Consider the Scheduler's Runtime Behavior
A scheduled push method runs whether or not clients are actively listening, unless you add your own guardrails. For lightweight status messages that may be fine. For heavy queries or large payload generation, it is worth checking whether the schedule should be conditional or whether the data should be cached and reused across subscribers.
That distinction becomes important as soon as the push job depends on database reads or external APIs rather than constant in-memory data.
Know When Scheduling Is the Wrong Trigger
A scheduled push is appropriate for periodic status snapshots, clock-like updates, or summarized metrics. It is not always the best fit for event-driven data. If the server already knows exactly when data changes, pushing immediately from the domain event is often better than waiting for the next scheduled tick.
The right question is not "can I schedule it". The right question is "should this update be periodic or event-driven".
Client Subscription Example
A typical JavaScript STOMP client subscribes once and then just listens:
From the client side, scheduled push looks the same as any other server-sent WebSocket message.
Common Pitfalls
- Using scheduled pushes for data that should really be emitted on demand or on domain events.
- Broadcasting large payloads to all clients when only some clients need them.
- Forgetting to enable scheduling, which makes the publisher appear broken.
- Mixing REST and WebSocket destination design without a clear message contract.
- Sending updates too frequently and creating unnecessary load on both server and browser clients.
Summary
- Scheduled WebSocket push in Spring Boot usually combines
@EnableSchedulingwithSimpMessagingTemplate. - STOMP destinations such as
/topic/...make periodic broadcast easy. - Choose topic structure and payload size carefully before the feature grows.
- Use scheduled push for periodic data, not as a default replacement for event-driven updates.
- The server side is simple once scheduling, broker config, and destination design are aligned.

