0
0
Apache Airflowdevops~20 mins

Why XCom enables task communication in Apache Airflow - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
XCom Communication Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
How does XCom facilitate communication between Airflow tasks?

In Apache Airflow, tasks often need to share data. Which of the following best explains how XCom enables this communication?

AXCom creates temporary files on the worker machine that tasks read and write to exchange data.
BXCom stores small messages or data in Airflow's metadata database, allowing tasks to push and pull information asynchronously.
CXCom sends data directly over network sockets between running tasks in real-time.
DXCom uses environment variables set globally on the Airflow server to share data between tasks.
Attempts:
2 left
💡 Hint

Think about where Airflow keeps task metadata and how tasks can access shared information.

💻 Command Output
intermediate
2:00remaining
What is the output of this XCom push and pull example?

Consider two Airflow tasks where task A pushes a value to XCom and task B pulls it. What will be printed by task B?

Apache Airflow
from airflow import DAG
from airflow.operators.python import PythonOperator
from datetime import datetime

def push_function(ti):
    ti.xcom_push(key='sample_key', value='hello world')

def pull_function(ti):
    value = ti.xcom_pull(key='sample_key', task_ids='push_task')
    print(value)

dag = DAG('xcom_example', start_date=datetime(2023, 1, 1))

push_task = PythonOperator(task_id='push_task', python_callable=push_function, dag=dag)
pull_task = PythonOperator(task_id='pull_task', python_callable=pull_function, dag=dag)
push_task >> pull_task
Ahello world
BKeyError: 'sample_key'
CNone
DSyntaxError
Attempts:
2 left
💡 Hint

Remember that task B pulls the value pushed by task A using the same key and task ID.

Troubleshoot
advanced
2:00remaining
Why does this XCom pull return None?

A developer notices that their task pulling from XCom always gets None. The push task runs before the pull task. What is the most likely cause?

Apache Airflow
def pull_function(ti):
    value = ti.xcom_pull(key='data_key', task_ids='push_task')
    print(value)

# The push task uses ti.xcom_push(key='data_key', value='data') correctly.
AThe pull task runs before the push task, so no data is available yet.
BThe key used in xcom_pull does not match the key used in xcom_push.
CThe push task did not run successfully or did not push any value.
DXCom only works with JSON-serializable data, and the pushed data was not serializable.
Attempts:
2 left
💡 Hint

Check if the push task actually completed and pushed data.

🔀 Workflow
advanced
2:00remaining
Which Airflow feature allows tasks to share data asynchronously?

In a complex DAG, tasks need to exchange small pieces of data without direct connections. Which Airflow feature is designed for this purpose?

AXCom, which stores data in the metadata database for tasks to push and pull asynchronously.
BVariables, which store global configuration values accessible by all tasks.
CPools, which limit concurrent task execution but do not share data.
DConnections, which store credentials for external systems.
Attempts:
2 left
💡 Hint

Think about a feature that allows tasks to exchange data during DAG execution.

Best Practice
expert
3:00remaining
What is the best practice when using XCom for task communication in Airflow?

When using XCom to share data between tasks, which practice helps avoid common issues?

AAvoid specifying keys when pushing data to XCom to reduce complexity.
BPush large files directly into XCom to simplify data sharing.
CUse environment variables to store sensitive data instead of XCom.
DKeep the data small and JSON-serializable to prevent database bloat and serialization errors.
Attempts:
2 left
💡 Hint

Consider how XCom stores data and what limitations it has.