Case Study/Voice & Telephony/Architecture, engineering, maintenance

Inbound Contact Center & ACD

Author
Aryan
Client
US support desk
Published
2026
Length
7 min · 1408 words

Abstract

Voice contact center on Telnyx with IVR screening, skill-based queues and a custom ACD over WebRTC.

Key outcomes

Routing
Custom ACD
Intake
IVR-screened
Audio
Telnyx WebRTC

Queues are application logic

Hosted contact center platforms sell routing as configuration. The platform provides a visual builder, a set of nodes and a fixed vocabulary of conditions such as business hours and caller ID. That is sufficient until the business’s routing rule is not one of the nodes, at which point the work becomes expressing a real rule in a vocabulary designed to be general. Every escape hatch, a computed field or a webhook pretending to be a condition, makes the flow harder to read than code would have been.

This system inverts that. The automatic call distributor is application code. The queue is a data structure, the priority function is a function, and overflow behaviour is a branch. The cost of that decision is that there is no admin screen for building a flow. The benefit is that the flow is testable, reviewable and expressible, because skills, priorities, overflow and dispositions are first-class concerns rather than the subset of them a generic platform happens to model.

Intake answers, screens and parks each call

A call arrives on the Telnyx Voice API and is answered. An IVR screens it, collecting what the business needs before the call reaches a person, and then the call is parked in a queue rather than held open in the application.

Parking is the important part. A queued call lives at the carrier and is represented in the application as a record with its position, its accumulated wait and its screening result. Nothing in the application is holding a media stream while the caller waits, so the wait costs carrier time rather than application memory. When the ACD selects an agent, the parked leg is connected to the agent’s browser over WebRTC, and only then does audio flow.

The ACD in practice

The distributor matches calls to agents on every change that could make a match possible: a new call arriving, an agent finishing wrap-up, an agent going unavailable, a supervisor pulling someone out of a queue. It is event-driven rather than a polling loop, because a poll interval is a wait interval and the quantity being optimized is how long a caller hears hold audio.

Three inputs decide a match. Which agents are available right now, which is presence rather than logged in, since an agent who is logged in but on a call is not available and an agent on break has said so. What skills the call needs, derived from the IVR path and the number it arrived on. And what priority the call carries, which is where business rules a generic platform cannot hold actually live.

Overflow is a first-class branch. When no agent can take a call within its target wait, the call does something specific: leave the queue, move to a different queue, or fall to voicemail. Making that a decision the application owns means it is not a platform limitation to route around.

State across three processes

The stack is a Turborepo monorepo with a web app, an API and an outbox worker, and the worker runs as a separate process. That separation is the source of the hardest constraint in the system: the processes do not share memory, and the database is the only place they can agree.

The contract between them is a packages/ workspace of shared Zod schemas, and that workspace is deliberately the only thing the API, the worker and the web app may agree on. If a payload shape is not in the shared schemas, it does not cross a process boundary. This is the difference between a monorepo that shares types and one that shares a runtime: nothing is imported across apps, and a schema change is a visible contract change rather than an accident.

The outbox pattern exists for the same reason. An operation that must both change state and cause a side effect, such as writing the call record and notifying the queue, cannot do both atomically against two systems. So the side effect is queued in the same transaction as the state change and the worker drains the queue. The failure mode this removes is the one where the record says a call was routed and the notification never went out, or the reverse. The failure mode it introduces is at-least-once delivery of the outbox entry, which means handlers have to be idempotent.

Postgres holds the durable records, Redis holds what is true for seconds, such as presence, queue counters and short-lived locks, and MinIO holds recordings. The honest trade is that any fact held in Redis can be lost on restart, so nothing that must survive a restart is allowed to live only there, and rebuilding volatile state from Postgres on boot is part of the design rather than an incident response.

Recording, transcription and cost per contact

Interactions are recorded, with the object stored in MinIO, and transcribed so a contact has a text artifact alongside its audio. The reason to transcribe rather than only record is that a recording answers what was said only if someone listens, and an operation that never has time to listen may as well not be recording.

Cost is reconciled per call against the carrier rather than reported per month. The per-month invoice is identical regardless of which queue, which agent or which call type produced it, and that is useless for deciding whether a routing rule is worth its cost. Reconciling to the individual call lets reporting answer cost per contact, which is the number a contact center makes decisions with. The audit trail covers every state change, so the path a call took is reconstructable rather than inferred.

Supervisor intervention is a routing primitive

Supervisors see queue depth and agent state and can intervene while the caller waits, taking a call themselves, pulling an agent or changing what a queue is doing. The reason this is grouped with routing rather than treated as a dashboard feature is that intervention is just another event the ACD handles. A supervisor picking up a queued call is not a special case in the matching code; it is a higher-priority claim on the same call.

The same surfaces carry wrap-up and dispositions, which completes the record before the next call arrives. If disposition were a separate screen it would be skipped under load and the system would accumulate calls with no outcome. Putting it on the surface the agent is already on makes the record complete by default.

Authentication and the shape of the deployment

Authentication is first-party with argon2id, and OIDC is an optional federated path rather than the foundation. That ordering is deliberate. A contact center’s identity needs are agent accounts, roles and sessions, and a first-party implementation keeps the dependency graph small and session behaviour under the application’s control. OIDC exists for the customer who already has an identity provider and wants to federate, not as the mechanism everything else is built on.

Postgres, Redis, MinIO and OpenTelemetry come up locally under one docker compose, because a stack with four backing services only stays approachable if onboarding is one command. OpenTelemetry is wired from the start rather than added when something is slow, since traces that begin after the incident begin too late.

What was hard, and what I would change

The hard part is that a match decision is taken in one process from state written in another, and the two processes can disagree about the answer for the duration of a transaction. Handling that with an outbox and idempotent handlers works, and it converts a correctness problem into a duplication problem, which is the right trade. It also means every handler has to be written as though it will run twice, and one handler that is not is a call offered to two agents at once.

What I would change is where presence lives. Presence in Redis is fast and simple and is also the state most likely to be stale at exactly the moment a match is computed. Rebuilding it on boot is necessary, but the sharper improvement is to treat presence as a lease with an expiry rather than a flag, so an agent that disappears without cleanly going unavailable stops being matchable on its own instead of requiring a sweep. That is the difference between a system that is correct when everything goes well and one that is correct when a laptop sleeps mid-shift.

References

  1. [Author]Aryan (Uo1428)

Built with

BunElysiaPostgreSQLRedisTelnyxReact 19

Related production systems from the same category.

All case studies →

Want this kind of system on your side of the table?