-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
docs: Fixes and realtime improvements #3265
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a9275d0
Various fixes
D-K-P 30ea2c7
Updated realtime docs to be much clearer
D-K-P 59a0916
Run updates + streaming distinction
D-K-P 483375e
Added auth comment
D-K-P 1ccb29f
Added setup with ai to the quickstart
D-K-P 0c9aec6
removed /v3 from writing tasks
D-K-P 5f43556
updated quick start
D-K-P File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,39 +1,63 @@ | ||
| --- | ||
| title: Realtime overview | ||
| sidebarTitle: Overview | ||
| description: Using the Trigger.dev Realtime API to trigger and/or subscribe to runs in real-time. | ||
| description: "Get live run updates and stream data from background tasks to your frontend or backend. No polling." | ||
| --- | ||
|
|
||
| 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. | ||
| **Realtime is the umbrella for everything live in Trigger.dev.** It covers two things: getting notified when a run's state changes, and streaming continuous data (like AI tokens) from a running task to your app. | ||
|
|
||
| You can subscribe to real-time updates for different scopes of runs: | ||
| Both use the same `@trigger.dev/react-hooks` package and the same authentication system. The difference is what they give you. | ||
|
|
||
| - **Specific runs** - Monitor individual run progress by run ID | ||
| - **Runs with specific tags** - Track all runs that have certain [tags](/tags) (e.g., all runs tagged with `user:123`) | ||
| - **Batch runs** - All runs within a specific batch | ||
| - **Trigger + subscribe combos** - Trigger a task and immediately subscribe to its run (frontend only) | ||
| ## Run updates vs Streaming | ||
|
|
||
| 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: | ||
| | | Run updates | Streaming | | ||
| |---|---|---| | ||
| | **What you get** | Run state: status, metadata, tags | Continuous data you define (AI tokens, file chunks, progress) | | ||
| | **When it fires** | On state changes | While the task runs, as data is produced | | ||
| | **Use case** | Progress bars, status badges, dashboards | AI chat output, live logs, file processing | | ||
| | **React hook** | [`useRealtimeRun`](/realtime/react-hooks/subscribe) | [`useRealtimeStream`](/realtime/react-hooks/streams) | | ||
| | **Setup in task code?** | No, automatic | Yes, using `streams.define()` | | ||
| | **Infrastructure** | [Electric SQL](/realtime/how-it-works) (PostgreSQL sync) | Streams transport | | ||
|
|
||
| - **Status changes** - queued → executing → completed, etc. | ||
| - **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)) | ||
| - **Tag changes** - When [tags](/tags) are added or removed from the run | ||
| - **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)) | ||
| You can use both at the same time. Subscribe to a run's status (to show a progress bar) while also streaming AI output (to display tokens as they arrive). | ||
|
|
||
| ## Using Realtime in your applications | ||
| ## Run updates | ||
|
|
||
| ### Authentication | ||
| Subscribe to a run and your code gets called whenever its status, [metadata](/runs/metadata), or [tags](/tags) change. No setup needed in your task code. | ||
|
|
||
| All Realtime subscriptions require authentication so you can securely trigger and subscribe to runs. See our [authentication guide](/realtime/auth) for more details. | ||
| You can subscribe to: | ||
|
|
||
| ### Frontend implementation | ||
| - **Specific runs** by run ID | ||
| - **Runs with specific tags** (e.g., all runs tagged with `user:123`) | ||
| - **Batch runs** within a specific batch | ||
| - **Trigger + subscribe combos** that trigger a task and immediately subscribe (frontend only) | ||
|
|
||
| Use our React hooks to build real-time UIs that update as runs execute. Ideal for progress bars, status indicators, and live dashboards. | ||
| → [React hooks](/realtime/react-hooks/subscribe) | [Backend](/realtime/backend/subscribe) | ||
|
|
||
| → **[See our React hooks guide](/realtime/react-hooks/)** | ||
| ## Streaming | ||
|
|
||
| ### Backend implementation | ||
| Define typed streams in your task, pipe data to them, and read that data from your frontend or backend as it's produced. You need to set up streams in your task code using `streams.define()`. | ||
|
|
||
| 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. | ||
| → [How to emit streams from tasks](/tasks/streams) | [React hooks](/realtime/react-hooks/streams) | [Backend](/realtime/backend/streams) | ||
|
|
||
| → **[See our Backend guide](/realtime/backend)** | ||
| ## Authentication | ||
|
|
||
| All Realtime hooks and functions require authentication. See the [authentication guide](/realtime/auth) for setup. | ||
|
|
||
| ## Frequently asked questions | ||
|
|
||
| ### How do I show a progress bar for a background task? | ||
|
|
||
| Use [run metadata](/runs/metadata) to store progress data (like a percentage), then subscribe to the run with [`useRealtimeRun`](/realtime/react-hooks/subscribe). Your component re-renders on every metadata update. | ||
|
|
||
| ### How do I stream AI/LLM responses from a background task? | ||
|
|
||
| Define a stream in your task with `streams.define()`, pipe your AI SDK response to it, then consume it in React with [`useRealtimeStream`](/realtime/react-hooks/streams). See [Streaming data from tasks](/tasks/streams) for the full guide. | ||
|
|
||
| ### Do I need WebSockets or polling? | ||
|
|
||
| No. Run updates are powered by [Electric SQL](/realtime/how-it-works) (HTTP-based PostgreSQL syncing). Streams use their own transport. The hooks handle connections automatically. | ||
|
|
||
| ### Can I use both run updates and streaming together? | ||
|
|
||
| Yes. A common pattern: subscribe to run status with `useRealtimeRun` (progress indicator) while streaming AI output with `useRealtimeStream` (token-by-token display). |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.