Sharing data between tasks effectively
📖 Scenario: You are building a simple Airflow workflow to process daily sales data. The first task fetches sales numbers, and the second task calculates the total sales. You want to share the sales data between these tasks efficiently.
🎯 Goal: Build an Airflow DAG where one task pushes sales data, and the next task pulls that data to calculate the total sales.
📋 What You'll Learn
Create a Python dictionary called
sales_data with exact entries: 'Monday': 100, 'Tuesday': 150, 'Wednesday': 200Create a task called
push_sales that pushes sales_data to XComCreate a task called
pull_and_sum_sales that pulls sales_data from XCom and calculates the total salesPrint the total sales in the
pull_and_sum_sales task💡 Why This Matters
🌍 Real World
Sharing data between tasks is common in workflows where one step produces data that the next step needs to use, like processing sales, logs, or user data.
💼 Career
Understanding XCom in Airflow is essential for building reliable data pipelines and workflows in many DevOps and data engineering roles.
Progress0 / 4 steps