协作头脑风暴
brainstorming
在实现前澄清需求、探索设计选择,并形成清晰的开发方向。
shopify-reliability-patterns【开发与工程】Implement reliability patterns for Shopify apps including circuit breakers for API outages, webhook retry handling, and graceful degradation. Use when building fault-tolerant Shopify integrations, handling webhook retry storms, or adding resilience to API calls. Trigger with phrases like "shopify reliability", "shopify circuit breaker", "shopify resi…
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
name: shopify-reliability-patterns description: 'Implement reliability patterns for Shopify apps including circuit breakers
for API outages, webhook retry handling, and graceful degradation.
Use when building fault-tolerant Shopify integrations, handling webhook retry storms,
or adding resilience to API calls.
Trigger with phrases like "shopify reliability", "shopify circuit breaker",
"shopify resilience", "shopify fallback", "shopify retry webhook".
' allowed-tools: Read, Write, Edit version: 2.7.0 license: MIT author: Jeremy Longshore jeremy@intentsolutions.io tags:
Build fault-tolerant Shopify integrations that handle API outages, webhook retry storms, and rate limit exhaustion gracefully.
Wrap all Shopify API calls in a circuit breaker (using opossum) that opens at 50% error rate, only counting 5xx and timeout errors. When open, serve cached data. The breaker auto-tests recovery after 30 seconds in half-open state.
See Circuit Breaker for the complete implementation.
Shopify retries webhooks up to 19 times over 48 hours if your endpoint doesn't return 200. Your handler must be idempotent. Use Redis to track X-Shopify-Webhook-Id with a 7-day TTL. Always respond 200 within 5 seconds, then process asynchronously.
See Webhook Idempotency for the complete implementation.
Implement a three-tier fallback: try the live API first (caching the result), fall back to cached data, then fall back to an alternative data source (e.g., local DB). Track the data source so you can log degraded responses.
See Cached Fallback for the complete implementation.
Don't process webhooks inline — queue them with BullMQ for resilience. Verify HMAC first, respond 200 immediately, then enqueue with topic/shop/payload metadata. The worker processes jobs with exponential backoff (5 retries) and idempotency checks.
See Webhook Processing Queue for the complete implementation.
Retry logic that respects Shopify's Retry-After header (REST 429) and GraphQL throttle status restore rate. Calculates optimal wait time from available points rather than blindly backing off.
See Rate Limit-Aware Retry for the complete implementation.
| Issue | Cause | Solution |
|---|---|---|
| Circuit stays open | Shopify extended outage | Serve cached data, monitor status page |
| Duplicate orders processed | Missing idempotency | Use X-Shopify-Webhook-Id for dedup |
| Queue growing unbounded | Worker down | Monitor queue depth, alert on backlog |
| Stale cache served for hours | Circuit never recovers | Set max cache staleness, force refresh |
app.get("/health", async (req, res) => {
res.json({
status: shopifyCircuit.opened ? "degraded" : "healthy",
shopify: {
circuit: shopifyCircuit.opened ? "open" : "closed",
stats: shopifyCircuit.stats,
},
webhookQueue: {
waiting: await webhookQueue.getWaitingCount(),
active: await webhookQueue.getActiveCount(),
failed: await webhookQueue.getFailedCount(),
},
});
});