Skip to main content

What is a Trigger?

A Trigger is what causes a Function to run. Triggers connect event sources to your functions, enabling automatic execution in response to:
  • HTTP requests
  • Scheduled cron jobs
  • Queue/pubsub messages
  • Stream events
  • Custom event sources
Triggers decouple your business logic (functions) from how they’re invoked. The same function can be triggered by HTTP, cron, or a queue without any code changes.

Trigger Architecture

Triggers have a two-level registration system:
  1. Trigger Types: Define the kind of event source (e.g., http, cron, queue)
  2. Triggers: Specific instances that connect a trigger type to a function

Built-in Trigger Types

HTTP Triggers

Map HTTP routes to functions. Powered by the RestApiModule.
HTTP triggers automatically parse request bodies, query parameters, and path params into the function input.

Cron Triggers

Schedule functions to run on a recurring basis using cron expressions.

Queue Triggers

Subscribe functions to queue topics for async job processing.

Stream Triggers

React to real-time stream events over WebSocket channels.

Registering Triggers

Basic Registration

Dynamic Triggers

Triggers can be registered and unregistered at runtime:

Custom Trigger Types

You can create custom trigger types by registering them from a worker:

Trigger Lifecycle

The trigger registration flow involves coordination between workers and the engine:

Protocol Messages

Under the hood, triggers use these WebSocket protocol messages:

RegisterTriggerType

Workers declare support for a trigger type:

RegisterTrigger

Create a specific trigger instance:

TriggerRegistrationResult

Engine confirms trigger registration:

UnregisterTrigger

Remove a trigger:

Internal Implementation

From the engine’s Rust implementation:
The TriggerRegistry maintains all registered trigger types and trigger instances. When a worker disconnects, all its triggers are automatically unregistered.

Firing Triggers Manually

You can manually fire all triggers of a specific type from the engine:
This invokes all functions registered to triggers of that type.

Best Practices

Use specific trigger IDs

Provide explicit IDs for triggers you’ll need to unregister later

Handle registration errors

Check TriggerRegistrationResult for errors and retry if needed

Clean up on disconnect

The engine auto-cleans triggers when workers disconnect, but unregister explicitly when possible

Keep configs simple

Trigger configs should be JSON-serializable and well-documented

Next Steps

Functions

Learn about the functions that triggers invoke

Architecture

Understand the engine and worker model