# Build Shopify backfill and cleanup jobs with scheduled workflows

Backfill and cleanup jobs repair old records, remove stale data, and keep store operations consistent. They need batching, logs, and safe retry behavior.

Canonical URL: https://blog.jsworkflows.com/articles/build-shopify-backfill-and-cleanup-jobs/

Category: Operations

Some automation does not start from a new order or customer event. It starts from old data that needs to be cleaned up.

Examples include stale draft orders, old customer records, missing metafields, products that need review, or historical orders that need a tag added for reporting.

These are backfill and cleanup jobs. They are often boring, but they are valuable.

## The pain point

Store data gets messy over time.

- Draft orders stay open after they are no longer useful.
- Products miss required tags or metafields.
- Customers need cleanup based on age or activity.
- Historical orders need a tag or note for reporting.
- Catalog records need to be checked after an import.
- A new process needs to be applied to old records.

Doing this manually is slow. Doing it with a one-off script can be risky if there is no run history.

## Why scheduled workflows are useful

A scheduled workflow can process records in controlled batches.

The workflow can:

1. Query a page of Shopify records.
2. Decide which records need action.
3. Update only the records that match the rule.
4. Store progress between steps.
5. Continue later if more pages remain.
6. Retry throttled or transient failures.
7. Send a completion summary.

This is safer than trying to update everything at once.

## Where this differs from simple event automation

[Shopify Flow](https://help.shopify.com/en/manual/shopify-flow/reference) supports event and scheduled workflows, and its own documentation describes Flow workflows as triggers, conditions, and actions. That is a good model for many store rules.

Backfill work often needs more control over paging, batching, progress tracking, and partial failure handling. JsWorkflows is useful when the job behaves more like a controlled data process than a single trigger-action rule.

## Good cleanup candidates

Good scheduled cleanup jobs have clear criteria.

- Delete stale draft orders after a set number of days.
- Archive products that have been out of stock for a long time.
- Add missing metafields from existing product data.
- Remove temporary tags after a campaign ends.
- Flag products missing required merchandising fields.
- Recalculate customer tags from historical order count.

The best cleanup jobs are specific and reversible, or at least easy to audit.

## Keep the job safe

Cleanup workflows should be conservative.

- Start in report-only mode when possible.
- Log records that would be changed.
- Process small batches first.
- Use clear filters.
- Send a summary.
- Avoid deleting data unless the rule is well tested.

For risky cleanup, a workflow can first add a review tag or send a report instead of changing the final field immediately.

## Merchant-configurable settings

Backfill jobs usually need simple setup fields:

- Age threshold.
- Product type or vendor filter.
- Tags to include or exclude.
- Notification email.
- Dry-run or active mode.

Technical settings such as page size, retry count, and continuation delay should stay in code.

## Why this matters

Backfill and cleanup jobs improve trust in store data.

They also reduce hidden operational debt. Instead of relying on someone to remember a monthly cleanup task, the workflow runs on a schedule, logs what happened, and reports the result.

That is the difference between a script and an operational workflow.

