Skip to content

UI - N+1 Calls in the Tasks Tab #59598

Closed

Description

@nclaeys

Apache Airflow version

Other Airflow 3 version (please specify below)

If "Other Airflow 3 version" selected, which one?

3.1.3

What happened?

When browsing the Airflow UI and looking at the tasks tab, it triggers n+1 queries for every task in your dag. If your dag has 200+ tasks, it does 200+ queries which should not be the case. The first 30 might succeed but afterwards the calls fail due to a sqlalchemy timeout.

problematic UI path: <airflowBaseUrl>/airflow/dags/<some-dag>/tasks

UI:
Image

Logs of the api-server where only 1 user is using it:

api-server.log

What you think should happen instead?

Visualizing and working with dags that have many tasks should work. The UI should not do a call for every task in the dag as that can never scale. Redesign of parts of the UI might be needed.

I saw in the issues that work has been done to fix n+1 queries (#57561), but it seems this path has been missed.

How to reproduce

Create a dag with 200 tasks in it and make sure there are a couple of dagruns (5 or so).
Go to the dag (gridview) and then click on tasks tab on the right panel. See previous screenshot.
Check the logs and you will see that 200 calls are triggered to fetch task instances for every task in the dag.

The 200 calls done against the backend look as follows:
<airflowBaseUrl>/airflow/api/v2/dags/<some-dag>/dagRuns/~/taskInstances?task_id=<some-task>&limit=14&order_by=-run_after

Operating System

ubuntu

Versions of Apache Airflow Providers

apache-airflow==3.1.3
apache-airflow-core==3.1.3
apache-airflow-providers-cncf-kubernetes==10.6.0
apache-airflow-providers-common-compat==1.9.0
apache-airflow-providers-common-io==1.6.5
apache-airflow-providers-common-sql==1.29.0
apache-airflow-providers-openlineage==2.9.0
apache-airflow-providers-postgres==6.4.1
apache-airflow-providers-smtp==2.3.2
apache-airflow-providers-standard==1.9.2
apache-airflow-task-sdk==1.1.3

Deployment

Other Docker-based deployment

Deployment details

We deploy airflow on kubernetes similarly to the officical Airflow helm chart but than using our own operator.

Anything else?

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. changed the title [-]n+1 queries still exists in the Airflow UI[/-] [+]n+1 calls problem still occuring in the Airflow UI[/+] on Dec 18, 2025
  2. sania-2912 commented on Dec 18, 2025

    @sania-2912

    Hi, I’d be happy to take a look at this issue.

    Since it’s currently unassigned, I can start investigating it. From an initial look, it seems that the Tasks tab in the UI may be triggering one API call per task, which can lead to N+1 calls for larger DAGs and cause scalability issues.

    I’ll begin by profiling the UI/API interaction and share my findings here before proposing or opening a PR.
    Thanks!

  3. potiuk commented on Dec 18, 2025

    @potiuk
    Member

    I think it's worth checking if it is the same for 3.1.5 ? This is the latest version released - and the report is about 3.1.3 which is quite "old news" already and a number of things in UI has been fixed.

  4. added and removed
    needs-triagelabel for new issues that we didn't triage yet
    on Dec 18, 2025
  5. potiuk commented on Dec 18, 2025

    @potiuk
    Member

    Can you confirm @nclaeys that it's the same in 3.1.5 ?

  6. tirkarthi commented on Dec 18, 2025

    @tirkarthi
    Contributor

    I think this is an intentional design in #46296 . In my initial implementation in #44604 I used the all task instances for a dag with dag run id as "~" which returned only 100 task instances. Perhaps this page can use a UI specific API since all the fields from public API for a task instance are not used here.

    cc: @bbovenzi

  7. nclaeys commented on Dec 22, 2025

    @nclaeys
    ContributorAuthor

    @potiuk I can confirm the same logic still exists on Airflow 3.1.5. I have just tested it.

  8. Shally-Katariya commented on Dec 27, 2025

    @Shally-Katariya
    Contributor

    Hi! I recently contributed a fix related to unnecessary polling in the Airflow UI
    (HITL polling on the DAG page).

    I’m interested in helping further with UI performance issues, and I’ve been
    looking into the N+1 calls behavior on the Tasks tab.

    I plan to first understand the current data-fetching flow and the linked PR (#59814),
    and I can help with testing, review, or follow-up improvements if needed.

  9. Shally-Katariya commented on Dec 27, 2025

    @Shally-Katariya
    Contributor

    Summarizing the issue:

    1️ The issue affects the DAG Tasks tab in the Airflow UI (/dags/<dag_id>/tasks).

    2️ The problem is an N+1 query pattern where the UI makes one taskInstances
    API call per task, leading to hundreds of requests for large DAGs.

    3️ A fix is already in progress and linked via PR #59814 by @Arunodoy18,
    which batch-fetches task instances in Tasks.tsx and avoids per-task requests.

    I tested the changes from PR #59814 locally using Breeze, and the N+1 calls
    are no longer present on the Tasks tab. Task cards render correctly with
    batched data.

    Once the PR is merged, this issue should be resolved.

  10. 2 remaining items

  11. github-actions commented on Jan 19, 2026

    @github-actions
    Contributor

    This issue has been closed because it has not received response from the issue author.

  12. nclaeys commented on Jan 19, 2026

    @nclaeys
    ContributorAuthor

    @tirkarthi not stale, this issue still needs resolving. The github actions configuration is very strict here, there was no open question for me to answer on.

  13. tirkarthi commented on Jan 19, 2026

    @tirkarthi
    Contributor

    There were recent changes to close issues with pending response label. Please check on latest Airflow version. Please feel free to propose a PR if you have a solution if exists on latest Airflow so that it can be reviewed or we need to wait for someone to take a look.

  14. nclaeys commented on Jan 19, 2026

    @nclaeys
    ContributorAuthor

    Well it feels a bit unfair to the people spending the effort in writing a detailed bug report to just close it after 2 weeks without resolving the issue.

    I liked the proposal of @Shally-Katariya as it will fix this issue structurally but the PR got closed due to issues. As a result this ticket had no work done, so it is not fixed.

    I think the pending-response label is wrong here. I think the problem is pretty clearly described for someone to pick it up.

  15. removed
    staleStale PRs per the .github/workflows/stale.yml policy file
    on Jan 20, 2026
  16. changed the title [-]n+1 calls problem still occuring in the Airflow UI[/-] [+]UI - N+1 Calls in the Grid[/+] on Jan 20, 2026
  17. changed the title [-]UI - N+1 Calls in the Grid[/-] [+]UI - N+1 Calls in the Tasks Tab[/+] on Jan 20, 2026
  18. pierrejeambrun commented on Jan 20, 2026

    @pierrejeambrun
    Member

    @nclaeys Yes, we forgot to remove the pending-response label, hence the auto closing. Sorry for that.

    Indeed the issue you mention still occurs, that's caused by the Tasks cards trying to load past TI execution. Compared to the Dags card that uses a specific endpoint fetching all at once and that is paginated.

    First of all the get_tasks endpoint should probably be paginated. We don't want 1 api call returning 5000 tasks if the dag is huge. THat would limit the number of parallel call in the UI.

    I think we need to convert the UI table into a simple 'table' not 'card'. If we really want card, we need an extra ui endpoint similar to get_dags ui that will return 'recent_runs' as well in the endpoint. So 1 call -> 1 page of tasks with 14 recent execution.

    I saw in the issues that work has been done to fix n+1 queries (#57561), but it seems this path has been missed.

    I also just want to mention that this is about another problem (hence the confusion). It fixed how the backend would perform N+1 db queries for a single API endpoint call. The issue reported here is how the UI would make multiple calls to the backend to retrieve information.

  19. pierrejeambrun commented on Jan 20, 2026

    @pierrejeambrun
    Member

    Opened #60830 to fix the problem.

  20. nclaeys commented on Jan 21, 2026

    @nclaeys
    ContributorAuthor

    @pierrejeambrun Thanks for the clarification. I like your plan, looking forward to the solution as it will help our users a lot.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions