Prefect
Orchestrate Python workflows with Prefect: flows, tasks, retries, caching, deployments, work pools and the Prefect UI.
Intermediate · about 6 hours · difficulty 3/5
Learn first: Orchestration Concepts
Prefect is a Python-native orchestrator that feels like writing normal Python. You decorate functions and get retries, logging, scheduling and a UI with very little boilerplate. It is popular with small teams and ML-heavy workflows.
Core concepts
- Flows:
@flowdecorated functions; the unit of orchestration. - Tasks:
@taskdecorated functions inside flows, with retries, timeouts and caching options. - Flows can be dynamic: loops and conditionals in plain Python decide what runs.
- Deployments attach schedules and parameters to a flow so it runs on infrastructure.
- Work pools and workers decide where runs execute: a local process, Docker, Kubernetes or serverless cloud.
- Blocks store configuration and credentials (S3, databases, Slack).
Observability
The Prefect UI (self-hosted server or Prefect Cloud's free tier) shows flow runs, task states, logs and failures, and supports automations such as alerting on failure.
Why teams choose it
- Very low friction for Python developers.
- Dynamic workflows are natural.
- Easy to run locally and test.
Trade-offs
Fewer prebuilt integrations than Airflow and less presence in Indian job descriptions. Backfills and partitioned data need more explicit design than in Dagster.
Pitfalls
- Treating Prefect as a magic retry wrapper while tasks are still not idempotent.
- Passing huge DataFrames between tasks instead of writing to storage.
You are ready to move on when you can deploy a scheduled Prefect flow that extracts, loads and runs dbt with retries, view its runs in the UI, and rerun it for a past date via parameters.
Key concepts
- Flows and tasks
- Retries, timeouts, caching
- Deployments and schedules
- Work pools and workers
- Blocks for config and secrets
- Automations and alerts
Other options for this step
- Apache Airflow: Build, schedule and operate pipelines with Apache Airflow: DAG files, operators, the TaskFlow API, connections, XComs, scheduling and production best practices.
- Dagster: Orchestrate pipelines as software-defined assets with Dagster: assets, partitions, resources, sensors and built-in lineage and observability.
Mini project
Write a Prefect flow that extracts from a public API, writes Parquet, loads into DuckDB and runs dbt build. Add retries, a date parameter and a daily deployment, then rerun it for three past dates.
Check yourself
How would you implement a backfill in Prefect for the last 30 days, and what must be true about your tasks for it to be safe?
Free resources
- Prefect documentation (Prefect)
- Data Engineering Zoomcamp (DataTalksClub)