Flyte Tutorial: Workflow Orchestration for Machine Learning and Data Engineering
Flyte is an open-source workflow orchestration platform purpose-built for machine learning, data engineering, and data science workloads. Developed by Union.ai and battle-tested at companies like Spotify, Lyft, and Freenome, Flyte provides a scalable, reproducible, and production-ready way to manage data and ML pipelines.
Unlike traditional workflow orchestrators such as Airflow that focus primarily on task scheduling, Flyte was designed from the ground up with deep understanding of ML requirements: data and model versioning, type safety, computation caching, and native container execution support. In this tutorial, we will learn Flyte from installation through building production-ready ML pipelines.
Why Flyte?
Before diving in, let's understand why Flyte is becoming an increasingly popular choice in the MLOps ecosystem:
Installation and Setup
Prerequisites
Ensure your system has:
- Python 3.8 or newer
- Docker (for running Flyte locally)
- pip or conda for package management
Installing Flytekit
Flytekit is the Python SDK for writing Flyte workflows:
pip install flytekit
For additional features like Pandas integration and visualization:
pip install flytekit[pandas]
pip install flytekitplugins-deck-standard
Running Flyte Locally
Flyte provides a sandbox for local development using Docker:
pip install flytectl
flytectl demo start
This command will run a complete Flyte cluster in Docker, including:
- Flyte Admin (API server)
- Flyte Console (web UI)
- Flyte Propeller (workflow engine)
- MinIO (object storage)
- PostgreSQL (metadata store)
Once successful, access the Flyte Console at http://localhost:30080/console.
For a lighter alternative, you can run workflows locally without a cluster:
pyflyte run myworkflow.py myworkflow --inputparam value
Core Concepts
Tasks
A task is the smallest unit of work in Flyte. It's a Python function decorated with @task:
from flytekit import task
@task
def sayhello(name: str) -> str:
return f"Hello, {name}!"
Note that type hints are mandatory. Flyte uses them for validation and data serialization.
Workflows
Workflows combine multiple tasks into a pipeline:
from flytekit import task, workflow
@task
def sayhello(name: str) -> str:
return f"Hello, {name}!"
@task
def greetinglength(greeting: str) -> int:
return len(greeting)
@workflow
def myworkflow(name: str) -> int:
greeting = sayhello(name=name)
length = greetinglength(greeting=greeting)
return length
Running Workflows
There are several ways to run workflows:
# Run locally (for development)
pyflyte run myworkflow.py myworkflow --name "Flyte"
Run on a Flyte cluster
pyflyte run --remote myworkflow.py myworkflow --name "Flyte"
Or run directly from Python:
if name == "main":
result = myworkflow(name="Flyte")
print(f"Result: {result}")
Basic Usage: Data Processing Pipeline
Let's build a simple data processing pipeline using Flyte:
import pandas as pd
from flytekit import task, workflow
from flytekit.types.file import FlyteFile
@task
def loaddata(filepath: str) -> pd.DataFrame:
"""Read dataset from a CSV file."""