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. In Airflow 3.3+ you specify which task in a Dag returns the result in the Dag code, see specify the Dag result.
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.
Specify the Dag result
In Airflow 3.3+ you can define which task in a Dag returns the result thewait endpoint should return, using the @result decorator on top of a @task decorated function.
.output (the XCom pushed with the key return_value) to the Dag object.