Event-driven scheduling
Added in version 3.0.
Apache Airflow allows for event-driven scheduling, enabling Dags to be triggered based on external events rather than predefined time-based schedules. This is particularly useful in modern data architectures where workflows need to react to real-time data changes, messages, or system signals.
By using assets, as described in Asset-Aware Scheduling, you can configure Dags to start execution when specific external events occur. Assets provide a mechanism to establish dependencies between external events and Dag execution, ensuring that workflows react dynamically to changes in the external environment.
The AssetWatcher class plays a crucial role in this mechanism. It monitors an external event source, such as a
message queue, and triggers an asset update when a relevant event occurs.
The watchers parameter in the Asset definition allows you to associate multiple AssetWatcher instances with an
asset, enabling it to respond to various event sources.
See the common.messaging provider docs for more information and examples.
Supported triggers for event-driven scheduling
Not all triggers in Airflow can be used for event-driven scheduling. As opposed to all triggers that
inherit from BaseTrigger, only a subset that inherit from BaseEventTrigger are compatible.
The reason for this restriction is that some triggers are not designed for event-driven scheduling, and using them to
schedule Dags could lead to unintended results.
BaseEventTrigger ensures that triggers used for scheduling adhere to an event-driven paradigm, reacting appropriately
to external event changes without causing unexpected Dag behavior.
Writing event-driven compatible triggers
To make a trigger compatible with event-driven scheduling, it must inherit from BaseEventTrigger. There are three
main scenarios for working with triggers in this context:
1. Creating a new event-driven trigger: If you need a new trigger for an unsupported event source, you should create
a new class inheriting from BaseEventTrigger and implement its logic.
2. Adapting an existing compatible trigger: If an existing trigger (inheriting from BaseTrigger) is proven to be
already compatible with event-driven scheduling, then you just need to change the base class from BaseTrigger to
BaseEventTrigger.
3. Adapting an existing incompatible trigger: If an existing trigger does not appear to be compatible with
event-driven scheduling, then a new trigger must be created.
This new trigger must inherit BaseEventTrigger and ensure it properly works with event-driven scheduling.
It might inherit from the existing trigger as well if both triggers share some common code.
Publishing partitioned asset events
To publish an update for a specific asset partition, yield AssetTriggerEvent with a partition_key:
from airflow.triggers.base import AssetTriggerEvent
yield AssetTriggerEvent({"changed": True}, partition_key="2026-10-16")
Airflow uses this key for partition-aware scheduling.
See Asset partitions for configuring downstream consumers.
Watcher logs
A deferred task’s trigger logs to that task try’s log, and a callback’s trigger to the callback’s log. An asset
watcher has no such log, so its lines go to a file of its own on the triggerer that runs it,
triggers/trigger_id=<trigger id>/triggerer_job_id=<triggerer job id>/trigger.log under
[logging] base_log_folder. The file lasts as long as the trigger stays on that triggerer, across every
restart of the watcher, and each line keeps the watcher’s trigger_id. With [logging] remote_logging
on, the remote log handler that uploads task and callback logs also uploads the file when the trigger leaves
the triggerer (as its next rotated file, since it can come back) or the triggerer stops, and a triggerer that
starts uploads the files left on its disk by triggerers that died.
[triggerer] watcher_log_max_bytes sets a target size for the file, with one rotated file in a rotated
directory next to it (with remote logging on, each rotated file is uploaded, as its own
rotated/trigger.<n>.log with a handler that stores files, such as S3, and tried once more if that fails;
if both fail, the next rotation deletes it, so lines can be lost while the store is down),
[triggerer] watcher_log_max_open_files caps how many such files are open at once, and
[triggerer] watcher_log_to_stdout keeps the watcher’s lines in the triggerer’s output too, for platforms
that collect it. A rotation waits for the previous rotated file’s upload, so while the remote store is slow or
unreachable the file can grow past watcher_log_max_bytes. Without remote logging, or with a handler that
keeps no copy of them (Elasticsearch, OpenSearch), only the most recently written of the files gone triggerers
left is kept for each watcher, so a watcher normally uses at most four times watcher_log_max_bytes of one
disk. None are kept for a trigger that no longer exists, also after its watcher left a running triggerer. A
full or read-only log disk doesn’t stop the triggerer: the lines a trigger’s log file can’t take go to the
triggerer’s output, with a warning at most once a minute per trigger.
Avoid infinite scheduling
The reason why some triggers are not compatible with event-driven scheduling is that they are waiting for an external resource to reach a given state. Examples:
Wait for a file to exist in a storage service
Wait for a job to be in a success state
Wait for a row to be present in a database
Scheduling under such conditions can lead to infinite rescheduling. This is because once the condition becomes true, it is likely to remain true for an extended period.
For example, consider a Dag scheduled to run when a specific job reaches a “success” state. Once the job succeeds, it will typically remain in that state. As a result, the Dag will be triggered repeatedly every time the triggerer checks the condition.
Another example is the S3KeyTrigger, which checks for the presence of a specific file in an S3 bucket.
Once the file is created, the trigger will continue to succeed on every check, since the condition
“is file X present in bucket Y” remains true.
This leads to the Dag being triggered indefinitely every time the trigger mechanism runs.
When creating custom triggers, be cautious about using conditions that remain permanently true once met. This can unintentionally result in infinite Dag executions and overwhelm your system.
Consuming Airflow event telemetry from Kafka
The Apache Kafka provider ships a KafkaEventProducerPlugin that publishes a message to a Kafka topic
for every Dag run and task instance state-change event. See the
plugin documentation for how a
Deployment Manager enables and configures it.
The plugin is aimed at operators and platform teams who want to observe or react to what an Airflow deployment is doing without polling its metadata database. It emits internal Airflow telemetry — the schema and contents of the published messages are produced by Airflow itself. As a Dag author or generally an Operations User you cannot change what telemetry is published to the topic, you can only consume it.
It is packaged as a plugin, rather than as an operator or hook you would use inside a Dag, precisely because it is deployment-level telemetry. It hooks into Airflow’s listener API to emit events for every Dag run and task instance in the deployment, so a Deployment Manager enables and configures it once (see the plugin documentation above), and it is not something individual Operations Users turn on or customize per Dag.
Because these events land on an ordinary Kafka topic, you can consume them with the same tools you would use for any other Kafka stream:
An
AssetWatcherbacked by the Kafka message-queue trigger, to schedule a Dag when a matching event is published (see Asset-Aware Scheduling for theAssetWatcherpattern).The AwaitMessageSensor, to defer a task until a matching event arrives on the topic.
The ConsumeFromTopicOperator or the
KafkaConsumerHook, to read events directly from within a task.
Use cases for event-driven Dags
Data ingestion pipelines: Trigger ETL workflows when new data arrives in a storage system.
Machine learning workflows: Start training models when new datasets become available.
IoT and real-time analytics: React to sensor data, logs, or application events in real-time.
Microservices and event-driven architectures: Orchestrate workflows based on service-to-service messages.