Prefect
Modern workflow orchestration for data pipelines.
Overview
Prefect is a modern workflow orchestration platform built for Python-first data pipelines, offering a developer-friendly alternative to traditional tools like Apache Airflow. Created to address the complexity and rigidity of existing orchestration solutions, Prefect enables data engineers and data scientists to build dynamic, observable workflows using native Python code with decorators and intuitive APIs. The platform emphasizes ease of development, automatic retries, and real-time monitoring while supporting everything from simple ETL jobs to complex machine learning pipelines.
This stack pairs Prefect's orchestration engine with PostgreSQL as the backend database, creating a production-ready workflow management system. PostgreSQL stores Prefect's flow run metadata, task states, deployment configurations, and execution history, while providing ACID compliance and robust querying capabilities for workflow analytics. The combination offers persistent state management, detailed audit trails, and the ability to scale from single-user development environments to enterprise-grade orchestration platforms.
Data teams building Python-centric pipelines will find this stack particularly valuable, especially those transitioning from notebook-based workflows or seeking alternatives to more complex orchestration tools. Organizations processing data at scale, managing ML model training pipelines, or coordinating multi-step ETL processes benefit from Prefect's dynamic task generation and PostgreSQL's reliability. The setup is ideal for teams that value development velocity and observability while maintaining production-grade data persistence and workflow state management.
Key Features
- Pythonic workflow definition using decorators and native Python functions
- Dynamic task generation and conditional workflow execution based on runtime data
- Built-in automatic retry mechanisms with exponential backoff and custom retry conditions
- Real-time flow run monitoring with detailed execution graphs and task state visualization
- Work pools and agent-based execution for distributed processing across multiple environments
- PostgreSQL-backed persistent storage for flow metadata, run history, and deployment configurations
- Caching and result persistence to optimize expensive computations and enable workflow resumption
- Block-based configuration system for managing secrets, storage connections, and third-party integrations
Common Use Cases
- 1Data engineering teams building ETL pipelines with complex dependencies and conditional logic
- 2ML engineers orchestrating model training, evaluation, and deployment workflows
- 3Financial institutions running daily risk calculations and regulatory reporting pipelines
- 4E-commerce companies managing inventory updates, recommendation model retraining, and analytics aggregation
- 5Research organizations coordinating multi-stage data processing for scientific computing
- 6DevOps teams automating infrastructure provisioning and application deployment workflows
- 7Startups transitioning from cron jobs and manual scripts to observable, maintainable pipeline automation
Prerequisites
- Minimum 1.5GB RAM (512MB for Prefect server, 256MB for PostgreSQL, plus workflow execution overhead)
- Port 4200 available for Prefect UI and API access
- Basic Python knowledge for creating flows and understanding decorator-based workflow definitions
- PostgreSQL familiarity for database maintenance and query optimization
- Understanding of workflow orchestration concepts like task dependencies and state management
- Docker Compose environment with network connectivity between services
For development & testing. Review security settings, change default credentials, and test thoroughly before production use. See Terms
docker-compose.yml
docker-compose.yml
1services: 2 prefect-server: 3 image: prefecthq/prefect:2-python3.114 container_name: prefect-server5 restart: unless-stopped6 command: prefect server start --host 0.0.0.07 environment: 8 PREFECT_API_DATABASE_CONNECTION_URL: postgresql+asyncpg://${DB_USER}:${DB_PASSWORD}@postgres:5432/${DB_NAME}9 ports: 10 - "4200:4200"11 depends_on: 12 - postgres13 networks: 14 - prefect1516 postgres: 17 image: postgres:16-alpine18 container_name: prefect-postgres19 environment: 20 POSTGRES_DB: ${DB_NAME}21 POSTGRES_USER: ${DB_USER}22 POSTGRES_PASSWORD: ${DB_PASSWORD}23 volumes: 24 - postgres_data:/var/lib/postgresql/data25 networks: 26 - prefect2728volumes: 29 postgres_data: 3031networks: 32 prefect: 33 driver: bridge.env Template
.env
1DB_NAME=prefect2DB_USER=prefect3DB_PASSWORD=changemeUsage Notes
- 1Docs: https://docs.prefect.io/
- 2UI at http://localhost:4200 - flow runs, deployments, work pools
- 3Configure client: prefect config set PREFECT_API_URL=http://localhost:4200/api
- 4Create flow: @flow decorator, run locally or deploy to server
- 5Start worker: prefect worker start -p default-agent-pool
- 6Blocks for secrets, storage, and integrations in UI
Individual Services(2 services)
Copy individual services to mix and match with your existing compose files.
prefect-server
prefect-server:
image: prefecthq/prefect:2-python3.11
container_name: prefect-server
restart: unless-stopped
command: prefect server start --host 0.0.0.0
environment:
PREFECT_API_DATABASE_CONNECTION_URL: postgresql+asyncpg://${DB_USER}:${DB_PASSWORD}@postgres:5432/${DB_NAME}
ports:
- "4200:4200"
depends_on:
- postgres
networks:
- prefect
postgres
postgres:
image: postgres:16-alpine
container_name: prefect-postgres
environment:
POSTGRES_DB: ${DB_NAME}
POSTGRES_USER: ${DB_USER}
POSTGRES_PASSWORD: ${DB_PASSWORD}
volumes:
- postgres_data:/var/lib/postgresql/data
networks:
- prefect
Quick Start
terminal
1# 1. Create the compose file2cat > docker-compose.yml << 'EOF'3services:4 prefect-server:5 image: prefecthq/prefect:2-python3.116 container_name: prefect-server7 restart: unless-stopped8 command: prefect server start --host 0.0.0.09 environment:10 PREFECT_API_DATABASE_CONNECTION_URL: postgresql+asyncpg://${DB_USER}:${DB_PASSWORD}@postgres:5432/${DB_NAME}11 ports:12 - "4200:4200"13 depends_on:14 - postgres15 networks:16 - prefect1718 postgres:19 image: postgres:16-alpine20 container_name: prefect-postgres21 environment:22 POSTGRES_DB: ${DB_NAME}23 POSTGRES_USER: ${DB_USER}24 POSTGRES_PASSWORD: ${DB_PASSWORD}25 volumes:26 - postgres_data:/var/lib/postgresql/data27 networks:28 - prefect2930volumes:31 postgres_data:3233networks:34 prefect:35 driver: bridge36EOF3738# 2. Create the .env file39cat > .env << 'EOF'40DB_NAME=prefect41DB_USER=prefect42DB_PASSWORD=changeme43EOF4445# 3. Start the services46docker compose up -d4748# 4. View logs49docker compose logs -fOne-Liner
Run this command to download and set up the recipe in one step:
terminal
1curl -fsSL https://docker.recipes/api/recipes/prefect/run | bashTroubleshooting
- Connection refused when accessing UI: Verify prefect-server container is running and port 4200 is properly mapped
- Database connection errors on startup: Check PostgreSQL container health and ensure PREFECT_API_DATABASE_CONNECTION_URL matches postgres credentials
- Flows not appearing in UI: Run 'prefect config set PREFECT_API_URL=http://localhost:4200/api' to configure client connection
- Worker not picking up flow runs: Start a worker with 'prefect worker start -p default-agent-pool' and ensure work pool exists
- PostgreSQL data loss after container restart: Verify postgres_data volume is properly mounted and persistent
- Flow runs stuck in pending state: Check that worker pools are configured and workers are actively polling for work
Community Notes
Loading...
Loading notes...
Download Recipe Kit
Get all files in a ready-to-deploy package
Includes docker-compose.yml, .env template, README, and license
Ad Space
Shortcuts: C CopyF FavoriteD Download