# Airflow XCom

> A small note one Airflow task leaves for another. It might be a file name or a count.

**Field:** Data Engineering  
**Category:** Orchestration  
**Also known as:** XCom, Cross-Communication

## Think of it like

It is like a sticky note left on the fridge for the next person. It holds a few words, not a whole book.

## Definition

XCom is how one Airflow task passes a small value to another. XCom is short for cross-communication. A task pushes a value, such as a file name or a row count. A later task pulls it by the first task's ID. When a task function returns a value, Airflow pushes it for you. XComs are kept in Airflow's database by default, so they are meant to be small.

## Example

An extract task writes a file to the cloud and pushes its path. The load task pulls the path and reads the file from there.

## Example code

```python
@task
def count_rows():
    return 1250          # pushed to XCom

@task
def report(n):
    print(f"{n} rows")   # pulled from XCom

report(count_rows())
```

The return value of count_rows travels to report through XCom. No file is written.

## Why it matters

Tasks may run on different machines, so they cannot share memory. XCom is the safe way to hand over a pointer to the data.

## Common mistake

Passing a whole table through XCom. It bloats Airflow's database. Pass the file path instead.

## Three principles

- **Small values.** IDs, paths and counts, not data.
- **Push and pull.** One task writes, a later one reads.
- **Kept in the database.** Stored with the run by default.

## Related terms

- [Airflow Task](https://learn.benibix.com/term/data/airflow-task)
- [Airflow Metadata Database](https://learn.benibix.com/term/data/airflow-metadata-database)
- [Airflow DAG](https://learn.benibix.com/term/data/airflow-dag)
- [Apache Airflow](https://learn.benibix.com/term/data/apache-airflow)
- [Airflow TaskFlow API](https://learn.benibix.com/term/data/airflow-taskflow-api)

![An operator box labelled BashOperator becomes a task called load_orders inside a DAG. Below it, three DAG runs for 1, 2 and 3 March each hold one task instance with its own status: success, success and running. The third run also shows an XCom carrying a file path.](https://learn.benibix.com/diagrams/airflow-operator-task.svg)

---

Source: https://learn.benibix.com/term/data/airflow-xcom
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
