Supercharging the ML and AI Development Experience at Netflix with Metaflow

Netflix Technology Blog
10 min readadvanced
--
View Original

Overview

Netflix introduces Spin, a new feature in Metaflow 2.19 that enables rapid, iterative development of ML and AI workflows by executing individual @step functions with preserved state from previous runs. Spin bridges the gap between notebook-style interactive development and production-ready workflow engineering, allowing developers to iterate on individual steps without re-running entire pipelines, while also supporting AI coding agents like Claude Code for accelerated development.

What You'll Learn

1

How to use Metaflow's new spin command to iterate on individual workflow steps without re-running entire pipelines

2

Why state management is a first-class design concern in ML/AI development and how Metaflow addresses it differently than notebooks

3

How to inject custom inputs, inspect outputs, and unit test individual Metaflow steps using spin with the Runner API

4

How to configure AI coding agents like Claude Code to use spin for faster iterative Metaflow development

5

When to use run vs resume vs spin as complementary execution modes in Metaflow workflows

Prerequisites & Requirements

  • Understanding of ML/AI workflow concepts including data pipelines, model training, and iterative development
  • Familiarity with Python and pip package management
  • Basic understanding of Metaflow concepts such as flows, steps, and artifacts
  • VSCode or Cursor IDE for the development experience with keyboard shortcuts and card viewer(optional)
  • Experience with notebook-based development (Jupyter, Observable, or Marimo) to understand the comparison(optional)

Key Questions Answered

What is Metaflow Spin and how does it improve ML development iteration speed?
Spin is a new command in Metaflow 2.19 that quickly executes a single @step with all state carried over from the parent step, similar to running a single notebook cell. Unlike run (which executes the entire flow) or resume (which re-executes from a selected step onward), spin executes only the targeted step without persisting artifacts by default, making it ideal for fast, throw-away iterations during development.
How does Metaflow Spin differ from resume and run execution modes?
Run executes all steps from start to end and creates a full versioned run with metadata. Resume clones previously executed steps and re-executes from a selected step onward, also creating a full versioned run. Spin executes only a single step using state from a previous run, skips tracking altogether, and is designed for fast throw-away iterations. This maps to notebooks: run is like running all cells, resume is like running from a cell onward, and spin is like running a single cell.
How do you inject custom inputs into a Metaflow spin execution?
You can override artifact values by creating a Python module with an ARTIFACTS dictionary containing key-value pairs, then pointing spin at it using the --artifacts-module flag. For example, create an artifacts.py file with ARTIFACTS = {"model": "kmeans", "k": 15} and run 'spin train --artifacts-module artifacts.py'. This allows testing steps with different inputs similar to how notebook cells can use arbitrary variables.
How can you unit test individual Metaflow steps using spin?
Spin can be used programmatically through the Runner API for unit testing. Import Runner from metaflow, then use 'with Runner("flow.py").spin("train", persist=True) as spin:' to execute a step and assert results like 'assert spin.task["model"].data == "kmeans"'. The --persist flag stores artifacts to a local directory-specific location that can be inspected with the Client API using inspect_spin.
How do you configure Claude Code or AI agents to use Metaflow spin effectively?
Add instructions to a CLAUDE.md file describing the incremental development workflow: create a flow skeleton, add a data loading step, run the flow to persist artifacts, then use spin to test individual steps. Provide the exact spin command syntax. Agents benefit because spin accelerates the development loop and surfaces errors faster with context localized to specific code, increasing the chance the agent can self-correct.
What advantages does Metaflow's @step have over notebook cells for ML development?
Metaflow @steps offer three key advantages over notebook cells: execution order is explicit and deterministic (no out-of-order cell execution surprises), state is not hidden but explicitly stored as self. variables that can be discovered and inspected via the Client API, and state is versioned and persisted making results more reproducible. With spin, steps also gain notebook-like fast iteration capability.
How do you use Metaflow spin with VSCode or Cursor for iterative development?
Install the metaflow-dev VS Code extension (works with Cursor too) which maps Ctrl+Opt+R to run and Ctrl+Opt+S to spin. The extension auto-saves the file and spins the step you're currently editing. Combined with Metaflow Cards and the built-in web-view and local card viewer, this enables a workflow where you tweak code and see visual results instantly, particularly powerful for building dashboards and reports.
How do you inspect spin outputs using the Metaflow Client API?
When running spin with the --persist flag, artifacts are stored in a directory-specific location. To access results, import inspect_spin from metaflow, call inspect_spin(".") to point at the directory, then use the standard Client API: Flow("TrainingFlow").latest_run["train"].task["model"].data. This approach keeps spin artifacts separate from the main Metaflow datastore for easy cleanup after testing.

Technologies & Tools

Some links below are affiliate links. We may earn a commission if you make a purchase.

ML/AI Framework
Metaflow
Core workflow framework for ML/AI development, open-sourced by Netflix in 2019, with the new spin feature in version 2.19
Workflow Orchestrator
Maestro
Netflix's open-sourced workflow orchestrator that powers nearly every ML and AI system at Netflix and serves as a backbone for Metaflow
IDE
Vscode
Development environment with the metaflow-dev extension for keyboard shortcut integration and built-in web-view for card visualization
IDE
Cursor
AI-powered IDE compatible with the metaflow-dev extension for spin and run keyboard shortcuts
Notebook
Jupyter
Referenced as a notebook environment for comparison with Metaflow's interactive development approach
Notebook
Observable
Referenced as an alternative notebook environment for data exploration
Notebook
Marimo
Referenced as an alternative notebook environment for data exploration
Workflow Orchestrator
Airflow
Referenced as a comparison point for Metaflow's workflow-like code structure
Workflow Orchestrator
Argo
Production orchestrator that Metaflow flows can be deployed to after local development with spin
Compute Platform
AWS Batch
Cloud compute platform for scaling up Metaflow flows in production
Container Orchestration
Kubernetes
Compute platform for scaling Metaflow flows in production
AI Coding Agent
Claude Code
AI coding agent used by Metaflow users that benefits from spin for faster iterative development loops
Programming Language
Python
Primary language for Metaflow flows and the spin command, enabling idiomatic Python project structure
Data Format
Parquet
File format used in example for reading datasets in Metaflow flows

Key Actionable Insights

1
Adopt the incremental spin-based development workflow for building Metaflow flows: start with a skeleton, run once to persist initial artifacts, then use spin to iterate on individual steps. This approach mirrors notebook-style development but produces production-ready, deployable workflows.
This workflow is especially valuable when steps involve computationally expensive operations like model training, where re-running the entire pipeline for each code change wastes significant time and compute resources.
2
Use the metaflow-dev VSCode/Cursor extension to bind spin and run to keyboard shortcuts (Ctrl+Opt+S and Ctrl+Opt+R respectively), enabling a seamless code-edit-test cycle that rivals notebook interactivity while maintaining production-grade code structure.
The extension automatically saves files before spinning, and combined with the local card viewer in VSCode's built-in web-view, it creates a particularly powerful workflow for developing Metaflow Cards visualizations and dashboards.
3
Leverage spin's artifact injection capability (--artifacts-module) to test steps with different input configurations without modifying flow code. This enables testing inference steps with different models from separate runs or verifying behavior with edge-case data.
Create a Python module with an ARTIFACTS dictionary to override step inputs, then use the --persist flag and inspect_spin to examine outputs, enabling comprehensive testing scenarios without polluting the main Metaflow datastore.
4
Integrate spin into your unit testing strategy using the Runner API programmatically. This allows you to write assertions against individual step outputs, creating focused tests that verify step-level behavior in isolation from the rest of the workflow.
The Runner API's spin method with persist=True stores artifacts locally, and the task accessor lets you assert specific artifact values, making it straightforward to add step-level testing to CI/CD pipelines.
5
Configure AI coding agents (like Claude Code) with CLAUDE.md instructions that describe the spin-based incremental development workflow, including the exact command syntax for run and spin. This nudges agents toward faster iteration loops and helps them surface and fix errors more efficiently.
Agents don't naturally understand execution speed trade-offs, so explicit instructions to use spin for testing individual steps instead of running the entire flow can significantly reduce the agent's development loop time and improve error recovery.
6
Use Metaflow's three complementary execution modes strategically: run for full end-to-end execution and artifact persistence, resume for re-executing from a failure point or changed step onward, and spin for fast throw-away iterations during active development of individual steps.
Understanding the distinction between these modes is critical because run and resume create full versioned runs with metadata, while spin deliberately skips tracking for speed — making each mode appropriate for different stages of the development lifecycle.

Common Pitfalls

1
Running the entire Metaflow flow (using run) for every code change during active development wastes significant time, especially when earlier steps involve computationally expensive operations like data loading or model training. Developers accustomed to notebook workflows may default to this approach without realizing spin exists.
Use spin to iterate on individual steps with preserved state from previous runs, and reserve full run for when you need to persist artifacts or verify end-to-end correctness.
2
When using spin with small data samples for testing, some data classes may be underrepresented, causing downstream steps like model training to fail. The article demonstrates this with Claude Code encountering a stratified sampling issue where a small subset of data led to underrepresented classes.
When sampling data for development, consider using stratified sampling to maintain class distribution proportions, or use spin's artifact injection to provide well-balanced test datasets.
3
Forgetting to run the flow at least once before using spin, which means no artifacts exist to carry state forward into the spun step. Spin depends on previously persisted artifacts from a prior run or resume execution.
Always start the development workflow by creating a minimal flow skeleton and running it to persist initial artifacts before switching to spin-based iteration.
4
Treating spin results as production artifacts. By default, spin deliberately skips tracking and doesn't persist artifacts to the Metaflow datastore, making it unsuitable for recording production results or creating reproducible run records.
Use run or resume when you need full versioned runs with metadata. Spin with --persist stores to a local directory-specific location meant only for development inspection, not production use.

Related Concepts

ML Workflow Orchestration
Notebook-based Development Vs Production Workflows
Checkpoint-based State Management
Artifact Versioning And Persistence
Metaflow Cards Visualization
Unit Testing ML Pipelines
Ai-assisted Code Development
Incremental Flow Development
Configuration Management In ML Systems
Custom Decorators And Composability
Production Deployment With Orchestrators
Stratified Data Sampling