GSM Hosting All articles
SMS Infrastructure

Token Buckets and Trust: How to Throttle Outbound SMS So Carriers Stop Noticing You

GSM Hosting
Token Buckets and Trust: How to Throttle Outbound SMS So Carriers Stop Noticing You

Photo: Federal Bureau of Investigation, Public domain, via Wikimedia Commons

No carrier trust team has ever woken up angry that a rack sent 40,000 messages yesterday. They get angry when a rack sends 200 a day for three weeks and then 9,000 between 9:40 and 10:25 on a Tuesday, because that curve is indistinguishable from pumping. Throttling isn't a penalty you get put into. It's the shape of your traffic, and you decide the shape — or a compliance analyst decides it for you.

Most farms skip this. They hard-code a single global sleep between sends, drop it to 25 ms when a campaign runs late, then act shocked when the account lands in manual review. A single sleep is not a throttle. It's a concurrency bug with a stopwatch attached.

Here's the three-layer version that has survived contact with real US carriers.

Layer one: per-SIM pacing

Every SIM gets its own token bucket with a refill rate and a small burst capacity. The mental model to keep is simple: what does a legit human handset look like? It sends a few messages a minute, not five a second. If one SIM in your rack is sustaining a rate no phone would ever sustain, you're writing a story about yourself in your own CDR.

A workable starting point:

That gives a soft ceiling near 15 messages a minute with room to absorb a retry without starving. The jitter matters more than people think. Two hundred SIMs sharing a clock boundary will all fire on the same second and hand your carrier a beautiful 200-message spike every minute. Spread it.

Also, do not trust your modem's queue depth. AT+CMGS flow control on cheap boards lies under load, and half the time the modem accepts a command it has no intention of sending promptly. Pace at the sender, not at the serial port.

Layer two: per-campaign pacing

Campaigns need their own bucket, above the SIM layer. If you're on 10DLC, you have a throughput allocation attached to the campaign — treat your internal ceiling as 80% of whatever you were granted, and treat that 20% as insurance you'll be glad you bought.

The enforcement detail that trips everyone up: a single scheduler must own the outbound queue. If each worker sleeps independently, your effective rate is worker count times your sleep interval, and it scales silently as you add workers. Put the queue in Postgres or Redis, let one dispatcher claim tokens, and let workers ask permission.

Layer three: a rack-wide gate

A global ceiling exists for exactly one reason: to save you from two campaigns that were individually polite and collectively alarming. This gate should be dumb and absolute. When it trips, it should require a human acknowledgement before the queue resumes. Not a Slack message someone can ignore at 2 A.M. — an actual block.

Keep it in the same config file as the other two layers so nobody has to hunt through three repos during an incident.

Burst detection that means something

Throttles cap the shape. Burst detection notices when the shape is wrong anyway — a retry storm, a misbehaving worker, a campaign that got double-queued after a deploy.

Two signals worth alerting on:

Neither of these needs machine learning. A moving percentile and a counter will do it.

The logs that read like a character reference

When a carrier asks what happened, you have one shot to sound like an operator instead of an amateur. That means the throttle decision has to be in the log, not inferred from it later.

Log one row per send attempt with at least: timestamp (UTC, monotonic source), sim_id, campaign_id, message_id, destination country, sending carrier, throttle decision, wait_ms, and the final submit result. Retain 90 days minimum; keep 13 months if your carrier agreement is vague about audit windows. You will not want to reconstruct this from modem syslog at 11 P.M. on a Friday.

A config block you can crib:

throttle:
  per_sim:
    refill_ms: 4000
    burst: 5
    jitter_pct: 15
  per_campaign:
    refill_ms: 900
    burst: 20
    carrier_ceiling_pct: 80
  global:
    max_per_minute: 600
    require_ack_on_trip: true
  burst_detection:
    window_s: 60
    baseline: p95_7d
    trip_multiplier: 3.0
    sustained_minutes: 2
    action: throttle_50_and_alert

What this actually buys you

Fewer 4xx responses, which means fewer retries, which means less test traffic burning through your SIM margin. Fewer manual reviews. And when a carrier does ask, a one-page export that shows steady state, deliberate caps, and every decision logged with a reason.

That's the whole pitch. Predictability is a product feature. Ship it before someone asks you to.

All Articles

Related Articles

The Plastic Is Cheap: Your Carrier Relationship Is the Asset You Actually Own

The Plastic Is Cheap: Your Carrier Relationship Is the Asset You Actually Own

Rotate or Regret: Giving SIM Cards a Working Retirement Date

Rotate or Regret: Giving SIM Cards a Working Retirement Date

The Reply That Never Came Back: Auditing Inbound SMS on a NAT-Trapped DIY Gateway

The Reply That Never Came Back: Auditing Inbound SMS on a NAT-Trapped DIY Gateway