Any PythonOperator that returns a value automatically pushes that value to XCom with the key return_value .
To make Airflow use your custom backend, configure the environment variable or update your airflow.cfg :
To get the most out of Airflow XCom exclusive, follow these best practices: airflow xcom exclusive
Automatically saves the URI string into the Airflow metadata database.
: Stores a value in the Airflow metadata database. Many operators (and any @task function) automatically push their return value to a special key called return_value by default. Any PythonOperator that returns a value automatically pushes
XCom data accumulates rapidly, leading to performance bottlenecks. Implement a maintenance DAG that runs weekly to purge expired or non-essential XCom rows directly from the metadata database using the SecretKeeper pattern or standard SQLAlchemy cleanup tasks:
t1 = PythonOperator( task_id='task_1', python_callable=task1, dag=dag, ) Many operators (and any @task function) automatically push
To understand when XCom is appropriate, compare it to other Airflow features:
The 48KB limit is a hard constraint in the default XCom implementation. Here's why it matters:
from airflow.decorators import dag, task import pendulum @dag(start_date=pendulum.datetime(2026, 1, 1), schedule=None, catchup=False) def modern_xcom_workflow(): @task def generate_user_id(): # Automatically pushed to XCom under 'return_value' return 42951 @task def process_user(user_id: int): # Automatically pulled from XCom behind the scenes print(f"Processing data for user: user_id") user_data = generate_user_id() process_user(user_data) modern_xcom_workflow() Use code with caution. 4. Exclusive Feature: Custom XCom Backends
To ensure your Airflow pipelines remain performant, reliable, and clean, observe these strict XCom architectural patterns: