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:- Next.js — frontend and API routes
- UploadThing — handles CSV file uploads
- Trigger.dev Realtime — streams progress updates back to the browser
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.triggerAndWaitto 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
TheuseRealtimeRun hook subscribes to the parent task’s run and exposes its metadata, which
includes the live progress values:
src/hooks/useRealtimeCSVValidator.ts
CSVProcessor component renders a progress bar driven by this hook:
src/components/CSVProcessor.tsx
Key concepts used
| Concept | How it’s used |
|---|---|
batch.triggerAndWait | Fan out row processing to child tasks and wait for all to complete |
metadata.set | Store progress state on the run so the frontend can read it |
metadata.parent | Allow child tasks to update the parent task’s metadata |
useRealtimeRun | Subscribe to the run from the frontend and receive live updates |
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