Skip to content
MS Keys Gate
Concept / DemoAPI integration

Payments & CRM — API integration

Shows webhook handling, retries and idempotency, and safe secret management.

A concept by MS Keys Gate, built to demonstrate capability. It is not a client project and was never commissioned.

Screens

sync-service.example

Event log. Incoming webhooks with status, attempts and payload.

What it sets out to prove

  • Process each webhook exactly once, even when the sender retries
  • Recover from a downstream outage without losing events
  • Keep every credential out of the codebase and the logs

Built with

  • TypeScript
  • Webhooks
  • Queue + retries
  • Secret manager

Idempotency by design

Every incoming event is keyed on its provider id; a duplicate is acknowledged and dropped before any work starts.

Fail slow, not loud

A failed sync goes back on the queue with exponential backoff and a dead-letter after N attempts, not a 500 to the provider.

A look at the code

The idempotent webhook entry point

export async function handleWebhook(req: Request): Promise<Response> {
  const event = verifySignature(await req.text(), req.headers);

  // Exactly-once: the provider id is the primary key.
  const created = await events.insertIfAbsent({
    id: event.id,
    type: event.type,
    receivedAt: Date.now(),
  });

  if (!created) return Response.json({ status: "duplicate" });

  await queue.enqueue("sync-order", { eventId: event.id });
  return Response.json({ status: "accepted" }, { status: 202 });
}

Illustrative snippet from the concept (typescript).

Take this further

The thinking here carries straight into a real project. See the Plugin development service, or tell us what you have in mind.