Skip to content

Commit 30ea2c7

Browse files
committed
Updated realtime docs to be much clearer
1 parent a9275d0 commit 30ea2c7

File tree

12 files changed

+142
-77
lines changed

12 files changed

+142
-77
lines changed

docs/docs.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@
137137
"realtime/run-object",
138138
"realtime/auth",
139139
{
140-
"group": "React hooks (frontend)",
140+
"group": "React hooks",
141141
"pages": [
142142
"realtime/react-hooks/overview",
143143
"realtime/react-hooks/triggering",

docs/realtime/backend/overview.mdx

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
---
2-
title: Backend overview
2+
title: "Subscribe to tasks from your backend"
33
sidebarTitle: Overview
4-
description: Using the Trigger.dev realtime API from your backend code
4+
description: "Subscribe to run progress, stream AI output, and react to task status changes from your backend code or other tasks."
55
---
66

77
import RealtimeExamplesCards from "/snippets/realtime-examples-cards.mdx";
88

9-
Use these backend functions to subscribe to runs and streams from your server-side code or other tasks.
9+
**Subscribe to runs from your server-side code or other tasks using async iterators.** Get status updates, metadata changes, and streamed data without polling.
1010

11-
## Overview
11+
## What's available
1212

13-
There are three main categories of functionality:
14-
15-
- **[Subscribe functions](/realtime/backend/subscribe)** - Subscribe to run updates using async iterators
16-
- **[Metadata](/realtime/backend/subscribe#subscribe-to-metadata-updates-from-your-tasks)** - Update and subscribe to run metadata in real-time
17-
- **[Streams](/realtime/backend/streams)** - Read and consume real-time streaming data from your tasks
13+
| Category | What it does | Guide |
14+
|---|---|---|
15+
| **Progress and status** | Subscribe to run status, metadata, and tag changes | [Progress & status](/realtime/backend/subscribe) |
16+
| **Streaming data** | Read AI output, file chunks, or any continuous data from tasks | [Streaming](/realtime/backend/streams) |
1817

1918
<Note>
20-
To learn how to emit streams from your tasks, see our [Realtime Streams](/tasks/streams) documentation.
19+
To learn how to emit streams from your tasks, see [Streaming data from tasks](/tasks/streams).
2120
</Note>
2221

2322
## Authentication

docs/realtime/backend/streams.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
---
2-
title: Streams
3-
sidebarTitle: Streams
4-
description: Read and consume real-time streaming data from your tasks in your backend
2+
title: "Stream data to your backend (AI, files)"
3+
sidebarTitle: "Streaming"
4+
description: "Read AI/LLM output, file chunks, and other streaming data from your Trigger.dev tasks in backend code."
55
---
66

7-
The Streams API allows you to read streaming data from your Trigger.dev tasks in your backend code. This is particularly useful for consuming AI/LLM outputs, progress updates, or any other real-time data that your tasks emit.
7+
**Read streaming data from your tasks in backend code.** Consume AI completions as they generate, process file chunks, or handle any continuous data your tasks produce.
88

99
<Note>
10-
To learn how to emit streams from your tasks, see our [Realtime Streams](/tasks/streams) documentation. For frontend applications using React, see our [React hooks streams documentation](/realtime/react-hooks/streams).
10+
To emit streams from your tasks, see [Streaming data from tasks](/tasks/streams). For React components, see [Streaming in React](/realtime/react-hooks/streams).
1111
</Note>
1212

1313
## Reading streams

docs/realtime/backend/subscribe.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
2-
title: Subscribe functions
3-
sidebarTitle: Subscribe
4-
description: Subscribe to run updates using async iterators
2+
title: "Progress and status updates (backend)"
3+
sidebarTitle: "Progress & status"
4+
description: "Subscribe to run status changes, metadata updates, and tag changes from your backend code using async iterators."
55
---
66

7-
These functions allow you to subscribe to run updates from your backend code. Each function returns an async iterator that yields run objects as they change.
7+
**Subscribe to runs from your backend and get updates whenever status, metadata, or tags change.** Each function returns an async iterator that yields the run object on every change.
88

99
## runs.subscribeToRun
1010

docs/realtime/how-it-works.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
2-
title: How it works
3-
sidebarTitle: How it works
4-
description: Technical details about how the Trigger.dev Realtime API works
2+
title: "How Realtime works"
3+
sidebarTitle: "How it works"
4+
description: "Technical architecture behind Trigger.dev's real-time run updates, built on Electric SQL and PostgreSQL syncing."
55
---
66

77
## Architecture

docs/realtime/overview.mdx

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,66 @@
11
---
22
title: Realtime overview
33
sidebarTitle: Overview
4-
description: Using the Trigger.dev Realtime API to trigger and/or subscribe to runs in real-time.
4+
description: "Subscribe to run state changes (status, metadata, tags) in real time from your frontend or backend."
55
---
66

7-
Trigger.dev Realtime allows you to trigger, subscribe to, and get real-time updates for runs. This is useful for monitoring runs, updating UIs, and building real-time dashboards.
7+
**Realtime subscriptions let you watch run state as it changes: status transitions, metadata updates, and tag changes.** You get the full [run object](/realtime/run-object) pushed to your code whenever something changes. No polling.
88

9-
You can subscribe to real-time updates for different scopes of runs:
9+
For streaming continuous data from tasks (AI completions, progress chunks, file data), see [Streams](/tasks/streams). Streams and Realtime work together but solve different problems.
1010

11-
- **Specific runs** - Monitor individual run progress by run ID
12-
- **Runs with specific tags** - Track all runs that have certain [tags](/tags) (e.g., all runs tagged with `user:123`)
13-
- **Batch runs** - All runs within a specific batch
14-
- **Trigger + subscribe combos** - Trigger a task and immediately subscribe to its run (frontend only)
11+
## How is Realtime different from Streams?
1512

16-
Once subscribed, you'll receive the complete [run object](/realtime/run-object) with automatic real-time updates whenever the [run changes](/realtime/how-it-works#run-changes), including:
13+
| | Realtime subscriptions | Streams |
14+
|---|---|---|
15+
| **What it sends** | Run state (status, metadata, tags) | Arbitrary data you define (AI tokens, progress, files) |
16+
| **When it updates** | On state changes | Continuously while the task runs |
17+
| **Typical use case** | Progress bars, status badges, dashboards | AI chat responses, live logs, file processing |
18+
| **React hook** | [`useRealtimeRun`](/realtime/react-hooks/subscribe) | [`useRealtimeStream`](/realtime/react-hooks/streams) |
19+
| **Define in task code?** | No, automatic | Yes, using `streams.define()` |
1720

18-
- **Status changes** - queued → executing → completed, etc.
19-
- **Metadata updates** - Custom progress tracking, status updates, user data, etc. ([React hooks](/realtime/react-hooks/subscribe#using-metadata-to-show-progress-in-your-ui) | [backend](/realtime/backend/subscribe#subscribe-to-metadata-updates-from-your-tasks))
20-
- **Tag changes** - When [tags](/tags) are added or removed from the run
21-
- **Realtime Streams** - Stream real-time data from your tasks, perfect for AI/LLM outputs and progress updates. ([Learn more](/tasks/streams) | [React hooks](/realtime/react-hooks/streams) | [Backend](/realtime/backend/streams))
21+
You can use both at the same time. Subscribe to a run's status with Realtime while also streaming AI output with Streams.
22+
23+
## What you can subscribe to
24+
25+
- **Specific runs** by run ID
26+
- **Runs with specific tags** (e.g., all runs tagged with `user:123`). [More on tags](/tags)
27+
- **Batch runs** within a specific batch
28+
- **Trigger + subscribe combos** that trigger a task and immediately subscribe (frontend only)
29+
30+
Once subscribed, you get updates for:
31+
32+
- **Status changes** like queued, executing, completed, failed
33+
- **Metadata updates** for custom progress tracking ([React hooks](/realtime/react-hooks/subscribe#using-metadata-to-show-progress-in-your-ui) | [backend](/realtime/backend/subscribe#subscribe-to-metadata-updates-from-your-tasks))
34+
- **Tag changes** when [tags](/tags) are added or removed
2235

2336
## Using Realtime in your applications
2437

2538
### Authentication
2639

27-
All Realtime subscriptions require authentication so you can securely trigger and subscribe to runs. See our [authentication guide](/realtime/auth) for more details.
40+
All Realtime subscriptions require authentication. See the [authentication guide](/realtime/auth) for setup.
41+
42+
### Frontend (React hooks)
43+
44+
Use `@trigger.dev/react-hooks` to build UIs that update as runs execute.
45+
46+
**[React hooks guide](/realtime/react-hooks/)**
47+
48+
### Backend
49+
50+
Subscribe to runs from your backend code, other tasks, or serverless functions.
51+
52+
**[Backend guide](/realtime/backend)**
53+
54+
## Frequently asked questions
2855

29-
### Frontend implementation
56+
### What's the difference between Realtime and Streams?
3057

31-
Use our React hooks to build real-time UIs that update as runs execute. Ideal for progress bars, status indicators, and live dashboards.
58+
Realtime tracks **run state**: status, metadata, and tags. Streams pipe **continuous data** (like AI completions or progress updates) from a running task to your frontend or backend. Use Realtime for "is my task done yet?" and Streams for "show me the AI output as it generates."
3259

33-
**[See our React hooks guide](/realtime/react-hooks/)**
60+
### Do I need to set up anything in my task for Realtime?
3461

35-
### Backend implementation
62+
No. Realtime subscriptions work automatically for any task. Just subscribe by run ID, tag, or batch from your frontend or backend. Streams require you to define them in your task code with `streams.define()`.
3663

37-
Use our server-side SDK to subscribe to runs from your backend code, other tasks, or serverless functions. Perfect for triggering workflows, sending notifications, or updating databases based on run status changes.
64+
### Can I use Realtime and Streams together?
3865

39-
**[See our Backend guide](/realtime/backend)**
66+
Yes. A common pattern is subscribing to a run's status with Realtime (to show a progress indicator) while also streaming AI output with Streams (to display tokens as they arrive).

docs/realtime/react-hooks/overview.mdx

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
2-
title: React hooks overview
2+
title: "React hooks for real-time task updates"
33
sidebarTitle: Overview
4-
description: Using the Trigger.dev Realtime API from your React applications.
4+
description: "Subscribe to background task progress, stream AI responses, and trigger tasks from React components using @trigger.dev/react-hooks."
55
---
66

77
import RealtimeExamplesCards from "/snippets/realtime-examples-cards.mdx";
88

9-
Our React hooks package provides a set of hooks that make it easy to interact with the Trigger.dev Realtime API from your React applications. You can use these hooks to subscribe to real-time updates, and trigger tasks from your frontend.
9+
**`@trigger.dev/react-hooks` gives your React components live access to background tasks.** Subscribe to run progress, stream AI output as it generates, or trigger tasks directly from the browser.
1010

1111
## Installation
1212

@@ -55,19 +55,19 @@ Learn more about [generating and managing tokens in our authentication guide](/r
5555

5656
## Available hooks
5757

58-
We provide several categories of hooks:
59-
60-
- **[Triggering hooks](/realtime/react-hooks/triggering)** - Trigger tasks from your frontend application
61-
- **[Subscribe hooks](/realtime/react-hooks/subscribe)** - Subscribe to runs, batches, metadata, and more
62-
- **[Streams hooks](/realtime/react-hooks/streams)** - Subscribe to real-time streams from your tasks
63-
- **[SWR hooks](/realtime/react-hooks/swr)** - Fetch data once and cache it using SWR
58+
| Hook category | What it does | Guide |
59+
|---|---|---|
60+
| **Trigger hooks** | Trigger tasks from the browser | [Triggering](/realtime/react-hooks/triggering) |
61+
| **Progress and status** | Subscribe to run status, metadata, and tags | [Progress and status](/realtime/react-hooks/subscribe) |
62+
| **Streaming data** | Consume AI output, file chunks, or any continuous data | [Streaming](/realtime/react-hooks/streams) |
63+
| **SWR hooks** | One-time fetch with caching (not recommended for most cases) | [SWR](/realtime/react-hooks/swr) |
6464

6565
## SWR vs Realtime hooks
6666

67-
We offer two "styles" of hooks: SWR and Realtime. The SWR hooks use the [swr](https://swr.vercel.app/) library to fetch data once and cache it. The Realtime hooks use [Trigger.dev Realtime](/realtime) to subscribe to updates in real-time.
67+
We offer two "styles" of hooks: SWR and Realtime. SWR hooks use the [swr](https://swr.vercel.app/) library to fetch data once and cache it. Realtime hooks use [Trigger.dev Realtime](/realtime) to subscribe to updates as they happen.
6868

6969
<Note>
7070
It can be a little confusing which one to use because [swr](https://swr.vercel.app/) can also be
7171
configured to poll for updates. But because of rate-limits and the way the Trigger.dev API works,
72-
we recommend using the Realtime hooks for most use-cases.
72+
we recommend using the Realtime hooks for most use cases.
7373
</Note>

docs/realtime/react-hooks/streams.mdx

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
---
2-
title: Streams hooks
3-
sidebarTitle: Streams
4-
description: Subscribe to real-time streams from your tasks in React components
2+
title: "Stream data to React (AI, files, progress)"
3+
sidebarTitle: "Streaming"
4+
description: "Display AI/LLM output token by token, stream file chunks, or pipe any continuous data from a background task into your React components."
55
---
66

7-
These hooks allow you to consume real-time streams from your tasks. Streams are useful for displaying AI/LLM outputs as they're generated, or any other real-time data from your tasks.
7+
**Display AI responses as they generate, stream file processing results, or pipe any continuous data from a running task into your React components.** Unlike [progress and status hooks](/realtime/react-hooks/subscribe) (which track run state), streaming hooks give you the raw data your task produces while it runs.
88

99
<Note>
10-
To learn how to emit streams from your tasks, see our [Realtime Streams](/tasks/streams)
11-
documentation.
10+
To learn how to emit streams from your tasks, see [Streaming data from tasks](/tasks/streams).
1211
</Note>
1312

1413
## useRealtimeStream (Recommended)
@@ -151,7 +150,7 @@ const { parts, error } = useRealtimeStream<string>(runId, {
151150
});
152151
```
153152

154-
For more information on defining and using streams, see the [Realtime Streams](/tasks/streams) documentation.
153+
For more information on defining and using streams, see the [Streaming data from tasks](/tasks/streams) documentation.
155154

156155
## useInputStreamSend
157156

@@ -430,3 +429,21 @@ export function MyComponent({
430429
All other options (accessToken, baseURL, enabled, id) work the same as the other realtime hooks.
431430

432431
For the newer `useRealtimeStream` hook, use the `throttleInMs` option instead (see [options above](#options)).
432+
433+
## Frequently asked questions
434+
435+
### How do I stream AI/LLM responses from a background task to React?
436+
437+
Define a typed stream in your task with `streams.define<string>()`, pipe your AI SDK response to it with `.pipe()`, then consume it in your component with `useRealtimeStream`. See [Streaming data from tasks](/tasks/streams) for the task-side setup.
438+
439+
### What's the difference between streaming and subscribing to runs?
440+
441+
[Subscribing](/realtime/react-hooks/subscribe) tracks **run state** (status, metadata, tags). Streaming (this page) pipes **continuous data** your task produces. Use subscribing for progress bars and status badges. Use streaming for AI chat output, live logs, or file processing results. You can use both at the same time.
442+
443+
### Can I send data back into a running task from React?
444+
445+
Yes. Use the `useInputStreamSend` hook to send data into a running task's input stream. This is useful for cancel buttons, user approvals, or any interactive flow. See [Input Streams](/tasks/streams#input-streams) for the full guide.
446+
447+
### Do streams work with the Vercel AI SDK?
448+
449+
Yes. You can pipe a Vercel AI SDK `streamText` response directly into a Trigger.dev stream using `.pipe()`. The [Streaming data from tasks](/tasks/streams) page has a complete AI streaming example.

docs/realtime/react-hooks/subscribe.mdx

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
---
2-
title: Subscribing to runs
3-
sidebarTitle: Subscribe
4-
description: Get live updates from runs, batches, metadata, and more in your frontend application.
2+
title: "Progress and status updates in React"
3+
sidebarTitle: "Progress & status"
4+
description: "Build progress bars, status indicators, and live dashboards by subscribing to background task updates from React components."
55
---
66

7-
These hooks allow you to subscribe to runs, batches, and streams using [Trigger.dev Realtime](/realtime). They automatically include real-time updates for run status, metadata, output, and other properties.
7+
**Subscribe to a run and your component re-renders whenever its status, metadata, or tags change.** Build progress bars, deployment monitors, or any UI that needs to reflect what a background task is doing right now.
88

9-
## Hooks
9+
For streaming continuous data (AI tokens, file chunks), see [Streaming data](/realtime/react-hooks/streams) instead.
1010

11-
## Triggering + Realtime hooks
11+
## Trigger + subscribe combo hooks
1212

13-
For triggering tasks and immediately subscribing to their runs, we provide combo hooks, details on how to use them can be found in the [triggering](/realtime/react-hooks/triggering) section.
13+
Trigger a task and immediately subscribe to its run. Details in the [triggering](/realtime/react-hooks/triggering) section.
1414

1515
- **[`useRealtimeTaskTrigger`](/realtime/react-hooks/triggering#userealtimetasktrigger)** - Trigger a task and subscribe to the run
1616
- **[`useRealtimeTaskTriggerWithStreams`](/realtime/react-hooks/triggering#userealtimetasktriggerwithstreams)** - Trigger a task and subscribe to both run updates and streams
1717

18-
## Other Realtime subscription hooks
18+
## Subscribe hooks
1919

2020
### useRealtimeRun
2121

@@ -654,3 +654,21 @@ export function MyComponent({
654654
```
655655

656656
This allows you to change the ID of the subscription based on some state. Passing in a different ID will unsubscribe from the current subscription and subscribe to the new one (and remove any cached data).
657+
658+
## Frequently asked questions
659+
660+
### How do I show a progress bar for a background task in React?
661+
662+
Use `metadata.set()` inside your task to update a progress value, then read it with `useRealtimeRun` in your component. The hook re-renders your component on every metadata change. See [Using metadata to show progress](#using-metadata-to-show-progress-in-your-ui) above for a complete example.
663+
664+
### What's the difference between subscribing to runs and streaming data?
665+
666+
Subscribing (this page) gives you **run state**: status, metadata, and tags. It's for progress bars, status badges, and dashboards. [Streaming](/realtime/react-hooks/streams) gives you **continuous data** like AI tokens or file chunks. Use subscribing for "how far along is my task?" and streaming for "show me the output as it generates."
667+
668+
### Can I subscribe to multiple runs at once?
669+
670+
Yes. Use `useRealtimeRunsWithTag` to subscribe to all runs with a specific tag (e.g., `user:123`), or `useRealtimeBatch` for all runs in a batch. Each yields an array of run objects that update in real time.
671+
672+
### Do I need to set up polling or WebSockets?
673+
674+
No. The hooks handle the connection automatically using Trigger.dev's Realtime infrastructure (built on [Electric SQL](/realtime/how-it-works)). Just pass a run ID and an access token.

docs/realtime/react-hooks/triggering.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
2-
title: Trigger hooks
2+
title: "Trigger tasks from React"
33
sidebarTitle: Triggering
4-
description: Triggering tasks from your frontend application.
4+
description: "Trigger background tasks from React components and optionally subscribe to their progress or stream their output."
55
---
66

7-
We provide a set of hooks that can be used to trigger tasks from your frontend application.
7+
Trigger tasks directly from your React components. You can fire-and-forget, or trigger and immediately subscribe to the run's progress or streamed output.
88

99
<Note>
1010
For triggering tasks from your frontend, you need to use “trigger” tokens. These can only be used

0 commit comments

Comments
 (0)