Synchronous dag execution
Synchronous dag execution refers to the ability in Airflow 3.1+ to trigger a dag run via an API call and wait for it to complete before returning XCom values pushed by one or more tasks in the dag run. This is useful both for single DAG runs and for cases where the same DAG may be triggered multiple times in parallel.
Synchronous dag execution was added as an experimental feature in Airflow 3.1.
Assumed knowledge
- Basic knowledge of Airflow. See Introduction to Apache Airflow.
- Knowing how to use the Airflow REST API.
- Basic understanding of XCom. See Passing data between tasks.
When to use synchronous dag execution
Synchronous dag execution is a way to use Airflow as the backend for services processing user requests coming from a frontend application like a website, mobile app, or slack bot. Common use cases include:
- Inference execution: A user provides input to a pipeline that interacts with one or more LLMs and/or AI agents to generate a response. The response is served back to the user as soon as the dag has completed running.
- Ad-hoc requests: Non-technical stakeholders request data analyses that use a dag to retrieve the desired result.
- Data submission: Non-technical users can submit their data to a dag to be processed and get immediate feedback on the status of the request and the result.
API Endpoint
The endpoint to wait for a dag run to complete is:
It includes the following path parameters:
dag_id
: (Mandatory) The id of the DAG to wait for.dag_run_id
: (Mandatory) The id of the DAG run to wait for.
The query parameters are:
interval
: (Mandatory) Seconds to wait between dag run state checks.result
: (Optional) Array of strings or null. A list of task ids from which to pull the XCom value pushed under thereturn_value
key.
Calling this endpoint on any running dag will start a waiting process until the dag run completes. If any XCom are requested in the result
parameter, they are returned in the response upon dag run completion.
Example script
The following script creates a dag run for the my_dag
dag and waits for it to complete. It includes XComs pushed under the return_value
key of the my_task
task in the response.
Running the script above returns an output similar to the following: