Broadcast architecture on WhatsApp within the rules

How to build bulk notification sending that respects opt-in, templates, pacing and limits: data model, send pipeline, failure handling and stop conditions.

A broadcast feature looks simple: take a list, send a template to everyone. On WhatsApp the hard part is not the loop, it is everything the loop must respect. Recipients need to have opted in, outside the 24-hour window only approved templates may be sent, Meta limits how many distinct people can be reached per day, and low-quality sends can pause a template mid-campaign. This article describes an architecture that treats those rules as first-class constraints of the system rather than afterthoughts.

Which rules does a broadcast system have to encode?

Four rules must be enforced by the system itself: consent per recipient and category, template-only messaging outside the service window, the portfolio's unique-user limit, and honouring opt-outs. If they live only in operator training, the first rushed campaign breaks them.

The WhatsApp Business Messaging Policy requires that a person gave their number and agreed to receive messages, that consent is the business's responsibility, and that users can opt out and the business must honour that, inside or outside WhatsApp. It also recommends separate consent per message category. Outside the 24-hour customer service window, businesses can message only with approved templates. Meta additionally documents an opt-out signal on its side: error 131050 means the recipient has opted out of marketing messages from your business and retrying will not help, and a user_preferences webhook exists to track opt-outs and opt-ins.

None of this is legal advice, and consent rules differ by country; the point for engineers is that consent must be data, not folklore.

What does the data model look like?

Model consent, campaign and delivery as separate tables, with consent checked at send time rather than at list-build time. A list built on Monday can be stale by Thursday.

CREATE TABLE consent ( tenant_id uuid NOT NULL, contact_id uuid NOT NULL, category text NOT NULL, -- 'marketing' | 'utility' | 'authentication' status text NOT NULL, -- 'opted_in' | 'opted_out' source text NOT NULL, -- where and how consent was captured changed_at timestamptz NOT NULL, PRIMARY KEY (tenant_id, contact_id, category) ); CREATE TABLE campaign ( id uuid PRIMARY KEY, tenant_id uuid NOT NULL, channel_id text NOT NULL, template text NOT NULL, category text NOT NULL, state text NOT NULL, -- draft | running | paused | done | aborted max_per_day integer NOT NULL -- planned reach, below the portfolio limit ); CREATE TABLE campaign_delivery ( campaign_id uuid NOT NULL, contact_id uuid NOT NULL, state text NOT NULL, -- queued | accepted | sent | delivered | read | failed | skipped provider_msg text, -- wamid or provider message id error_code integer, PRIMARY KEY (campaign_id, contact_id) );

The primary key on campaign_delivery is doing real work: a contact appears at most once per campaign, so a retry of the job cannot double-send. Record why a recipient was skipped (opted out, no consent for that category, invalid number) so the customer can see a complete account of the audience, not just a shorter list.

What does the send pipeline do for each recipient?

For each recipient the pipeline re-checks consent, claims the row, sends with an idempotency key, then waits for status webhooks to move the row forward. Claiming before sending is what makes the pipeline restart-safe.

async function processDelivery(campaign, row) { const consent = await consentFor(campaign.tenantId, row.contactId, campaign.category) if (consent !== 'opted_in') return mark(row, 'skipped', { reason: 'no_consent' }) // claim: only one worker flips queued -> accepted for this row const claimed = await db.claim(row, 'queued', 'accepted') if (!claimed) return const r = await api.send(campaign.channelId, templatePayload(campaign, row), { idempotencyKey: `${campaign.id}:${row.contactId}`, }) if (r.ok) return saveProviderId(row, r.messageId) // 202 means accepted, not delivered return handleError(campaign, row, r.error) // see below }

The idempotency key is deterministic from the campaign and the contact, so even a crash between the API call and the database write cannot produce a second message. Status progress then arrives through webhooks; the webhooks reference describes the delivery and retry rules, and the send endpoint answers 202 because the message was queued for Meta, not delivered.

How should the campaign be paced and limited?

Pace to the lowest of Meta throughput, the portfolio's unique-user limit and the provider's rate limit, and cap each campaign below the daily allowance so one campaign cannot consume everything. Template pacing on Meta's side adds a fourth constraint that your system has to understand.

Meta documents template pacing for marketing templates and, in specific cases, utility templates: newly created, unpaused or not-GREEN templates may be paced, meaning that after an unspecified threshold new messages are held while customer feedback comes in. Positive feedback releases the held messages; negative feedback sets the template to PAUSED and the held messages fail with code 132015. The send response then carries a message_status of held_for_quality_assessment instead of accepted. Your pipeline should treat held as a normal intermediate state with its own timeout, not as success and not as failure.

SignalMeaningPipeline reaction
message_status acceptedProcessed; will be sentWait for sent and delivered webhooks
message_status held_for_quality_assessmentHeld while feedback arrivesKeep the row in a held state; do not retry
Error 132015Template paused for low qualityPause the campaign and alert; do not keep sending
Error 131050Recipient opted out of marketingMark as opted out, never retry
Error 131049Withheld to protect engagement, often a per-user marketing limitDo not resend for at least 24 hours
Error 131056Too many messages to the same recipient too quicklyRetry that recipient later; continue with others

When should a campaign stop itself?

A campaign should pause itself automatically on defined signals: a paused template, a spike in failures, a spike in opt-out errors or a throughput error that does not clear. Stopping a bad send in the first minutes is worth far more than reporting on it afterwards.

  • Template paused (error 132015): pause immediately; the remaining audience cannot be sent anyway.
  • Failure rate above a threshold you set over a rolling window: pause and notify the owner.
  • Opt-out errors above a threshold: stop, because the list quality is the problem.
  • Account-level restriction errors (for example 368 or 131031): abort the campaign and escalate, since continued sending can worsen the situation.
  • Manual stop: a visible, instant button that moves the campaign to paused and releases workers.

Define these thresholds per tenant, because a small list and a large one have different baselines. Avoid inventing universal numbers; start from the customer's own history and tighten with experience.

What happens after the send?

After the send, reconcile statuses, record outcomes per recipient and feed opt-outs back into the consent table. A broadcast that never updates consent teaches the next broadcast the same mistakes.

  • Process status webhooks idempotently and tolerate out-of-order statuses.
  • Listen for user preference changes and update the consent table the same day.
  • Store the per-message pricing information from status webhooks so cost can be attributed to the campaign; see the cost-attribution article in this series and the pricing page for rates.
  • Produce a customer-facing report with sent, delivered, read, failed and skipped counts, and the reasons.

Frequently asked questions

Can I send a template to anyone in my database?

Only to people who gave their number and agreed to receive messages from your business, and who have not opted out. The policy makes consent the business's responsibility, so store its source and category.

What happens when a template gets paused mid-campaign?

Held messages are dropped and fail with code 132015, and the template cannot be sent until it is edited and approved. A broadcast system should pause the campaign as soon as it sees that code.

Should consent be checked when the list is built or when sending?

At send time. Consent can change between building the list and the moment the message goes out, and an opt-out should take effect immediately.

Fontes

Documentação oficial da Meta, conferida em 31 de outubro de 2026.