0
0
Apache Airflowdevops~20 mins

Sharing data between tasks effectively in Apache Airflow - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
XCom Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
How does XCom share data between tasks?

In Apache Airflow, what is the primary mechanism used to share small pieces of data between tasks?

AWriting data to a shared file system manually.
BUsing XCom to push and pull data between tasks.
CPassing data through environment variables automatically.
DUsing global Python variables accessible by all tasks.
Attempts:
2 left
💡 Hint

Think about the built-in Airflow feature designed for inter-task communication.

💻 Command Output
intermediate
1:30remaining
Output of XCom pull with no matching key

What is the output of the following Airflow PythonOperator task code snippet when no XCom value exists for the given key?

Apache Airflow
ti.xcom_pull(key='nonexistent_key', task_ids='task_a')
A'' (empty string)
BRaises KeyError
CNone
D0
Attempts:
2 left
💡 Hint

Consider what Airflow returns when no XCom value is found for a key.

Configuration
advanced
2:00remaining
Correct XCom push syntax in a PythonOperator

Which code snippet correctly pushes a value to XCom inside a PythonOperator's callable function?

A
def task_func():
    xcom_push(key='result', value=42)
B
def task_func(ti):
    ti.xcom_push('result', 42)
C
def task_func(ti):
    ti.push_xcom(key='result', value=42)
D
def task_func(ti):
    ti.xcom_push(key='result', value=42)
Attempts:
2 left
💡 Hint

Remember the method name and parameters for pushing XCom data.

🔀 Workflow
advanced
2:00remaining
Best practice for sharing large data between tasks

Which approach is best for sharing large datasets between Airflow tasks?

AStore the data in an external storage like S3 or a database and pass the reference via XCom.
BPush the entire dataset directly via XCom between tasks.
CSerialize the data as a string and push it via XCom.
DUse global variables in the DAG file to share data.
Attempts:
2 left
💡 Hint

Think about XCom size limits and performance.

Troubleshoot
expert
2:30remaining
Why does XCom pull return None unexpectedly?

You have two tasks: task_a pushes a value to XCom with key 'data', and task_b tries to pull it. But task_b always gets None. What is the most likely cause?

Atask_b runs before task_a completes, so the XCom value is not yet available.
BThe key used in task_b's xcom_pull is misspelled.
CXCom backend is disabled in Airflow configuration.
Dtask_a did not push any value to XCom.
Attempts:
2 left
💡 Hint

Consider task execution order and dependencies.