Skip to main content

Overview

This Next.js example project demonstrates how to build a CSV importer with live progress updates. When a user uploads a CSV file, a Trigger.dev background task downloads and parses it, then fans out row validation across multiple child tasks. Progress is streamed back to the UI in real time using Trigger.dev Realtime. Tech stack:

GitHub repo

View the Realtime CSV Importer repo

Fork this repo to use it as a starting point for your own CSV import feature.

Demo video

How it works

Task architecture

The processing logic is split across two tasks: csvValidator (parent task)
  • Receives the uploaded file URL
  • Downloads and parses the CSV
  • Splits rows into batches
  • Uses batch.triggerAndWait to dispatch all rows to the child task in parallel
  • Updates its own run metadata with overall progress as child tasks complete
handleCSVRow (child task)
  • Receives a single CSV row
  • Validates the email address (simulated in this example)
  • Reports progress back to the parent using metadata.parent
src/trigger/csv.ts

Streaming progress to the frontend

The useRealtimeRun hook subscribes to the parent task’s run and exposes its metadata, which includes the live progress values:
src/hooks/useRealtimeCSVValidator.ts
The CSVProcessor component renders a progress bar driven by this hook:
src/components/CSVProcessor.tsx

Key concepts used

Learn more

Trigger.dev Realtime

Learn how to subscribe to runs and stream data to your frontend

React hooks

The full reference for Trigger.dev’s React hooks

Run metadata

Store and update arbitrary data on a run, readable from anywhere

Batch triggering

Trigger multiple tasks at once and wait for all results