Capability - Bulk messaging engine

One image upload per campaign, not 8,800

How a templated WhatsApp carousel reaches tens of thousands of recipients: audience resolved from the warehouse, media uploaded once and cached, then sent in parallel fan-out groups - roughly a 10x throughput gain over the original loop.

Send pipeline

1 - resolve

Audience

Filters + selection -> recipient list, resolved from the analytics store. Users with no phone are excluded.

->
2 - cache

Media upload

Each card image converted to JPEG and uploaded once; media_id cached 6h with in-flight coalescing.

->
3 - cache

Template meta

One GET /message_templates per campaign instead of one per recipient.

4 - fan out

Parallel send

Batches sent in groups of WA_SEND_CONCURRENCY (10) with a 100 ms pause between groups.

->
5 - track

Live progress

In-memory status map drives the banner; warehouse rows feed the historical report.

->
6 - scale

Schedule

Cloud Tasks persists future sends; recipients re-resolved at fire time.

What changed - the carousel case (4 cards x 2,200 recipients)

4
image uploads / campaign 8,800
~355
messages / min 33
~15s
warm 100-user batch 2.5-7 min
10.6x
end-to-end speedup

The dominant cost was redundant uploads: the same four images were re-uploaded for every recipient. Caching the media_id removed ~95% of the runtime; parallel fan-out removed most of the rest.

Tuning knobs & safety limits

ControlDefaultPurpose
WA_SEND_CONCURRENCY10Parallel sends per fan-out group
WA_INTER_FAN_OUT_MS100Pause between groups (headroom under Meta's limit)
Media cache TTL6hSpans a full campaign run
Max download / image8 MBGuards against OOM from a mis-pasted URL
Scheduled explicit ids1,500Cloud Tasks 100 KB body cap; larger audiences use a filter spec

Theoretical ceiling at the defaults is 100 msg/sec - comfortably under Meta's 250 msg/sec Cloud API limit; sustained rate (~5.9/sec) is bounded by Meta's per-message latency, not the client.

Relay - anonymized engineering case study. Diagram describes architecture only; no production data shown.