Case study // 03

WhatsApp Message Service

Prepaid, queue-backed WhatsApp campaigns with ACID billing and Meta Cloud API delivery — designed for frontend clients, not a demo UI.

Role · Backend / platform engineer

WhatsApp message service architecture cover
~100/sec
Worker limiter
3× backoff
Retries
≤100
Recipients / req
15 / 15m
Auth guard
01

Overview

Direct Meta API calls are slow, rate-limited, and hard to bill. Businesses need reliable bulk send, personalization, wallet accounting, and campaign observability. This service productizes WhatsApp outreach: register → fund wallet → send campaign → track outcomes → refund on permanent failures — without blocking the HTTP request path.

02

Architecture

Layered Express API: routes → auth/validation → controllers → services. Campaign creation atomically writes MongoDB records, deducts tokens, and enqueues BullMQ jobs. Workers deliver via a WhatsApp provider isolation layer and write outcomes back — refunding the wallet when jobs fail.

  • Versioned REST under /api/v1 with uniform success envelopes
  • Provider pattern isolates Meta Graph API
  • Request-ID correlated Winston logging
  • Docker Compose for app + Redis; graceful shutdown
03

Features

JWT register / login / refresh
Bulk text & template messaging
Per-recipient template personalization
Prepaid wallet + ledger
Auto-refund on delivery failure
Campaign tracking & events
Cursor pagination
Swagger OAuth-ready docs
Dockerized app + Redis
Dependency health checks
04

Challenges → Solutions

Concurrent wallet overdrafts

Atomic conditional debit with MongoDB sessions

Slow / flaky Meta sends

BullMQ retries + rate limiter at the worker boundary

Charge without delivery

Failure classification with automatic token refunds

Heavy campaign lists

Cursor pagination + projections for list endpoints

05

Tech stack

Node.jsExpressMongoDBMongooseRedisBullMQJWTJoiWinstonHelmetDockerMeta WhatsApp Cloud APIOpenAPI / Swagger

Positioning

Backend messaging platform designed for frontend clients — not a React/Next UI case study. Prepaid ledger is ready for payment-gateway webhooks; full gateway integration is a roadmap item.

Next