Skip to main content
Welcome back. It’s the first of November — one month before the deadline — and October’s orders just arrived. Your pipeline already ingests, validates, cleans, and transforms raw CSVs into actionable insights, but you still run Jupyter Notebook cells by hand in the right order. Human-driven workflows work, but they’re error-prone and hard to scale. In this lesson we’ll cover:
  • Risks of a manual pipeline
  • Benefits of automation
  • How an orchestrator sequences and tracks pipeline steps
  • A simple, modular pipeline pattern you can run locally or schedule in production
Initially you packaged everything into a single Python script and ran it like this:
The image features a person with a KodeKloud t-shirt standing next to a description of tasks related to data pipelines, accompanied by an animated cat character.
That made execution deterministic (all steps run every time) and reduced mistakes, but the file quickly became hard to read and maintain. Console output for the single-file run might look like:
Splitting into modules To improve readability and reuse, break the single script into focused modules:
  • ingest.py — read and validate raw file, archive it, and log ingestion
  • clean.py — drop or correct invalid rows and save cleaned data
  • transform.py — join cleaned orders to products and customers, compute metrics
Start by centralizing folder and path setup (either in each module or a shared helper). Example setup inside ingest.py to find an orders file:
Design each module as an importable function (e.g., run) that:
  • Accepts explicit parameters (file name, folder paths, etc.)
  • Returns outputs the caller needs (usually an output_folder path) This makes dependencies explicit and facilitates unit testing.
A simple orchestrator script Create run_pipeline.py that imports each module and calls their run functions in order. This file orchestrates the end-to-end flow for a single file:
How modules coordinate Each module receives the specific inputs it needs and returns outputs for downstream stages. The call sequence inside run_pipeline.py becomes explicit and easy to follow:
This pattern makes reasoning about data flow and side effects easier and supports testing modules independently. Idempotency and state tracking To avoid reprocessing the same file, maintain an ingest log or state file that records processing status for each file (e.g., ingested, cleaned, transformed). This allows resuming a failed pipeline without duplicating work.
Use an ingest log or state-tracking file to make your pipeline idempotent: the orchestrator can check previous state and skip already-completed steps.
A simple CSV ingest log is often enough for small pipelines. Example ingest_log.csv:
Using this safety mechanism, the pipeline is safe to run multiple times without double-processing files.
The image shows a person standing in front of a computer screen displaying a code editor with a directory structure and a terminal window. The person is wearing a shirt with a logo and appears to be explaining or demonstrating something related to the code on-screen.
Scheduling and orchestration Right now you still manually trigger the pipeline:
For recurring automation, you have several options depending on scale and requirements.
  • Simple server scheduling: use cron on Unix-like systems.
  • Cloud scheduler: use AWS EventBridge (or similar) to trigger cloud jobs.
  • Full workflow orchestration: use Apache Airflow or Prefect for complex dependencies, retries, monitoring, and team collaboration.
Cron example: edit your crontab with crontab -e and add a line to run the script at midnight on the first of every month (replace with your interpreter and absolute path):
Cron schedule fields are: minute, hour, day of month, month, day of week. For monthly runs at midnight on the first day:
The image shows a diagram explaining time units like seconds and minutes, and a person on the right wearing a "KodeKloud" shirt gesturing while talking.
When to use an orchestrator
  • Use cron or EventBridge for simple periodic tasks (backups, monthly reports).
  • Use Airflow, Prefect, or other orchestrators when you need:
    • Directed acyclic graphs (DAGs) of dependent tasks
    • Retry policies and alerting
    • Visibility and centralized logs
    • Parallel task execution and resource management
The image shows a person wearing a "KodeKloud" shirt standing next to an illustration of a person typing on a laptop, with logos of Apache Airflow and Prefect, and labeled sections such as "More Steps," "Dependencies," and "Teams Involved."
Running the pipeline (example) To process October’s orders, run:
A successful run prints step-by-step logs and outcomes:
If the pipeline is re-run, the ingest log prevents duplication:
Quick reference: module responsibilities
ModuleResponsibilityExample output
ingest.pyRead CSV, validate, archive raw file, update ingest loginsights/2025/10/orders_ingested.csv
clean.pyRemove/correct invalid rows, save dropped rowsinsights/2025/10/orders_clean.csv, orders_dropped.csv
transform.pyJoin with products.csv/customers.csv, compute KPIsTop products/customers reports
Recap
  • Manual pipelines are fragile: they depend on human sequencing and can cause mistakes.
  • Modular automation makes pipelines readable, testable, and maintainable.
  • Use an ingest log or state file to make your pipeline idempotent and resumable.
  • Scheduler/orchestrator choice depends on complexity: cron/EventBridge for simple schedules; Airflow/Prefect for DAGs, retries, monitoring, and team workflows.
Next: complete the hands-on exercise to refactor your single-file pipeline into modular stages and add a simple ingest log.

Watch Video

Practice Lab