Overview
Motia provides built-in support for real-time data streaming using Server-Sent Events (SSE) and WebSocket-like streams. This enables you to push updates to clients as they happen.Server-Sent Events (SSE)
SSE is perfect for one-way server-to-client streaming, like live updates, progress notifications, or streaming AI responses.SSE with Python
You can also build SSE endpoints using Motia’s Python SDK:steps/sse_step.py
Streaming AI responses
SSE is ideal for streaming LLM responses to clients:steps/ai-chat.step.ts
Real-time state streams
Motia provides built-in state streams for real-time data synchronization:steps/todo.stream.ts
steps/create-todo.step.ts
Progress updates
Stream progress updates for long-running operations:Best practices
Set proper headers
Always set
content-type: text/event-stream and cache-control: no-cache for SSE.Handle client disconnects
Check connection status periodically. Clean up resources when clients disconnect.
Send heartbeats
Send periodic ping events to keep connections alive and detect disconnects.
Limit concurrent streams
Monitor and limit the number of concurrent streaming connections per client.
Next steps
AI Integration
Build AI-powered workflows with streaming responses
Multi-language
Mix TypeScript and Python in one project