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.Documentation Index
Fetch the complete documentation index at: https://astronomer-preview.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
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:dag_id: (Mandatory) The id of the DAG to wait for.dag_run_id: (Mandatory) The id of the DAG run to wait for.
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_valuekey.
result parameter, they are returned in the response upon dag run completion.
Example script
The following script creates a dag run for themy_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.