Skip to main content
Streaming allows you to send intermediate results from your distributed workers back to the client in real-time. This is particularly useful for long-running operations like image generation, video creation, or model training where users benefit from seeing progress updates.
For a complete working example of streaming with multi-GPU inference, see the Parallel SDXL Tutorial.

How Streaming Works

With fal.distributed, you can stream results from workers during execution:

Basic Streaming Example

1. Stream from Workers

In your DistributedWorker, use add_streaming_result() to send intermediate results:
Key points:
  • add_streaming_result(): Sends data to the client
  • as_text_event=True: Formats as Server-Sent Events (SSE)
  • Only rank 0 should stream to avoid duplicate messages

2. Create Streaming Endpoint

Define an endpoint that returns a StreamingResponse:

3. Consume Stream from Client

JavaScript/TypeScript:
Python:
If your endpoint uses a path other than /stream, specify it with the path parameter to match your @fal.endpoint() decorator.

Advanced: Streaming with Gather

Stream intermediate results from all GPUs and combine them:

Best Practices

1. Stream Only from Rank 0

Avoid duplicate messages by only streaming from the main worker:

2. Throttle Stream Frequency

Don’t stream on every iteration - use intervals:

3. Use Synchronization

Synchronize workers after streaming to maintain consistency:

4. Keep Payloads Small

Stream minimal data for responsiveness:

5. Handle Images Efficiently

For streaming images, use base64 encoding:

Complete Example

See the Multi-GPU Inference Tutorial for a complete working example with streaming, including:
  • Real-time preview generation
  • Progress updates every 5 steps
  • Gathering results from multiple GPUs
  • Progressive blur effects during generation

Next Steps

Multi-GPU Inference Tutorial

Complete streaming example with SDXL

Real-time Endpoints

Learn about fal’s real-time framework