Skip to content

[Feature]: Database Backup & Export Pipeline (Async Workers & Streams) #176

@yash-pouranik

Description

@yash-pouranik

Description

Developers using urBackend currently have no way to download or backup their project's data. If they want to migrate, analyze their data locally, or create a snapshot, they are stuck. We need an asynchronous pipeline to export collection data to JSON or CSV formats.

Since collections can grow large, doing this synchronously via an HTTP request will cause timeouts and memory crashes. We need a background job system using BullMQ and Mongoose Streams to handle this safely.

Goals

  • Add a new endpoint POST /api/projects/:projectId/export in the dashboard API to trigger the export job.
  • Implement a background worker using BullMQ that connects to the project's MongoDB instance.
  • Safely stream the data out using Model.find().cursor() to avoid running out of memory.
  • Convert the stream to JSON/CSV and upload it to the project's Supabase Storage bucket.
  • Send an email to the project owner (using the existing Mail API/emailService) with a secure, temporary download link once the export is complete.

Implementation Steps

  1. Queue Setup: Create a new dataExportQueue and worker in packages/common/src/queues.
  2. Dashboard API: Create the trigger endpoint in apps/dashboard-api and ensure only the project owner can trigger it.
  3. Worker Logic:
    • Use cursor() on the Mongoose model to stream documents.
    • Transform and pipe the data to a temporary file or directly to the Storage bucket (using apps/public-api/src/controllers/storage.controller.js logic as a reference).
    • Generate a presigned download URL.
  4. Email Notification: Dispatch an email to the user with the download link upon job success, or a failure notification if it errors out.

Skills Required

  • Node.js & Express
  • Mongoose (Streams and Cursors)
  • BullMQ (Background Jobs)
  • Supabase Storage

Acceptance Criteria

  • Endpoint successfully enqueues an export job.
  • Worker successfully streams data without crashing on collections > 100k documents.
  • Exported file is accessible via a secure link sent to the project owner's email.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions