Architecture
The Realtime API is built on top of Electric SQL, an open-source PostgreSQL syncing engine. The Trigger.dev API wraps Electric SQL and provides a simple API to subscribe to runs and get real-time updates.Run changes
You will receive updates whenever a run changes for the following reasons:- The run moves to a new state. See our run lifecycle docs for more information.
- Run tags are added or removed.
- Run metadata is updated.
Run object
The run object returned by Realtime subscriptions is optimized for streaming updates and differs from the management API’s run object. See the run object page for the complete schema and field descriptions.Basic usage
After you trigger a task, you can subscribe to the run using theruns.subscribeToRun
function. This function returns an async iterator that you can use to get updates on the run status.
runs.subscribeToRunsWithTag
function.
batchTrigger
to trigger multiple runs, you can also subscribe to changes to all the runs triggered in the batch using the runs.subscribeToBatch
function.
Run metadata
The run metadata API gives you the ability to add or update custom metadata on a run, which will cause the run to be updated. This allows you to extend the Realtime API with custom data attached to a run that can be used for various purposes. Some common use cases include:- Adding a link to a related resource
- Adding a reference to a user or organization
- Adding a custom status with progress information
Using metadata with Realtime & React hooks
You can combine run metadata with the Realtime API to bridge the gap between your trigger.dev tasks and your applications in two ways:- Using our React hooks to subscribe to metadata updates and update your UI in real-time.
- Using our backend functions to subscribe to metadata updates in your backend.
Limits
The Realtime API in the Trigger.dev Cloud limits the number of concurrent subscriptions, depending on your plan. If you exceed the limit, you will receive an error when trying to subscribe to a run. For more information, see our pricing page.Learn more
- Read our Realtime blog post “How we built a real-time service that handles 20,000 updates per second
- Using Realtime: React Hooks (frontend)
- Using Backend (server-side)