Triggers v2 #647
Replies: 1 comment 2 replies
-
Goals
An example of this would be great! Components
How would we control how these two interact in the case of WhatsApp for example? Create an HTTP Endpoint with opts Just thinking this could get tricky as we'd probably need more complex logic, e.g. a fully fledged handler function. Not easily serializable. But maybe (in this case) the response can be pre-computed without request data. Queues
That will be great! It's a bit how the current batching system (TBD) works, using push instead. Would the idea be to use an external queueing system for this? Payloads
Good thing is, it should be straightforward to do separately from the other changes. Webhook registrationCompletely agree with this 👍 Will have to make HTTP Trigger
In many cases this could probably be automated by the user (with another task), just as we are currently doing for integrations. Maybe the new Webhook Registration abstraction could help here too. Interactive Webhooks
Ties into my comment re HTTP Endpoint + Secret primitives. One thing to keep in mind is that this may not be possible without keeping the incoming connection (from WhatsApp or Slack) open, effectively turning the Trigger.dev platform into a proxy. Filtering
If filters are directly tied to HTTP Endpoints, we may be able to filter during ingestion and not even store all events in the DB. We currently filter before invoking dispatchers: |
Beta Was this translation helpful? Give feedback.
-
Goals
The core ideas
Break Triggers down into separate components
Currently Triggers are created as one asset from the user's side. This makes it hard to create new types of Triggers, hard to support more complex Triggers and makes integrations brittle to changes.
Instead let's break the functionality of Triggers into separate components. They can be created and retrieved using the Trigger.dev API/SDK. They can be versioned and updated independently. We can create new components where needed when we discover a better way of doing things, without breaking existing Triggers.
Some components might be:
Move more of the logic to the client
Generally speaking in the current system the Trigger.dev service asks for data about a Trigger and the client responds with that data.
We should change this, so the Trigger.dev service sends lifecycle events to the client. This gives the client the opportunity to perform actions using the Trigger SDK and external APIs. This reversal means that Integrations can be more flexible, allows for complicated combinations of components, and is less brittle.
The client requests the data it wants and performs the actions it wants, using the Trigger API or external ones. The Trigger.dev service sends lifecycle events to the client with the data they need to start doing stuff.
Queues
We should add a new layer to the system, a Queue. This helps decouple the production of events, the consumption of events, and the processing of events. Plus it means we can add concurrency, batching and rate limiting more easily and granularly.
Events would be pulled from a queue by a consumer, and then processed.
We shouldn't send Trigger payloads to the client
Deployment platforms have aggressive limits on the amount of data you can use in a request to their functions (4.5MB in Vercel's case). But there's no limit (as far as I know) on outgoing requests from inside their functions. We can take advantage of this:
Make webhook automatic registration easier
Unfortunately we need to support re-using webhooks for multiple events as some APIs only allow a limited number of webhooks to be registered. This makes it far trickier as you sometimes need to update an existing webhook rather than just creating a new one.
To make this easier for users we can create an abstraction around this, by introducing a CRUD webhook object. Integration creators would just need to implement the exposed methods. We will do the hard work of calling the right methods with the required data.
Behind-the-scenes this is still using primitives but it's just a layer of abstraction inside the SDK or integration-kit packages that make it easier to work with.
Pseudo-code
HTTP Trigger
This would allow users to subscribe to webhooks where we don't have an integration.
Questions
Can we make all webhooks "interactive"?
This means we would store the request, and immediately forward to the user's server. This is required for verification requests (WhatsApp) and interactive webhooks (Slack). We'd store the response from the user's server, and send it back to the webhook provider.
If the server doesn't respond then we have the payload so we can add it to a queue to retry later.
Where does filtering happen?
We need to filter before we batch events, or Trigger runs.
Some APIs, with different requirements
Some top-level examples of how we would implement some triggers.
For all of these Diagrams, we'll use these style to distinguish between Trigger.dev and the user's server.
Dashed lines mean there can be a delay between the two steps.
WhatsApp
Registration
The webhooks
Diagrams
1. Registering for webhooks
2. Receiving a request from WhatsApp
Note that the Responses to WhatsApp aren't marked on here because it screws the diagram up… 🤦♂️
3. Trigger a run
GitHub
Registration
The webhooks
Diagrams
1. Registering for webhooks
We need to share webhooks when possible.
A single GitHub webhook needs to be shared across many of our triggers. Those triggers can subscribe to different events.
We need to handle creating and updating webhooks from separate triggers here. This means we need the information from all the relevant triggers, and the diff since last time we registered. More details on how this can be simply achieved in the "Making webhook automatic registration easier" section.
2. Receiving a request from GitHub
3. Trigger a run
Stripe
Registration
The webhooks
Diagrams
1. Registering for webhooks
We need to share webhooks when possible.
A single Stripe webhook needs to be shared across many of our triggers. Those triggers can subscribe to different events.
We need to handle creating and updating webhooks from separate triggers here. This means we need the information from all the relevant triggers, and the diff since last time we registered. More details on how this can be simply achieved in the "Making webhook automatic registration easier" section.
2. Receiving a request from Stripe
3. Trigger a run
Airtable
Registration
The webhooks
Diagrams
1. Registering for webhooks
We need to share webhooks when possible.
A single Airtable webhook needs to be shared across many of our triggers. Those triggers can subscribe to different events.
We need to handle creating and updating webhooks from separate triggers here. This means we need the information from all the relevant triggers, and the diff since last time we registered. More details on how this can be simply achieved in the "Making webhook automatic registration easier" section.
2. Receiving a request from Airtable
Note that we have to fetch the actual payloads, as the webhooks are just notifications. And we need to store a cursor.
3. Trigger a run
Notion
Notion has no support for webhooks, so we'll have to poll their API.
Discord
Registration
The webhooks
More details.
Gmail
Registration
The webhooks
Beta Was this translation helpful? Give feedback.
All reactions