Skip to content

Reduce per-task DB round trips in the asset dependency graph API - #71915

Merged
vatsrahul1001 merged 2 commits into
apache:mainfrom
ColtenOuO:batch-asset-graph-inlet-outlet-queries
Sep 7, 2026
Merged

vatsrahul1001 merged 2 commits into
apache:mainfrom
ColtenOuO:batch-asset-graph-inlet-outlet-queries

Conversation

@ColtenOuO

Copy link
Copy Markdown
Contributor

Summary

get_data_dependencies() (the Assets dependency-graph API) resolved each producing/consuming task's inlet/outlet asset references with one DB query per task, inside a BFS loop. An asset shared by many Dags/tasks — common in multi-team deployments — turned opening its graph into hundreds of sequential round trips in a single request.

Change

  • The same file already batches Dag entry-point resolution the same way (_get_dag_entry_points); this extends that pattern to the two remaining per-task query sites.
  • Task keys needing an inlet or outlet lookup are now collected across the whole BFS round and resolved with one tuple_(dag_id, task_id).in_(...) query each, instead of one query per task.

Round-trip reduction

Measured with the new regression test (3 Dags each with one task producing the same asset, in a single BFS round): total DB queries per request dropped from 11 to 9 — 2 fewer round trips (3 individual inlet queries collapsed into 1 batched query).

This scales with the number of tasks touched per round: for N tasks needing an inlet lookup, it goes from N round trips to 1; same for M tasks needing an outlet lookup. For an asset shared by hundreds of tasks, this is a reduction from hundreds of round trips down to at most 2 per BFS round (one inlet batch, one outlet batch).


Was generative AI tooling used to co-author this PR?
  • Yes — Claude Code (Sonnet 5)

get_data_dependencies() already batches Dag entry-point resolution into
one query per BFS round, but still issued one inlet/outlet
TaskInletAssetReference/TaskOutletAssetReference query per individual
task. An asset shared by many Dags/tasks (common in multi-team
deployments) turned opening its dependency graph into hundreds of
sequential round trips within a single request.

Collect the task keys needing an inlet or outlet lookup across the
whole round and resolve each with one batched query, the same
tuple_(...).in_(...) pattern already used for entry-point resolution
and elsewhere in the API layer.

@pierrejeambrun pierrejeambrun left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread airflow-core/tests/unit/api_fastapi/core_api/routes/ui/test_dependencies.py Outdated
The new regression test only exercised the inlet-lookup batching
path, leaving the outlet-lookup path (traced from consuming tasks)
uncovered.
@ColtenOuO
ColtenOuO force-pushed the batch-asset-graph-inlet-outlet-queries branch from 3659a8f to 34a8c84 Compare August 29, 2026 19:51
@vatsrahul1001 vatsrahul1001 added the type:bug-fix Changelog: Bug Fixes label Sep 7, 2026
@vatsrahul1001
vatsrahul1001 merged commit a3b5b0b into apache:main Sep 7, 2026
79 checks passed
@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Backport failed to create: v3-3-test. View the failure log Run details

Note: As of Merging PRs targeted for Airflow 3.X
the committer who merges the PR is responsible for backporting the PRs that are bug fixes (generally speaking) to the maintenance branches.

In matter of doubt please ask in #release-management Slack channel.

Status Branch Result
❌ v3-3-test Commit Link

You can attempt to backport this manually by running:

cherry_picker a3b5b0b v3-3-test

This should apply the commit to the v3-3-test branch and leave the commit in conflict state marking
the files that need manual conflict resolution.

After you have resolved the conflicts, you can continue the backport process by running:

cherry_picker --continue

If you don't have cherry-picker installed, see the installation guide.

pierrejeambrun pushed a commit to astronomer/airflow that referenced this pull request Sep 8, 2026
…che#71915)

* Reduce per-task DB round trips in the asset dependency graph API

get_data_dependencies() already batches Dag entry-point resolution into
one query per BFS round, but still issued one inlet/outlet
TaskInletAssetReference/TaskOutletAssetReference query per individual
task. An asset shared by many Dags/tasks (common in multi-team
deployments) turned opening its dependency graph into hundreds of
sequential round trips within a single request.

Collect the task keys needing an inlet or outlet lookup across the
whole round and resolve each with one batched query, the same
tuple_(...).in_(...) pattern already used for entry-point resolution
and elsewhere in the API layer.

* Add outlet-resolution batching test for the asset dependency graph

The new regression test only exercised the inlet-lookup batching
path, leaving the outlet-lookup path (traced from consuming tasks)
uncovered.
imrichardwu pushed a commit to imrichardwu/airflow that referenced this pull request Sep 11, 2026
…che#71915)

* Reduce per-task DB round trips in the asset dependency graph API

get_data_dependencies() already batches Dag entry-point resolution into
one query per BFS round, but still issued one inlet/outlet
TaskInletAssetReference/TaskOutletAssetReference query per individual
task. An asset shared by many Dags/tasks (common in multi-team
deployments) turned opening its dependency graph into hundreds of
sequential round trips within a single request.

Collect the task keys needing an inlet or outlet lookup across the
whole round and resolve each with one batched query, the same
tuple_(...).in_(...) pattern already used for entry-point resolution
and elsewhere in the API layer.

* Add outlet-resolution batching test for the asset dependency graph

The new regression test only exercised the inlet-lookup batching
path, leaving the outlet-lookup path (traced from consuming tasks)
uncovered.
regarmukesh3g pushed a commit to regarmukesh3g/airflow that referenced this pull request Sep 27, 2026
…che#71915)

* Reduce per-task DB round trips in the asset dependency graph API

get_data_dependencies() already batches Dag entry-point resolution into
one query per BFS round, but still issued one inlet/outlet
TaskInletAssetReference/TaskOutletAssetReference query per individual
task. An asset shared by many Dags/tasks (common in multi-team
deployments) turned opening its dependency graph into hundreds of
sequential round trips within a single request.

Collect the task keys needing an inlet or outlet lookup across the
whole round and resolve each with one batched query, the same
tuple_(...).in_(...) pattern already used for entry-point resolution
and elsewhere in the API layer.

* Add outlet-resolution batching test for the asset dependency graph

The new regression test only exercised the inlet-lookup batching
path, leaving the outlet-lookup path (traced from consuming tasks)
uncovered.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:API Airflow's REST/HTTP API type:bug-fix Changelog: Bug Fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants