Skip to content

About

Real-time campaign pacing with hour-of-week median/MAD baselines and a damped, rate-limited controller that avoids false alarms on normal seasonal peaks.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

11 Commits

Folders and files

Repository files navigation

pacingloop

Campaign pacing with robust seasonal baselines and a damped controller, so it does not alert on a normal Saturday.

CI and Pages Live demo

Pacing Loop desktop demo

Why

A misconfigured bid or a broken creative can burn a week of budget in a few hours overnight. The mirror failure is quieter: a campaign that under-paces all month leaves budget unspent, which is the same size of loss. Alerting on raw spend does not help, because delivery is strongly seasonal. A mean + 3 sigma threshold fires every Saturday evening, gets muted, and then misses the real incident. A naive proportional pacing controller is worse: on a noisy hourly signal it oscillates and hurts delivery.

pacingloop uses a robust per-hour-of-week baseline for detection and a damped, rate-limited controller for pacing, with a spend ceiling enforced outside the controller.

Features

  • Hour-of-week baselines (median + MAD) per signal: spend, clicks, installs.
  • Multi-signal classification into BID_RUNAWAY, CREATIVE_BREAK, TRACKING_OUTAGE, FRAUD_SPIKE or UNKNOWN, with a human-readable explanation. A tracking outage (installs collapse, spend and clicks normal) is told apart from a real performance drop.
  • Buckets with too little history report insufficientData instead of being assumed healthy.
  • Damped pacing controller with a deadband, per-step rate limit and multiplier bounds; every adjustment is logged with its reason.
  • Hard spend ceiling applied independently of the controller.
  • Seeded simulator with weekly seasonality and incidents planted at known hours, so detection latency and false-alarm rate are measurable.
  • Browser demo (site/) that computes a bounded pacing adjustment from target spend, actual spend, seasonal index, gain, damping and a maximum adjustment.

Architecture

flowchart LR
  SIM["sim.ts<br/>seasonal stream + planted incidents"] --> DET["detect.ts<br/>multi-signal classifier"]
  BASE["baseline.ts<br/>hour-of-week median + MAD"] --> DET
  DET --> ALERT["alerts with explanations"]
  SIM --> CTRL["control.ts<br/>damped controller"]
  CTRL --> CEIL["hard spend ceiling"]
  CEIL --> OUT["spend, multiplier trace, audit log"]
Loading

The simulator produces hourly spend, clicks and installs. baseline.ts builds a 168-bucket baseline from the training weeks; detect.ts scores each new hour against it and classifies the pattern. control.ts turns a pace error into a bounded multiplier change, and applyCeiling caps spend regardless of what the controller asked for. More detail is in docs/ARCHITECTURE.md.

Quick start

Requires Node 22.6+ (CI uses Node 24). There are no dependencies and no build step. On Node 22 TypeScript needs a flag; Node 24 runs .ts files natively.

git clone https://github.com/Nimisharani/pacingloop.git
cd pacingloop

# Node 24+
npm test
npm run demo

# Node 22.6 - 23
node --experimental-strip-types --test tests/pacing.test.ts site/core.test.mjs
node --experimental-strip-types src/demo.ts

To open the browser demo locally, serve site/ with any static server, for example python3 -m http.server -d site 8000.

Example

npm run demo simulates 16 weeks (12 for the baseline, 4 with planted incidents) and prints:

  DETECTION
  incident            planted at    detected after   classified as
  BID_RUNAWAY         h2204         0h               BID_RUNAWAY
  CREATIVE_BREAK      h2392         0h               CREATIVE_BREAK
  TRACKING_OUTAGE     h2472         0h               TRACKING_OUTAGE
  FRAUD_SPIKE         h2550         0h               FRAUD_SPIKE

    4/4 detected, 0.00 false alarms per week.
    On a stream with NO incidents: 0 detections, 0.00 false alarms per week.

  THE CONTROLLER
  controller            adjustments   direction reversals   final pace error
  damped + deadband     279           33                    0.1%
  proportional (naive)  488           117                   0.0%

  THE HARD CEILING
    Controller with an INVERTED gain - it boosts when overspending:
      cap over the period   35,000
      actually spent        35000
      ceiling engaged       true

Latency is measured in whole hours because the stream is hourly. These numbers come from the seeded simulator, not from production traffic.

How it works

  • Baseline. buildBaseline groups history by hour of week and stores the median and MAD (scaled by 1.4826) for each bucket. Both have a 50% breakdown point, so incidents in the history do not widen the threshold. In the demo, adding three incident hours to the history moves the standard deviation from 770 to 3465 but the MAD only from 965 to 970.
  • Scoring. score converts an observation to deviations from the bucket centre. The spread is floored at 12% of the expected level (and at least 1) because campaign noise is multiplicative; the default threshold is 4 deviations. A bucket needs at least MIN_SAMPLES (6) observations to be judged.
  • Classification. classify compares spend, click and install deviations: spend high is a runaway, clicks high with installs flat is fraud, installs low with spend and clicks normal is a tracking outage, clicks low is a creative break.
  • Controller. step multiplies the bid multiplier by 1 - gain * paceError, ignores errors under the deadband, limits each move to maxStep, and clamps to [minMultiplier, maxMultiplier]. The default config (gain 0.35, max step 8%, deadband 4%) reversed direction 33 times over three simulated weeks, against 117 for the undamped config.
  • Ceiling. applyCeiling is separate from the controller, so a controller bug cannot overspend.

Testing

npm test

tests/pacing.test.ts has 20 tests covering: median/MAD robustness against contamination, per-hour-of-week baselines, insufficient-data handling, detection of every planted incident within the latency budget, a false-alarm rate under one per week (and zero alerts on an incident-free stream), outage-versus-collapse classification, damped versus naive controller stability, deadband, rate limit, multiplier bounds, the adjustment audit log, and the ceiling holding against a broken controller. site/core.test.mjs covers the demo's compute function. CI also validates the site and deploys it to GitHub Pages.

Project layout

src/
  baseline.ts   median/MAD, hour-of-week baseline, scoring
  detect.ts     multi-signal classifier
  control.ts    damped controller, ceiling, stability assessment
  sim.ts        seeded simulator with planted incidents
  demo.ts       the demo script
tests/          unit and behaviour tests
site/           browser demo (static)
docs/           architecture notes and screenshots
scripts/        site validation

Limitations

  • Telemetry is synthetic; there is no ingestion pipeline, queue or database.
  • Latency numbers are in whole hours because observations are hourly.
  • The controller is evaluated in simulation only and does not talk to any ad platform. It is not a bidding engine.
  • The browser demo shows a simplified single-step adjustment, not the full simulation.

License

MIT, see LICENSE.

Maintainer

Maintained by Sai Nimisha Kakarla, Senior Data Analyst, whose work focuses on turning complex, multi-source data into governed KPIs and trusted insights. The project was originally published under the Nimisharani GitHub account.

About

Real-time campaign pacing with hour-of-week median/MAD baselines and a damped, rate-limited controller that avoids false alarms on normal seasonal peaks.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages