Syncing Shopify inventory to a static storefront without hammering the API
A static storefront is fast and cheap, but stock changes. Calling a commerce API from every product page load is the wrong answer: it adds latency, burns quota and couples your page speed to someone else’s uptime.
The pattern
Separate the write path from the read path. A scheduled job pulls the source of truth and writes a snapshot to a fast edge store. The storefront reads that snapshot through a same-origin endpoint, with a short cache.
Why it works
- Reads are constant and cheap; the source is called once per interval, not once per visitor.
- The storefront never exposes the source credentials or its URL.
- If the source is down, the last snapshot keeps serving.
- The failure mode is explicit: stale data for one interval, not broken pages.
What to get right
Decide the interval from business reality, not from fear of quota. A five-hour sync means five hours of possible staleness; a fifteen-minute sync is usually still negligible against API limits.
Keep the snapshot shape stable and version it. If the snapshot is malformed, fail the sync and keep the previous one rather than writing partial data.
The trade-off you accept
You are choosing eventual consistency. Document it, show stock conservatively, and make manual correction easy. For most catalogues that is a better trade than coupling every page view to a live API.