Webhook icon
Schedule icon
WorkingDirectory icon
Commands icon
Docker icon
Request icon
Script icon
If icon
Loop icon
Log icon
MailSend icon
SlackIncomingWebhook icon

Hold a Braze Campaign That Would Blow Through the Weekly Frequency Cap

Checks a Braze campaign launch against the weekly per-user frequency cap, then emails the owner and pings Slack when users would be throttled.

Categories
Business

How it works

  1. campaign_launch_approval (io.kestra.plugin.core.trigger.Webhook, keyed with the BRAZE_APPROVAL_WEBHOOK_KEY secret) accepts a POST carrying campaign_id, name and segment. daily_frequency_review (io.kestra.plugin.core.trigger.Schedule, cron 0 6 * * *) is the daily safety net and ships disabled: true until an operator turns it on.
  2. frequency_workspace (io.kestra.plugin.core.flow.WorkingDirectory) opens one shared filesystem so the fixture, the API response and the analysis all see the same files.
  3. write_sends_fixture (io.kestra.plugin.scripts.shell.Commands on the io.kestra.plugin.scripts.runner.docker.Docker runner, image alpine:3.20) writes weekly_sends.json with a heredoc holding three users whose weekly send counts are two, four and five, and entryPoint: [] clears the image entrypoint so the shell runs instead of the default command.
  4. fetch_braze_campaigns (io.kestra.plugin.core.http.Request) GETs https://rest.braze.com/messages/campaigns/list with Authorization: Bearer {{ secret('BRAZE_API_KEY') }}, and options.allowFailed lets a 4xx or 5xx answer through so the review continues on the fixture instead of dying.
  5. analyze_frequency (io.kestra.plugin.scripts.python.Script on python:3.12-slim) prefers the users array from the Braze response and falls back to weekly_sends.json when the body is missing or unparseable. For every user it projects weekly_sends + campaign_sends, compares that against weekly_cap, rolls the per-user results up into segment entries with max_projected and headroom, and prints verdict, capped_users, segments and blocked as a single ::{"outputs": ...}:: line. The webhook segment is always included, and a matching campaign list entry fills in the target segment when the POST did not carry one.
  6. frequency_gate (io.kestra.plugin.core.flow.If) branches on capped_users > 0 and not inputs.dry_run. Above zero, log_segment_headroom (io.kestra.plugin.core.flow.Loop) walks each segment and logs its peak against the cap, notify_owner (io.kestra.plugin.email.MailSend) emails the owner with the counts and the segment JSON, and alert_throttle posts the verdict to Slack. At zero, or on a dry run, log_no_throttle records why nothing was sent.
  7. The flow level errors handler (io.kestra.plugin.slack.notifications.SlackIncomingWebhook) reports any failure with the execution id, because a guard that dies silently looks exactly like a clean launch.

What you get

  • A gate before the send button, users who already hit the weekly cap are counted before the campaign launches instead of after the unsubscribe spike.
  • A verdict you can branch on: verdict, capped_users, segments and blocked are flow outputs for a downstream approval or dashboard.
  • Per-segment headroom in the execution log, so the fix is obvious, split the segment, delay the send, or raise weekly_cap.

Who it's for

  • Lifecycle marketers who own Braze campaigns and need proof that a launch will not burn through the frequency cap.
  • Marketing operations teams that want throttling decisions recorded as execution history rather than argued in chat.
  • Platform owners who need a repeatable rule that runs the same way from a webhook and from a daily review.

Why orchestrate this with Kestra

Braze's frequency capping is configured once and then quietly applies to every send, so nobody sees the cost of a launch until a segment complains. Kestra gives the check a keyed webhook for the launch approval, a disabled daily schedule as the net for campaigns that skip the approval, a live API call that degrades to a fixture instead of failing the review, a Python pass that turns raw send counts into a segment level headroom picture, and a conditional branch that separates a real throttle from a dry run. The same version controlled file carries the thresholds, the notification policy and the execution history that proves the guard ran.

Prerequisites

  • A worker with Docker access, the fixture is written in alpine:3.20 and the analysis runs in python:3.12-slim.
  • A Braze REST API key that can read the campaign list endpoint, plus a stub of that endpoint while you trial the flow.
  • An SMTP relay reachable from the worker for the owner email, and a Slack incoming webhook for the throttle and failure alerts.

Secrets

  • BRAZE_APPROVAL_WEBHOOK_KEY: key segment guarding the launch approval webhook URL, anyone holding it can start a review.
  • BRAZE_API_KEY: bearer token sent to the Braze campaign list endpoint.
  • SMTP_HOST, SMTP_USERNAME, SMTP_PASSWORD, SMTP_FROM: relay settings used by notify_owner.
  • LAUNCH_OWNER_EMAIL: mailbox that receives the throttle email.
  • SLACK_WEBHOOK_URL: Slack incoming webhook URL for the throttle alert and for failure alerts.

Quick start

  1. Add the eight secrets to your Kestra namespace.
  2. Run the flow once with the default inputs and confirm verdict reads THROTTLE_REQUIRED, capped_users reads 2, blocked reads true and segments lists loyal-readers and trial-nurture. The gate takes the else branch because dry_run is still true.
  3. Re-run with dry_run set to false and watch log_segment_headroom, the owner email and the Slack alert fire, then raise weekly_cap to 6 and watch the verdict turn CLEAR_TO_LAUNCH.
  4. Trigger campaign_launch_approval at /api/v1/{tenant}/executions/webhook/{namespace}/braze-frequency-throttle-guard/{BRAZE_APPROVAL_WEBHOOK_KEY} with {"campaign_id": "cmp-spring", "name": "Spring Offer", "segment": "loyal-readers"}, or set disabled: false on daily_frequency_review once the API key and SMTP relay are in place.

How to extend

  • Replace the heredoc fixture with a io.kestra.plugin.core.http.Request that pulls per-user send counts from your CDP, keeping the fixture as the offline fallback.
  • Add a second If inside frequency_gate that auto-splits a segment through the Braze API when capped_users is above a higher threshold.
  • Fan the segment list out to a subflow per segment with io.kestra.plugin.core.flow.ParallelEach when several campaigns share the same audience.

Links

See How

New to Kestra?

Use blueprints to kickstart your first workflows.