Self-healing help-desk sync that catches dropped webhooks

Client system Published Jun 30, 2026 Reviewed Nov 21, 2026

A Go ingestion service that mirrors Zendesk tickets into Postgres via a durable database queue, then continuously reconciles against Zendesk so silently dropped webhooks are found and repaired automatically.

At a glance

Problem
A consumer subscription business ran its AI support agent and dashboards off a Postgres mirror fed by Zendesk webhooks. When Zendesk silently skipped a webhook, tickets vanished without triggering any error.
Constraint
Webhooks arrive out of order, in bursts, as duplicates or not at all, and the mirror had to stay accurate across deploys, crashes and API rate limits without manual babysitting.
System built
A Go service using the raw webhook table as a Postgres queue, monotonic ticket upserts, a three-schedule reconciler with 404 tombstones, and 46 in-process anomaly checks alerting Slack.
Outcome
Silently dropped webhooks turn into detected gaps refilled within hours, and in-flight retries survive every deploy because queue state lives in Postgres.

Overview

A consumer subscription business runs customer support in Zendesk across multiple brands and thousands of daily tickets. Its AI support agent, internal dashboards and routing logic all query a Postgres mirror of those tickets. That mirror originally relied on Zendesk webhooks routed through n8n until I built a dedicated Go service to replace it.

Webhooks are an unreliable delivery contract. Zendesk repeats them, fires bursts within seconds, delivers updates out of order and occasionally drops them altogether. A skipped webhook leaves zero footprint on the receiver, letting the mirror drift silently while every error metric stays green.

The service was built to be self-checking by default, finding and repairing missing tickets without human intervention.

The events table is the queue

Every incoming webhook passes two authentication checks before hitting disk: a constant-time API key check followed by HMAC-SHA256 verification of the Zendesk signature timestamp and raw payload, rejecting timestamps skewed by more than 5 minutes. Valid requests insert the raw payload into an events table and return HTTP 202 immediately.

The earliest prototype dispatched webhooks through an in-memory channel with in-process retry timers. Any restart or deploy wiped both. A staged redesign turned the events table itself into the durable queue, storing retry timing in a next_attempt_at column.

UPDATE events e
SET status = 'processing', started_at = now(), attempts = e.attempts + 1
WHERE e.id IN (
  SELECT id FROM events
  WHERE (status = 'queued' AND (next_attempt_at IS NULL OR next_attempt_at <= now()))
     OR (status = 'processing' AND started_at < now() - interval '5 minutes')
  ORDER BY received_at
  LIMIT $1
  FOR UPDATE SKIP LOCKED
)
RETURNING e.id, e.ticket_id, e.attempts, e.raw_payload;

Claiming work: the second condition is the whole crash-recovery mechanism

Any row left in processing past its 5-minute lease becomes claimable again automatically, removing the need for a separate crash-recovery daemon. Transient failures back off from 2 seconds, doubling with up to 20% jitter up to a 5-minute cap across 5 attempts. Validation and permission errors fail immediately instead of burning retries, and failed rows remain replayable via an admin endpoint.

Coalescing, and the deadlock it hid

A single ticket edit frequently emits a rapid burst of webhooks. The worker claims the oldest ready row as a lead, waits 10 seconds from that ticket's first arrival, and folds all other ready rows for the same ticket into one batch while skipping tickets already active in the same process.

Workers never trust webhook bodies as authoritative state. Each batch fetches the live ticket and its comments from Zendesk and upserts them by Zendesk's primary IDs. Ticket updates apply only when incoming updated_at is at least as recent as the stored row, blocking late deliveries from rewinding state. The raw webhook contributes only two facts the API lacks: whether a customer posted a public comment and whether the status changed.

A 20-way concurrent-claimer stress test exposed a deadlock roughly once every 20 runs. During rolling deploys, two instances could grab different lead rows for the same ticket and then deadlock while locking each other's sibling rows. Adding a second FOR UPDATE SKIP LOCKED pass when folding siblings resolved it cleanly by skipping rows claimed elsewhere instead of waiting.

Webhooks that never arrived

The defining production incident was a set of real Zendesk tickets with zero corresponding rows in events: Zendesk had silently skipped their creation webhooks. A fallback sync existed, but it triggered only after complete webhook silence; on a busy help desk receiving events every few seconds, it never fired.

Four changes shipped together: a mandatory hourly incremental sweep, a missing-ID gap detector, a paging alert on gaps, and a CLI backfill tool accepting a file of ticket IDs. The silence-triggered sync was deleted because a full webhook outage already had its own alert.

All three recovery paths then unified into one reconciler ticking every 5 minutes across independent schedules:

  • Hourly incremental sweeps of Zendesk's tickets API from a persisted cursor.
  • Every 6 hours, a generate_series anti-join across the past 48 hours of ticket IDs to surface tickets Zendesk never announced.
  • Every 4 hours, a staleness recheck of open, new and pending tickets unchanged locally for 72 hours.

All three feed the same bounded refresh pipeline, deduplicating work within each tick so no ticket refreshes twice.

Tombstones for IDs that were never ours

The ID anti-join initially assumed contiguous ticket IDs per account. In reality, Zendesk allocates IDs across a shared multi-tenant cluster, meaning 1–2% of integers in any range belong to other customers and return 404 permanently. Combined with deleted tickets, the missing-ID gauge pinned itself at the 100-ID batch limit, alerts stayed permanently open, and the detector wasted ~200 API calls every 6 hours.

Now any code path seeing a 404 writes a tombstone row recording first and last sighting, sighting count and source path. The anti-join ignores tombstoned IDs. Tombstones are permanent (a restored ticket requires clearing its row or running a backfill), and a separate alert watches for abnormal spikes in daily tombstones.

46 checks that alert people

Forty-six anomaly checks run in-process across two tiers. Fast checks run every tick against Prometheus counter deltas and lightweight probes: webhook silence, lag, Zendesk rate limits, retry storms, expired leases and queue backlog. Integrity checks run hourly over recent rows, plus full sweeps at startup and every 24 hours, hunting orphaned comments, inverted or future timestamps, malformed arrays and projection drift.

Every check routes as page, digest or log. Pages and digests post to Slack; operators acknowledge active alerts, while resolved anomalies auto-acknowledge. Checks report problems without attempting repairs; repair stays strictly inside the reconciler on its regular cadence. Two of the original 21 checks were later removed after discovering they queried columns that never existed in production.

The Zendesk HTTP client retries 429 and 5xx responses up to 4 times, honoring Retry-After headers whenever sent, while backfills cap at 4 concurrent fetchers to stay inside account rate limits.

Limitations

  • Gap detection is periodic: a silently dropped webhook can stay absent for up to 6 hours, or need a manual backfill if missed past the 48-hour lookback.
  • The reconciler holds no cross-process lock; overlapping deploys can run two sweeps concurrently, staying safe solely because every upsert is idempotent.
  • Monotonic timestamp guards protect individual ticket rows, not ordering across tickets or derived tables.
  • Alert thresholds are hand-tuned, and two checks shipped broken, proving monitoring queries need code review like application logic.
  • A validly signed webhook containing bad upstream data is mirrored verbatim; ingestion validates authenticity, not Zendesk business semantics.
  • In hindsight, the ID gap detector belonged in version one; a silence-based fallback created false confidence without catching partial drops.

Related case studies

Bring one real problem

One hour, €80. You leave with a written plan for what belongs in AI, what belongs in code, and what a first release takes, whether we work together or not.