Developer DocsBackground jobs

Background jobs

Event-driven and scheduled work runs in a dedicated worker container (apps/worker) on BullMQ over self-hosted Redis — no external queue service (chosen for $0 cost + data residency).

What the worker does

AreaProcessor(s)Responsibilities
Derivationderive, session-derive, scoringTurn player_events into player-profile stats (deposits, GGR/NGR, wagered, counts, last-activity) and player scores (churn/value/engagement).
LifecyclelifecycleRecompute each player’s stage (+ VIP tiering) and log transitions.
Segmentssegments, segments-realtimeRecompute dynamic-segment membership; a fast real-time reconciler for opted-in segments.
Notificationsemail, telegram, push, inapp, channel-fallbackDrain the notification queue per channel and deliver (email/SMTP, Telegram/Bot API, web-push/VAPID, in-app inbox over Realtime), with channel fallback.
Campaignscampaigns, ab-winnerDispatch scheduled/recurring campaigns; auto-select the winning A/B variant.
Journeysjourneys, journey-enroll, journey-enroll-scheduledEnrol players and advance journey runs through the graph.
WebhookswebhooksDrain the webhook queue: sign, POST, log the attempt, retry with backoff.
Reports/exportsreports, segment-exportsScheduled KPI digests (with PDF charts) and scheduled segment CSV exports.
Alertsalerts, alert-rulesEvaluate operator alert rules and custom metric rules, and notify.
Intelligencefraud, train-modelsFraud scoring and ML model training (feeding forecasts / next-best-action / scores).
Taskstask-remindersSend reminders for due CRM tasks.

Delivery semantics

  • Idempotent / claim-based. Jobs claim rows atomically (e.g. a queued → sending CAS) so two workers don’t double-process.
  • Backoff on failure. Outbound webhooks retry ~1m → 5m → 15m → 1h up to 5 attempts; other queues use BullMQ’s retry/backoff.
  • Service role. The worker uses the Supabase service-role client and is not constrained by RLS — it operates platform-wide by design.

Append-only inputs

The worker reads append-only streams (player_events, balance_transactions) and writes derived state elsewhere. It never mutates the streams, so derivation can always be recomputed from scratch.

Configuration

Queues connect to Redis via REDIS_URL. Channel delivery needs its provider credentials (SMTP, TELEGRAM_BOT_TOKEN, VAPID keys). Webhook tuning is via WEBHOOK_BATCH, WEBHOOK_MAX_ATTEMPTS, WEBHOOK_TIMEOUT_MS.