Via Server-Sent Events (SSE)
Restate has a TypeScript library to implement streaming updates from Restate services to frontends via SSE. You can use this, for example, to stream agent updates to your chat UI.restatedev/pubsub
Explore the library.
nextjs-example-app
NextJS Chat app backed by an AI SDK Agent that streams updates using SSE.
Register the pubsub object
Publish messages from your service
Use the pubsub client to publish messages:Note that the UUID, in the publish step, is an idempotency key that Restate will use to deduplicate events.
This is necessary since this publish step goes via the Restate ingress.
Without this idempotency key, each replay/retry leads to duplicate events.
Alternatively, you can use service-to-service calls to publish events.
restate/services/agent.ts
Create an SSE endpoint
For example for NextJS, create an API route that streams pubsub messages:
app/pubsub/[topic]/route.ts
Subscribe from the frontend