डिजिटल वस्तुओं का थोक मंच

Order Delivery Recovery 2026: Polling-Based B2B डिजिटल गुड्स API के लिए patterns

FoxReload webhooks provide नहीं करता। Production-grade order delivery recovery: polling loop, backoff math, DLQ, client-side dedup और SLA alerts।

Order Delivery Recovery 2026: Polling-Based B2B डिजिटल गुड्स API के लिए patterns

FoxReload Public API में webhooks नहीं हैं। कोई X-FoxReload-Signature, कोई HMAC callbacks, कोई order.delivered events नहीं। इसका मतलब है: missed delivery का default pattern अलग है — आपको robust polling infrastructure चाहिए।

यह article उन production patterns को cover करता है जो FoxReload partners reliable order delivery के लिए use करते हैं।

1. Polling Loop — foundation

FoxReload से order delivery GET /api/orders/{order_id} से मिलती है:

curl https://public-api.foxreload.com/api/orders/{order_id} \
  -H "X-API-Key: YOUR_API_KEY"

status === "completed" पर items[].externalData[] में codes।

Jitter के साथ exponential backoff formula:

function nextPollDelay(attempt: number): number {
  const base = 3_000;  // 3s
  const cap = 15_000;  // 15s max
  const exp = Math.min(base * Math.pow(1.5, attempt), cap);
  const jitter = Math.random() * exp * 0.3; // ±30%
  return exp + jitter;
}
// attempt 0: 3–3.9s
// attempt 3: 10–13s
// attempt 5+: 15–19.5s (capped)

2. Dead-letter Queue (DLQ)

Orders जो N attempts के बाद भी complete नहीं हुए, DLQ में जाने चाहिए — lost नहीं होने चाहिए:

// Express + BullMQ
import { Queue, Worker } from 'bullmq';

const pollQueue = new Queue('foxreload-poll', { connection: redis });

// Order create होने के बाद polling job add करें
async function startPolling(orderId: string) {
  await pollQueue.add('poll', { orderId }, {
    attempts: 60,      // max 5 minutes at 5s intervals
    backoff: { type: 'exponential', delay: 3000 },
    removeOnFail: false,  // DLQ inspection के लिए रखें
  });
}

new Worker('foxreload-poll', async (job) => {
  const order = await fetchOrder(job.data.orderId);

  if (order.status === 'completed') {
    const codes = order.items.flatMap((i: any) => i.externalData ?? []);
    await deliverToCustomer(order, codes);
    return;
  }

  if (order.status === 'cancelled' || order.status === 'failed') {
    await notifyFailure(order);
    return;
  }

  // अभी processing — job fail करें ताकि retry हो
  throw new Error(`order ${job.data.orderId} not yet complete: ${order.status}`);
}, { connection: redis });

DLQ events on-call engineer review करता है और manually resolve करता है।

3. Client-Side Dedup

Polling loop से एक order को दो बार deliver करने से बचें:

Storage Latency TTL Cost / 1M events
Redis SETNX <2ms Custom $0.40
Postgres UNIQUE index 5–8ms forever $0.10
async function deliverWithDedup(orderId: string, codes: string[]) {
  // Atomic: mark delivered पहले, फिर deliver
  const marked = await db.orders.tryMarkDelivered(orderId);
  if (!marked) return; // already delivered

  try {
    await sendCodesToCustomer(codes);
  } catch (e) {
    await db.orders.unmarkDelivered(orderId); // rollback
    throw e;
  }
}

4. >1% stuck orders पर alerting

- alert: OrderDeliveryDegraded
  expr: |
    (count(orders{status="completed", age_minutes <= 10})
     / count(orders{created_at > "10 minutes ago"})) < 0.99
  for: 2m
  labels: { severity: page }

Alert PagerDuty/Opsgenie में route होता है। 80% cases में root cause: balance ख़त्म (check BalanceNotEnough errors) या supplier outage।

5. Balance Monitoring

FoxReload balance से orders debit होते हैं। Balance कम हो तो BalanceNotEnough error आती है:

// हर order attempt के बाद check करें
async function checkBalanceHealth() {
  // Balance crypto topup history से estimate करें
  const recentTopups = await getRecentTopups();
  const recentOrders = await getRecentOrders();
  // अगर orders ज़्यादा और topups कम — alert
  if (estimatedBalance < dailySpend * 2) {
    await sendAlert('FoxReload balance critically low — top up via /api/topups/crypto/');
  }
}

CTA

FoxReload API polling-based delivery के लिए optimize है। Robust polling loop, DLQ, और balance monitoring के साथ — 99.9%+ delivery rate achievable है। API access request करें

अक्सर पूछे जाने वाले प्रश्न

FoxReload webhook क्यों नहीं भेजता?
FoxReload Public API में webhooks feature नहीं है। Order delivery जानने का एकमात्र तरीका GET /api/orders/{order_id} polling है। जब status 'completed' हो, items[].externalData[] में codes मिलते हैं।
Order delivery miss होने से कैसे बचें?
Polling loop implement करें जो 5 minutes तक हर 5 seconds poll करे। इसके बाद भी completed नहीं हुआ तो DLQ में डालें और manual review करें। अपने DB में हर order का status track करें।
Polling से duplicate delivery से कैसे बचें?
Order को 'delivered' mark करने के लिए DB transaction use करें — पहले mark, फिर deliver। अगर delivery fail हो तो mark rollback करें। यह at-most-once delivery ensure करता है।
Order delivery health कैसे monitor करें?
Rolling 5-minute में 'completed' orders का percentage track करें। अगर 99% से नीचे गिरे तो alert करें। अपने DB में stuck_since timestamp store करें — 10 minutes से stuck orders immediate alert हैं।
FoxReload API एक्सेस पाएं

संबंधित लेख