Building an Outbound Voice Dialer That Survives Campaign Bursts
System DesignModel answerLast updated
Design a multi-tenant service that places API-driven phone calls through carriers with hard channel and CPS limits, stays fair under bursts, and tracks call state reliably.
Problem
You are building a platform that lets business customers place outbound phone calls through an HTTPS API. A customer submits a request naming one destination number and a media configuration (for example, which voice agent or audio to use). The platform dials the number through a telecom carrier, waits for the person to pick up, and then connects the call to the chosen media endpoint.
Design the platform end to end. Treat this as an open-ended discussion: ask clarifying questions, present a high-level design, then go deep on the hardest part, which is scale.
Assumptions
- Requests arrive over HTTPS. Each one has a single destination number and a media configuration.
- Calls go out over one or more carriers through SIP trunks. Every carrier enforces both a maximum number of simultaneous calls (channels) and a maximum call-attempt rate (calls per second, CPS). Neither limit can be exceeded.
- There are a few hundred customers (tenants). A typical call lasts 2 to 5 minutes.
- Traffic is bursty: a campaign launch can generate thousands of requests within a few seconds.
- Each call follows this lifecycle:
queued → dialing → ringing → in_progress → completed | failed | no_answer | busy. - Customers learn about call status through webhooks and a status endpoint.
- Immediate calls should start dialing within seconds, but pacing or queueing during bursts is acceptable.
Questions worth raising early
- Are calls immediate, scheduled, or both? Are there campaigns and priorities?
- How many carriers are there, and what are their limits? Is failover or least-cost routing needed?
- What happens after the callee answers: static audio, a human agent, or a real-time AI agent with bidirectional audio?
- What per-tenant limits and quotas apply?
- What delivery guarantees do webhooks need (retries, duplicates, ordering)?
- Are there compliance rules such as consent, do-not-call lists, or calling-hour windows?
What to cover
- Call lifecycle and core design. Walk through the path from API request to a ringing phone and a bridged call. Define the main services, the call data model, and the API.
- Handling bursts. Many tenants submit far more calls than the carriers can place at once. Explain how you protect the system, respect carrier limits, and keep tenants treated fairly. Consider whether urgent traffic such as one-time-passcode calls must jump ahead of bulk campaigns.
- Reliability and observability. Cover no-answer, busy, carrier errors, dropped media, and workers that crash mid-call. Explain how you keep call state authoritative, retry safely, and monitor the system.
Hints
Hint 1
Estimate throughput with Little's law (concurrency = arrival rate x hold time). Work out how many new calls per second a carrier's channel limit really allows, and compare it to the CPS limit. Which one binds in steady state?
Hint 2
If the sustainable dial rate is far below the burst arrival rate, queueing is the core of the design. Think about ingress rate limiting, a durable queue, per-tenant fair scheduling, a separate class for urgent calls with reserved capacity, and an admission step that checks both CPS and channel budgets.
Hint 3
For reliability, treat call state as a state machine with conditional (versioned) updates, write intent before dialing, use idempotency keys, hold leases on active calls, and run a reconciler that frees leaked channel slots after crashes.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
1. Clarify and size the problem
Assumptions I would state out loud:
- Two traffic classes: realtime (OTP, verification; dial within about 2 s) and bulk (campaigns; minutes of queueing is fine).
- Three carriers, each with roughly 2,000 channels and 50 CPS.
- The answered leg streams audio both ways to an AI voice agent.
- Webhooks are at-least-once, with a per-call monotonic sequence number so clients can dedupe and order.
- Compliance checks (consent, do-not-call, local calling windows) happen at admission.
Capacity math. Little's law says concurrency = rate x hold time. With about 20 s of ringing plus about 3 minutes of talk, hold time is roughly 200 s. One carrier with 2,000 channels therefore sustains about 10 new calls/s, well under its 50 CPS. Across three carriers that is about 30 calls/s.
A burst of 50k requests in 10 s (5k req/s at the API) takes about 28 minutes to drain. Conclusions:
- In steady state, channels are the binding limit, not CPS. CPS matters mainly right after idle periods, when many channels are free.
- Queueing is the design, not an exception path. The API cannot absorb a burst by dialing faster.
2. API and data model
POST /v1/calls Idempotency-Key header
{to, from, agent_id, priority: realtime|bulk, campaign_id?, not_before?, metadata, webhook_url}
-> 202 {call_id, status: "queued"}
GET /v1/calls/{id} state plus event history
POST /v1/calls/{id}/cancel
POST /v1/campaigns bulk upload, schedule, window rules
Webhook: call.status_changed {call_id, status, sequence, timestamp, sip_code}
calls: call_id, tenant_id, idempotency_key (unique per tenant), to, from, agent_id, priority, campaign_id, state, version, carrier_id, carrier_call_sid, attempt, not_before, timestamps, end_reason. Use a sharded relational store keyed by call_id.call_events: append-only (call_id, seq, type, payload, source). It is the audit log and the feed for webhooks.- Redis (or similar) for live per-carrier and per-tenant counters and token buckets.
3. Architecture
Client -> API gateway (auth, per-tenant rate limit)
-> Call API (validate, compliance, idempotency, write row + outbox, 202)
-> Durable queue (Kafka/SQS), partitioned by tenant and priority
-> Scheduler / admission controller (fairness + carrier budgets)
-> Dialer workers -> SBC / SIP stack -> carriers
Answered call -> media gateway -> voice agent
State changes -> call_events -> outbox -> webhook dispatcher -> client
The request path is synchronous only up to the durable write: the API never dials. Dialing is asynchronous. SIP responses drive the state machine: 100/180 means ringing, 200 OK means in_progress (then bridge media), 486 means busy, timeout or 408 means no_answer, and 5xx means failed or a retry on another carrier.
4. Surviving the burst
- Ingress backpressure. Per-tenant token buckets at the gateway return
429withRetry-After. Add a per-tenant cap on queued calls so storage cannot grow without bound. - Two priority classes. Separate queues for realtime and bulk, plus a reserved slice of each carrier's channels (say 10%) that only realtime may use. OTP calls never wait behind a 50k-call campaign.
- Fair scheduling. Run weighted fair queueing or deficit round-robin across per-tenant queues. A tenant with 50k queued calls gets the same share as one with 50, unless contract weights differ. Add per-tenant concurrency caps so nobody holds every channel for hours.
- Carrier gating. Admit a dial only if it gets a token from the carrier's CPS bucket (refilled at about 90% of the limit as a margin) and a channel slot (active < limit - reserve). Release the slot on any terminal state. Autoscale dialers on admitted work, not queue depth; queue depth tells you drain time, not worker need.
- Pace the output. Emit dials evenly (for example every 20 ms) instead of in batches, since carriers penalize micro-bursts.
Trade-off: strict fairness can leave capacity idle if one tenant is the only one with work. Use work-conserving scheduling so unused share flows to whoever has demand.
5. State, retries, observability
Authoritative state. Every transition is a conditional update:
UPDATE calls SET state=$new, version=version+1
WHERE call_id=$id AND state IN ($allowed_prev) AND version=$v
Stale or illegal events (a ringing after completed, duplicate hangups) are dropped and logged. Terminal states are absorbing. Carrier callbacks are inputs, not the source of truth.
Idempotency. The unique (tenant_id, idempotency_key) index returns the existing call on client retries. Each dial has an attempt number, and the worker records dialing, attempt=n before sending the INVITE, so a crash cannot produce a blind duplicate dial.
Crash recovery. Workers hold leases (TTL plus heartbeat) on active calls. A reconciler finds expired leases in non-terminal states, asks the carrier or SBC for the real status by carrier_call_sid, advances the state, and frees the channel slot. Leaked slots are the classic bug that slowly strangles capacity, so also put TTLs on slot leases.
Retry policy.
| Outcome | Retry? | How |
|---|---|---|
| Carrier 5xx or timeout before ringing | Yes | Another carrier, exponential backoff with jitter |
| Busy / no answer | Only if the customer asked | Business-level retry, e.g. after 30 minutes |
| Answered call that dropped | No by default | Never auto-redial a person who already picked up |
Webhooks. Use the transactional outbox for at-least-once delivery, retry with backoff, include the sequence number, sign payloads, and use a dead-letter path with a replay API.
Observability. Track per-carrier channel utilization and CPS headroom, queue age (oldest item) per tenant and class, time from accept to dial, answer-seizure ratio, SIP error code breakdown, leaked-slot count, and webhook lag. Alert on queue age for realtime traffic and on sudden drops in answer rate per carrier, which should trigger automatic traffic shifting.
6. Common mistakes
- Trying to scale by dialing faster instead of queueing and pacing.
- Using queue depth as the autoscaling signal.
- Forgetting that channels, not CPS, bind in steady state.
- One shared FIFO queue, letting one tenant starve the rest.
- Trusting carrier callbacks as truth, or re-dialing after a worker crash without checking.
- No reconciler, so channel slots leak.