Skip to content

Asset event scheduling - introduce max_asset_events parameter #55956

Open

Description

@dabeeru

Description

Currently, when a DAG is triggered by asset events, Airflow's scheduler consumes all available asset events from the queue and creates a single DAG run that processes all these events together (code).

This feature request proposes adding a configurable parameter (eg. max_asset_events) that allows DAG developers to control how many asset events are consumed per DAG run.

Use case/motivation

This feature request is primarily motivated by the need to simplify migration from Airflow 2.x DAGs that were previously triggered by SQS queue events and designed to process one message at a time (as SqsSensor allowed to configure max_messages=1 parameter).

Related issues

No response

Are you willing to submit a PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. added
    kind:feature
    needs-triage
    on Sep 22, 2025
  2. jroachgolf84 commented on Sep 22, 2025

    @jroachgolf84
    Collaborator

    If this is something that you're looking to recreate only for SQS/other queue-based integrations, I would suggest doing so at the Trigger-level, rather than generalizing for all Assets. Just my thoughts, I'll leave it open for folks such as @cmarteepants or @dstandish to comment on as well.

  3. added
    area:data-aware-scheduling
    and removed
    needs-triage
    on Sep 22, 2025
  4. cmarteepants commented on Sep 23, 2025

    @cmarteepants
    Collaborator

    @dabeeru Conceptually I'm pro having this kind of option, and I've wondered about how to do something like this, but from a different angle (guaranteeing that every asset event triggers a Dag Run).

    Where I get stuck: If a dag is only scheduled against a single asset, this seems easy enough to achieve, but how do we deal with dags that are scheduled against more than one asset?

    Not sure where the param should live in your design, but assuming this:

    asset_1 = Asset(
        "some_sqs_queue", 
        watchers=[AssetWatcher(name="sqs_watcher_some_queue", trigger=trigger)], 
        max_messages=1
    )
    
    asset_2 = Asset(
        "another_sqs_queue", 
        watchers=[AssetWatcher(name="sqs_watcher_another_queue", trigger=trigger)]
        max_messages=1
    )
    
    with DAG(
        schedule=['asset_1, 'asset_2']. # DAG will only run when there is an asset even for `asset_1` and `asset_2`
    ) as dag:
         # do something
    

    How do we handle for example cases where asset_1 has 5 asset events before an asset even is finally created for asset_2?

    (Happy to explain the scenario more deeply, not sure how clear it is).

  5. cmarteepants commented on Sep 23, 2025

    @cmarteepants
    Collaborator

    Perhaps we do the dumb thing and have the param be at the dag-level, and only let you use this parameter if the dag is only scheduled against a single asset?

    The next question is if this overlaps with partitions cc @uranusjr @dstandish

  6. dabeeru commented on Sep 24, 2025

    @dabeeru
    Author

    @cmarteepants I think we could introduce this parameter at the DAG level while still allowing it to be used in any scenario. Then max_asset_events parameter would just limit how many asset events can be polled for single DAG run, always assuming that we should prioritize polling the oldest items first.

    So for example:

    Timeline: DAG with max_asset_events=1, scheduled on Assets A, B, C
    
    Time    Asset A Queue    Asset B Queue    Asset C Queue    DAG Action
    -----   -------------    -------------    -------------    ----------
    10:00   [E1]             []               []               Wait
    10:05   [E1]             [E1]             []               Wait  
    10:10   [E1, E2]         [E1]             []               Wait
    10:15   [E1, E2]         [E1, E2]         []               Wait
    10:20   [E1, E2]         [E1, E2]         [E1]             🚀 TRIGGER!
            
            Consumed Events: A-E1, B-E1, C-E1 (oldest from each)
            
    10:20   [E2]             [E2]             []               Wait
    10:25   [E2, E3]         [E2]             [E2]             🚀 TRIGGER!
            
            Consumed Events: A-E2, B-E2, C-E2 (oldest from each)
            
    10:25   [E3]             []               []               Wait
    10:30   [E3, E4]         [E3]             []               Wait
    

    Not sure how much it would impact current implementation, but conceptually it makes sense for me. What do you think?

  7. uranusjr commented on Nov 12, 2025

    @uranusjr
    Member

    Is there a use case for values other than None (no limit, current behaviour) and 1? Maybe we could get away with just one flag to control if grouping happens or not. This would also make the multiple asset case easier to reason with.

    Another thing is how would the behaviour be if different depended assets set this flag differently. (Maybe the flag should be on the depending dag instead?)

  8. added this to the Airflow 3.2.0 milestone on Nov 12, 2025
  9. anishgirianish commented on Feb 21, 2026

    @anishgirianish
    Contributor

    Hi,@uranusjr, I'd like to work on this, if this is still open.

    On boolean vs integer, AssetDagRunQueue is keyed by (asset_id, target_dag_id) and deduplicates on insert, so it's a boolean signal, not an event counter. An integer limit would need the queue rearchitected to track individual events. Boolean "each event triggers its own run" vs "all grouped into one run" covers the use case and is simpler.

    For where the flag lives, DAG-level feels right. Asset has no scheduling parameters, and two DAGs depending on the same asset might want different grouping. Something like DAG(schedule=[asset], group_asset_events=False) defaulting to True for backward compat.

    Re partitions, these use separate infrastructure (AssetPartitionDagRun + PartitionedAssetKeyLog vs AssetDagRunQueue), and partitioned DAGs are excluded from the regular asset-triggered path. They shouldn't conflict.

    Let me know if this direction makes sense.

  10. dshemetov commented on Jul 31, 2026

    @dshemetov

    Would like to put my vote in for this feature. Our intended use case: we have a backfill DAG that iterates over files in an S3 bucket and emits an Asset event per file in a time window and emits an Asset event per file. A downstream pipeline DAG grabs these, but is written to handle only one file (Asset event) per dagrun - it throws if it gets more than 1 Asset event and we mostly manage to achieve that by throttling the Asset emission rate on the backfill DAG (with sleep/queues). It's a bit hacky, but the approach mostly works. Still, it would be nice to have this not be a variable at all. (Happy to hear alternative approaches; to be clear - it's not really practical for us to make the downstream pipeline .expand() over multiple files.)

  11. raphaelauv commented on Nov 9, 2026

    @raphaelauv
    Contributor

    done by #68517 and release with 3.4.0

    @dabeeru could you close the issue, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:data-aware-schedulingkind:feature

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions