Data streaming

Build real-time features over websockets with type-safe Dart streams: return a Stream from a server endpoint and listen to it in Flutter, with no manual socket handling or serialization.

Get Started

Typed streams

Live features usually mean managing raw websocket connections, reconnection logic, and JSON framing on both the server and the client. That is a lot of connection code to maintain, and easy to get wrong.

Serverpod turns a websocket into a typed Dart stream. The server yields model objects; the client awaits them with a plain await for loop; and the framework handles transport, serialization, and reconnection.

How it works

1Create a Stream from an endpoint

Return a Stream and yield typed objects as they arrive.

class ChatEndpoint extends Endpoint {
  Stream<ChatMessage> subscribe(Session session, int roomId) async* {
    yield* session.messages.createStream<ChatMessage>('room-$roomId');
  }
}

2Listen in Flutter

The generated client exposes the same stream, type-safe end-to-end.

await for (var message in client.chat.subscribe(roomId)) {
  setState(() => _messages.add(message));
}

3Post updates to the channel

Post from anywhere on the server, and set global to reach subscribers on every server in your cluster.

await session.messages.postMessage('room-$roomId', message, global: true);

Endpoint streams

Any endpoint can return a Stream of your models, and the client receives them as a typed Dart stream, with serialization handled for you.

Two-way streaming

Endpoints can also accept streaming parameters, so the client can push a live stream of input to the server in the same endpoint method.

Cluster-wide messaging

The messaging API lets one server broadcast to subscribers on every other server, which is how you fan out live updates at scale.

Everything included

Typed Stream endpoints
Streaming method parameters
Publish and subscribe messaging
Cluster-wide broadcast
Automatic serialization
Typed exceptions over streams
Sessions, auth, and keep-alive built in

Why Serverpod

Full-stack type safety. The stream carries your generated models, checked at compile time on both ends.
Open source. Run the websocket server anywhere Dart runs, with no proprietary real-time service.
Zero-configuration deployments. Ship streaming endpoints to Serverpod Cloud with no extra setup.

Works with

Redis Postgres

Frequently asked questions

Does Serverpod support websockets?

Yes. Streaming endpoints run over websockets, exposed to your app as typed Dart streams.

How do I push real-time updates to a Flutter app?

Return a Stream from an endpoint and await it in the client; new values arrive as the server yields them.

Does it support publish and subscribe messaging?

Yes. The messaging API broadcasts between sessions and across every server in your cluster.

Can the client stream data to the server?

Yes. Endpoints can accept streaming parameters, so input can flow in both directions.

When should I not use this?

For simple request-response calls, a standard endpoint method is simpler. Streams are for continuous, real-time updates.

Stay up-to-date

Our mailing list keeps you up-to-date with new Serverpod releases and features. You will get an email about once a month or when something big is happening. We promise to keep it relevant and we have a strict no-spam policy.

© 2026 Serverpod AB
Built with Serverpod - Hosted on Serverpod Cloud