Skip to main content
πŸ“˜ Complete PDF

Airflow Certification Practice Test 08

Practice Test 08

Question 1 of 20
πŸ“‹ Multiple Choice
Question 141
A newly joined Data Engineer at a retail enterprise needs a workflow task to pause and wait until a third-party supplier's daily inventory file lands in an Amazon S3 bucket before triggering downstream transformation tasks. Which Airflow architectural feature BEST matches this polling and synchronization requirement?
βœ“
A. Airflow Sensor (e.g., S3KeySensor)
B. Airflow Variable
C. Airflow XCom
D. Airflow Pool
Answer
βœ… A. Airflow Sensor (e.g., S3KeySensor)
Explanation

1. Direct Question Answer & Core Concept βœ… A. Airflow Sensor (e.g., S3KeySensor)

Core Concept: Airflow Sensors are specialized operators designed to wait for a specific external condition (file arrival, database record, partition, or API status) to be met before permitting downstream task execution.

2. Deep-Dive Analytical Explanation When a workflow depends on an external asynchronous event (like a supplier dropping a file into S3), using standard Python sleep loops inside PythonOperators wastes worker slots. Airflow Sensors (e.g., `S3KeySensor`, `HttpSensor`, `ExternalTaskSensor`) repeatedly check ('poke') the target resource at configured intervals. In modern Airflow, running sensors in `mode='reschedule'` releases the worker slot between checks, maximizing cluster capacity.

3. Comprehensive Option Analysis & Distractor Dissection - **A. Airflow Variable:** Key-value store in the metadata database used for global configuration, not for polling external file arrival. - **B. Airflow XCom:** Cross-communication mechanism for passing small metadata payloads between tasks in a DAG, not for external event waiting. - **D. Airflow Pool:** Concurrency control mechanism that limits the number of tasks accessing a shared constrained resource.

4. Architectural & Execution Context / Physical Execution Sensors execute in the worker. In `mode='poke'`, the sensor monopolizes the worker slot for its entire duration. In `mode='reschedule'`, if the condition is not met, the sensor task changes state to `UP_FOR_RESCHEDULE`, releases the worker thread, and sleeps until the next poke interval.

5. Practical Code Example

from airflow import DAG
from airflow.providers.amazon.aws.sensors.s3 import S3KeySensor
from datetime import datetime, timedelta

with DAG(
    dag_id="supplier_inventory_ingestion",
    start_date=datetime(2026, 1, 1),
    schedule="@daily",
    catchup=False,
) as dag:
    # Modern resilient sensor releasing worker slot between checks
    wait_for_supplier_file = S3KeySensor(
        task_id="wait_for_supplier_file",
        bucket_name="retail-enterprise-inbound",
        bucket_key="supplier_data/inventory_{{ ds }}.csv",
        aws_conn_id="aws_default",
        poke_interval=60,         # Check every 60 seconds
        timeout=3600,             # Fail if file does not arrive within 1 hour
        mode="reschedule",        # Releases worker slot while sleeping
    )

6. Key Takeaway Use Airflow Sensors with `mode='reschedule'` to wait for external file arrivals and events without exhausting worker concurrency slots.

7. Best Practice & Production Recommendation Always specify a finite `timeout` (e.g., 3600 seconds) and set `mode='reschedule'` on all sensors to prevent deadlock in worker pools.

8. Real-World Engineering Scenario A retail pipeline had 20 daily DAGs using `mode='poke'` sensors waiting for morning vendor files. The sensors occupied all 20 worker slots, starving all other DAGs in the enterprise. Switching to `mode='reschedule'` freed all 20 slots immediately.

9. Common Exam Trap / Anti-Pattern / Misconception Using `mode='poke'` with short poke intervals for long-waiting sensors. This blocks worker concurrency slots and can bring an entire Airflow cluster to a deadlock.

10. Related InsightfulSaga Tutorial Master these concepts in [Airflow Core Architecture & Operations](/tutorials/airflow/sensors-airflow).

Answered: 0 / 20
Question Navigator (Test 08)0% Answered