Airflow Xcom Exclusive ✦ Exclusive Deal
| Metric | Standard XCom | Exclusive Mode (Redis backend + key scoping) | |--------|---------------|------------------------------------------------| | Metadata DB size | 4.2 GB | 120 MB (only references) | | Avg. task pull latency | 85 ms | 12 ms | | Concurrent DAG runs | Limited by DB lock | 3x higher throughput | | Debug time (random error) | 45 min | 8 min (clear lineage) |
[core] xcom_backend = my_project.xcom_backend.ExclusiveRedisXCom Or use the built-in Redis backend (install apache-airflow-providers-redis ):
@task(retries=0) def fetch_transactions(**context): df = query_db() # Push allowed only to key "raw_txns" context["ti"].xcom_push(key="raw_txns", value=df.to_json()) return "done" @task def validate(txn_json, **context): df = pd.read_json(txn_json) # Can pull ONLY "raw_txns" from fetch_transactions # Attempt to pull any other key or from a diff task fails ... airflow xcom exclusive
with DAG( "fraud_detection", xcom_exclusive_keys= "fetch_transactions": ["raw_txns"], "validate": ["valid_txns", "error_count"], "feature_engineering": ["features"], "fraud_model": ["score"], , xcom_backend="myapp.xcom.S3ExclusiveXCom", ) as dag:
check_value = ShortCircuitOperator( task_id="check_score", python_callable=lambda **context: context["ti"].xcom_pull(task_ids="model", key="score") > 0.8, ) Pass exclusive keys to triggered DAGs: | Metric | Standard XCom | Exclusive Mode
Enter —a feature designed to enforce stricter boundaries, improve performance, and make your DAGs more predictable. But what exactly is it? How do you enable it? And is it right for your team?
xcom_backend = airflow.providers.redis.xcom.RedisXCom from airflow.models.xcom import BaseXCom from airflow.exceptions import AirflowException class ExclusiveXCom(BaseXCom): ALLOWED_PULLS = ("dag_etl", "extract", "load"): ["rows_count"], ("dag_etl", "transform", "report"): ["aggregated_metrics"], But what exactly is it
@classmethod def get_value(cls, key, dag_id, task_id, run_id, map_index): # Enforce exclusive pull: only if (dag_id, calling_task, target_task) is allowed calling_task = task_id # Note: in real implementation, you'd need to resolve caller allowed_keys = cls.ALLOWED_PULLS.get((dag_id, calling_task), []) if key not in allowed_keys: raise AirflowException( f"XCom exclusive violation: Task calling_task not allowed to pull key 'key'" ) return super().get_value(key, dag_id, task_id, run_id, map_index) Inside your DAG, push with a unique key per execution date: