Pass file paths, not dataframes, through Airflow XComs
Use Airflow XComs to pass small metadata such as file URIs between tasks instead of large payloads that bloat the metadata database.
28 Jun 2026, 19:21 UTC

The problem: a task that passes too much through XCom
Imagine a DAG that extracts a daily report, transforms it with pandas, and loads the result into a warehouse. The extract task pushes the entire DataFrame to XCom so the transform task can pull it. It works on a small sample, but in production the metadata database grows, the scheduler slows, and the task eventually fails with a serialization or size error.
XCom—short for cross-communication—is Airflow's mechanism for tasks to exchange small amounts of metadata within a single DAG run. It is not a data pipeline. The practical takeaway: use XComs to pass pointers such as object-storage URIs or database table names, and keep the actual payload in storage.
How XComs fit in a DAG run
Each task instance can push a value with a key, and a downstream task can pull that value by key and task ID. Airflow stores XComs in the metadata database, so every large value increases database size and scheduler load. Values must also be serializable, which rules out many open file handles or complex objects.
Worked example: pass an S3 path instead of a DataFrame
Place this DAG in your Airflow dags/ folder. You need write permission to the DAGs directory and an Airflow user able to parse DAG files. Replace s3://your-bucket/daily-report/{{ ds }}.parquet with a real bucket path.
from airflow import DAG
from airflow.operators.python import PythonOperator
from airflow.utils.dates import days_ago
import pendulum
def extract(**context):
# Simulate writing a file to object storage.
output_path = "s3://your-bucket/daily-report/{{ ds }}.parquet"
# In a real task, write your dataframe or file here.
context["ti"].xcom_push(key="report_path", value=output_path)
def transform(**context):
ti = context["ti"]
report_path = ti.xcom_pull(task_ids="extract", key="report_path")
if not report_path:
raise ValueError("No report path received from extract")
# Read from storage, not from XCom.
print(f"Reading report from {report_path}")
with DAG(
dag_id="report_pipeline",
start_date=pendulum.datetime(2026, 1, 1, tz="UTC"),
schedule="@daily",
catchup=False,
tags=["example"],
) as dag:
extract_task = PythonOperator(
task_id="extract",
python_callable=extract,
)
transform_task = PythonOperator(
task_id="transform",
python_callable=transform,
)
extract_task >> transform_task
Run airflow dags list from the Airflow scheduler or webserver host to confirm the DAG parses. Then trigger report_pipeline in the UI and inspect the task instance details for transform. The log should show the pulled URI, and no large object should appear in the XCom value.
Risk: if a downstream task pulls a nonexistent key, xcom_pull returns None by default and can fail later with an unclear error. Always validate the pulled value before using it.
Limitation: XComs are metadata, not a data bus
XComs work well for keys, dates, file URIs, and small JSON summaries. They are a poor fit for dataframes, images, or log files. Large values bloat the metadata database and can exceed serialization limits. For shared data, write to object storage, a shared filesystem, or a database table, then push only the location.
To check whether XComs are growing unexpectedly, review the size of your Airflow metadata database's XCom table or inspect large XCom values in the task instance details view. If a DAG run shows multi-megabyte XCom entries, refactor those tasks to write to storage first.
Closing checklist
- Ask whether the value being pushed is small enough to store in the metadata database.
- Push storage URIs, table names, or job IDs rather than file contents.
- Validate pulled XCom values before downstream logic runs.
- Monitor XCom table growth as part of routine Airflow maintenance.