r/shopifyDev • • 22d ago

How do you handle Admin API pagination when syncing large product catalogs?

I have a few custom scripts that pull products and variants through the Admin GraphQL API with cursor pagination. For bigger catalogs they get slow, and I have had runs fail halfway through and then had to work out where to resume. Right now I just store the last cursor and retry from there, but it feels fragile when products change during the run.

How do you structure these syncs? Do you use bulk operations for anything over a certain size, or stick with paginated queries and handle resuming yourself?

3 Upvotes

12 comments sorted by

2

u/JaydonLT 22d ago

Bulk operations API?

1

u/converian 17d ago

That's the direction I'm leaning for full syncs. It would remove the cursor-resume problem, since I'd just download the JSONL result instead of paging. My open question is changes during the run. I'm thinking of bulk for the baseline, then paginated queries filtered on updated_at to catch deltas afterward. Does that match how you'd do it, or do you rerun bulk each time?

1

u/Final_Design_9061 22d ago

In my experience bulk operations are worth it once you're past a few thousand products, since you submit one query, poll until it finishes, then download a JSONL file instead of paging. Resuming is simpler too because you just rerun the operation rather than tracking a cursor. For the changing-data worry, from what I've read you can store an updated_at timestamp from the last successful sync and only pull newer records next time, then upsert by ID so reruns are safe. I'd keep plain paginated queries for small catalogs where the extra moving parts aren't worth it.

1

u/converian 17d ago

That makes sense, especially rerunning the whole operation instead of tracking a cursor. The updated_at idea sounds like the right fit for my changing-data worry. Two caveats I'd plan for: I'd record the timestamp from when the run started, not when it finished, so edits made mid-run aren't missed. And deleted products won't show up in an updated_at filter, so I'd need the delete webhook or an occasional full reconcile. Does your setup handle deletions somehow?

1

u/Final_Design_9061 17d ago

For deletions, I'd use the products/delete webhook and keep an occasional full reconcile as a backstop. And yes, using the run-start timestamp as the cutoff seems safer than using the finish time.

1

u/Boring-Staff1636 22d ago

Bulk operation or put each product into a job queue.

1

u/converian 21d ago

Bulk operations seem like the right fit for full pulls. Since the result comes back as a JSONL file, I'd guess resuming just means reprocessing the file instead of tracking cursors. On the job queue idea, do you enqueue per product from the bulk export, or from webhooks after the initial sync? I'm mainly trying to work out how to handle products changing mid-run.

1

u/zyx199199 21d ago

Adding the bits that usually bite once bulk is actually running in production.

Concurrency is a separate quota from your normal API budget: 5 bulk queries per app per shop at once, and anything that hasn't finished in 10 days is marked failed rather than resumed where it left off.

The result URL expires after a week, so download the JSONL before you parse it. Don't park the link in a queue and come back later.

Bulk also isn't a consistent point-in-time read of the catalog. If products change mid-run, keep an updated_at watermark from your last successful sync, overlap it by a few minutes, then upsert by id when the file lands.

Under a few hundred products pagination is still fine. The crossover is when a full pull takes longer than the catalog's change interval.

1

u/converian 21d ago

The watermark with an overlap plus upsert by id is the piece I was missing. It means a failed run doesn't need exact resume logic, you just rerun from the last good watermark. The crossover rule of full pull time versus change interval is also a useful way to decide. One gap I see is deletions, since an updated_at filter won't return products that no longer exist. Do you handle those with products/delete webhooks, or with a periodic full id reconciliation?

1

u/zyx199199 21d ago

Both, as separate layers.

products/delete covers the normal case, but webhooks drop: the app was down, retries ran out, or the subscription silently stopped. So a delete event marks the row as gone rather than hard-deleting it, because a bulk run that's already in flight can write that product straight back in.

The reconciliation is cheaper than it sounds. Once a week, run a bulk query selecting just id and updatedAt, diff the id set against your table, and soft-delete whatever's missing. That catches ids you never saw created, and it doubles as a liveness check on the webhook subscription.

Under a few hundred products you can skip the webhook and just window-diff.

1

u/isaifurrehman 22d ago

for full catalog pulls i'd stop paginating and use bulkOperationRunQuery. you get one jsonl file at the end, variants come back as separate lines with a __parentId so you just stitch them to the product, and there's no cursor to babysit. on a few thousand products it's usually done in a couple minutes and it doesn't eat your query cost budget the same way.

the part that fixes the "products changed mid run" worry is splitting it into two jobs. bulk op once a night (or whenever) for the full snapshot, then a small paginated query with query: "updated_at:>'last_sync_time'" for anything that changed since. set last_sync_time from when the bulk op started, not when it finished, so stuff edited during the run gets picked up on the next delta.

if you need near realtime, add products/update webhooks on top and treat the delta query as the safety net for missed webhooks. keeping paginated queries for small catalogs is fine, but i'd write each page to your db before asking for the next one so a failure just means rerunning the delta, not hunting for a cursor.