pinecallDocs
Operating / Scaling

Scaling

What each process costs, where it saturates, and how an environment's fleet grows.

The runtime is gateways on a cluster with workers on as many machines as the calls need. It is configuration: a worker is pinecall-runtime worker start on a machine that reaches the gateway and LiveKit, holding its environment's fleet key. The operator's verbs are The runtime CLI; the cluster it runs on, from nothing, is A server made by Terraform.

Growing it, step by step#

The runtime runs on a Kubernetes cluster (infra/): a core node for the platform's services, a media node per environment with its LiveKit, its SIP and a few small workers, and a pool of worker nodes per environment that grows with the calls. Each row is a value of the chart or of Terraform, never a machine made by hand. The numbers are what the runtime was measured holding on machines of the same types (the tables below); on the cluster they are proven on staging before production.

you need do holds (measured)
a cluster make tf-plan, make tf-apply, make image, make deploy (A server made by Terraform) two gateways, Postgres, a LiveKit, a SIP and two small workers per environment
the smallest cluster that answers at once an environment's media on the core node (envs.<env>.mediaPool: core), its core workers' seats raised to what that machine holds, and no scaled worker kept warm (scaled.min: 0): the infra's README, "A small deployment" the seats of the core workers, with no wait; past 60 % of them busy the gateway orders a scaled worker, whose node takes a minute or two ("The burst", below)
more calls at once nothing: KEDA adds a scaled worker when the gateway asks for one, and the cluster autoscaler a node for it ("The burst", below) 32 calls a scaled worker, alone on an 8-vCPU node at ~60 %
more gateway processes gateway.replicas in the chart's values ~330 calls a gateway core
Postgres that outlives a node postgres.instances: 2 (charts/postgres): CloudNativePG keeps a streaming replica and promotes it; its WAL and nightly base backups are in a bucket either way —
past ~15 000–20 000 calls a second cell: another cluster, an org living in one Postgres grows ~1.4 cores per 1 000 calls; one database is one cell

Four planes, each grows on its own#

plane what it is grows with
control the gateways: logs, keys, routes, quotas, the roster; any serves any endpoint of any call, telling the others what it did on Redis requests, never calls: another gateway behind the balancer
media LiveKit rooms, SIP, WebRTC: a LiveKit per environment, so a sandbox call never shares a machine with a production one one per environment and region, beside the callers
workers the conversations: the ears, the model, the voice calls
callers the simulated callers of spoken test calls: a voice into a room, three a process simulations at once (below)

The control plane is as many gateways as the requests need. Each keeps in memory only a cache of what Postgres holds and what is bound to a connection it holds (an app socket, a stream, a written call's session, a WhatsApp thread) and, for five seconds, a key it verified; everything else is in Postgres, or said on the signal each second (who holds which agent, the roster, an org's calls at once). A key revoked, or a person changed (role, agents, production, operator, disabled), at an endpoint is forgotten on every gateway at once, said on the signal; a change made at a shell (keys revoke) holds for those seconds on a gateway that remembered the key. Any gateway answers any request of a call, so the cluster's load balancer sends each wherever it likes and a second gateway costs a call nothing; the chart runs two (gateway.replicas), and a disruption budget keeps one up through a node's drain. A release never shows a caller a 503: a stopping gateway serves on for 30 s (its pod's preStop) while the load balancer takes it out of the group, and only then closes; and it keeps an idle connection 620 s, past the load balancer's 600, so the load balancer never sends a request down a socket the gateway already closed. A new gateway imports every vendor's plugin before it listens (5 s), so no request waits on the first endpoint that lists the vendors.

The simulated callers are a plane of their own#

A spoken simulation has two sides: the agent, which a worker of the sandbox's fleet runs like any call, and the caller, a voice that speaks into the room. The caller is played by a callers process, a loop with nothing on it but the few callers it claimed, and a gateway only places it.

placed the gateway that takes the request writes the caller's row (caller_jobs): the simulation whole, as it was asked for, and the org's place on its line
claimed a process with room takes the next row that waits (for update skip locked): the caller of the org that holds the fewest first, then the one placed first. No two processes ever take one row
played on that process alone, from the seat it asks the fleet for to the hang-up. It says every 10 s that it still has the caller
let go played to its end, the job is over. Broken before the call began, the process says why on the row and a gateway ends the call with that reason (a callers process has no live side). Cut while the process stops, a caller whose call never began is another process's to play whole; one on the line leaves a call that is over, and a comparison places it again
left a process silent for 40 s is gone: a gateway gives the caller's seat back and closes its room, and the caller is played whole by another process if its call never began, once; else the call is over and its comparison places it again

One process plays two callers at once (PINECALL_CALLERS_PER_PROCESS), and the service runs several (PINECALL_CALLER_PROCESSES; unset, half the cores it is given). A caller costs 0.18 of a core: its voice synthesised, resampled, stretched and mixed with its room, handed to LiveKit ten milliseconds at a time, a tenth of a second ahead. Two are about a third of the one core a Python loop has, so a burst from one leaves the other its time (with three, a process woke 55 to 66 ms late under twenty calls at once, and two callers' voices broke up). A process reads the clock twenty times a second and, after a reading that came 50 ms late, claims nothing for ten seconds: the callers it plays are what made it late, and one more would break the voice of all of them. Each caller's leg also counts the frames it handed to the room after the one before had run out, and keeps the count with the call (call_facts.caller_line: {frames, late_frames, late_ms, worst_ms}): a call whose line ran late was heard broken by its agent, and says nothing of the agent.

What this replaced, measured on 2026-11-25: every simulated caller was a task of the gateway that took its request, beside its endpoints, its loops and its app sockets. Six at once were clean. Nineteen at once put two cores of work on one loop: the room heard 20 to 100 ms of silence inside the caller's words, 36 to 55 times a minute, in 101 of 140 calls of one run; a realtime model's reply measured 3.35 s there and 0.77 s with ten at once; the same loop kept the gateway's pool busy, and workers and the CLI were answered 503. And a gateway started again ended every simulated call on the line with it.

A release drains them. A callers process told to stop (SIGTERM) claims no other caller and ends when the calls it plays do, eleven minutes at most (a simulated call lasts ten); the service waits for every one of its processes, and its container or pod is given twelve. A gateway that rolls ends no simulated call: it plays none. During a release the new callers' processes start once the old ones ended, so a caller placed meanwhile waits for one, as it would for a seat.

Sizing. A simulated call takes a seat of the sandbox's fleet and half of a callers process: 0.22 of a core at the worker and 0.18 at the caller. Sixteen at once are eight processes and about 6.4 cores between the two. On a server the service is one container (callers); on a cluster it is the Deployment pinecall-callers (callers.replicas, callers.processes), each process holding at most PINECALL_CALLERS_PER_PROCESS + 2 connections of Postgres. A gateway that is not told a callers service exists (PINECALL_CALLERS_SERVICE unset: a laptop, a machine with one process of each) claims and plays callers itself, by the same rows and under the same two at once: it stays on time, and what it cannot play yet waits.

Rolling to it. The migration first (caller_jobs starts empty), then the gateways and the callers service together. A gateway of the release before plays the callers of the calls it placed as it always did and writes no row; a new one writes rows that only a process of this release claims. Until every gateway is new, the org's most at once is counted apart by the two kinds (an old gateway's memory, the new ones' rows), so an org may pass it by what the other kind placed.

A fleet per environment#

One gateway serves both environments; what keeps a test call off a production process is a fleet of workers per environment. LiveKit dispatches by agent name, a worker registers under its unit's PINECALL_FLEET (pinecall for production, pinecall-sandbox for the sandbox by default, the fleets row of the platform, /v1/ops/fleets), and the gateway dispatches every call to the fleet of its environment. A worker holds its environment's fleet key, and the gateway refuses a call of the other environment. Everything below is per fleet: the roster is keyed by fleet, the totals are a fleet's, and the cluster asks how many scaled workers each fleet wants.

Capacity is counted in calls#

A worker hands LiveKit one number, its load, and LiveKit reads it twice, with one line, 0.7: livekit-server offers a job only to a worker whose last reported load is under it (agents.target_load, default 0.7; the worker reports every 2.5 s), and livekit-agents, in the worker, declines at it (load_threshold, default 0.7). A call neither will take is never offered again: if no other worker has room, it waits in its room in silence until the SIP bridge closes it. So a worker speaks LiveKit's scale: one gated on CPU reports its share of the machine, and one that counts its calls (PINECALL_MAX_JOBS) reports 0.7 × calls ÷ slots, so LiveKit's full is its last slot. To the gateway the same worker reports calls ÷ slots, full at 1.0, which is where the roster opens overflow. Neither of LiveKit's lines is overridden: they are its contract, the same on LiveKit Cloud. The worker's 0.7 is its own constant (REFUSED_AT in fleet/service/slots.py, read by jobs/service/load.py); no test reads the installed framework's line to hold the two equal, so a livekit release that moved it would go unnoticed.

(Until 2026-10-03 a counting worker reported calls ÷ slots to LiveKit too, and both of LiveKit's readers called it full at 0.7 of its slots while the gateway counted the rest free: a worker of 8 took six calls, a worker of 32 took 23, and the next rang in silence.)

The measure is taken, never guessed: on the machine type it will run on, calls with real audio, more each step, until first audio's p95 crosses what a caller tolerates; MAX_JOBS is one under it.

Two edges of LiveKit's remain, both a burst on a worker's last moment: the server reads a load up to 2.5 s old, so in a burst faster than that it may offer a worker on its last slot one call too many, which the framework declines and nobody retries; and a worker holding no call yet guesses each call's weight as its line over its warm processes, so it accepts at most that many in the same instant until the first is launched. With two workers or more, the server offers the declined call to another; on the last free slots of the whole fleet it is silence until the roster says full (five seconds) and overflow opens.

Set it; never leave a worker on CPU. Measured on 2026-10-01 with spoken calls (Deepgram, Haiku, Cartesia) against a worker alone on an 8-vCPU machine: on CPU, ten calls placed a second apart got five agents at 20 % of the machine — each new call's process loads the turn models, the CPU reading crosses 0.7 for an instant, LiveKit marks the worker unavailable and never offers that room again; counting (PINECALL_MAX_JOBS=20), 14 of 15 calls got their agent (the fifteenth was the 0.7 line) at 42 % of the machine. A call costs ~0.24 vCPU, so a worker machine holds about 2.9 × vCPU calls at the line: set PINECALL_MAX_JOBS to vCPU × 4 and the 0.7 line falls there. That is a machine of workers alone. On a machine that also runs other services everything shares the cores: each environment's media node runs its LiveKit and SIP beside two core workers, of two seats in production (an e2-standard-4) and of one in the sandbox (an e2-standard-2) (envs.<env>.workers.core in the chart's values), sized from the platform measured whole:

A deployment, measured whole. On 2026-10-01, on a deployment of production's machine type (4 vCPU: Postgres, LiveKit, SIP, the room's recorder of the time (egress), two gateways and one worker on it), SIP callers speaking a turn every 10 s and the three vendors faked on their own wire on another machine (the load lab): a call costs ~0.5 cores of the platform — ~0.3 the worker, ~0.12 its recording, ~0.1 SIP and LiveKit.

calls at once platform cores turns the agent answered first audio p50 / p95 ring to live p50
2 1.6 24 of 24 1.24 / 1.32 s 8 s
4 2.5 45 of 45 1.26 / 1.35 s 16 s
6 3.5 66 of 66 1.35 / 1.63 s 19 s
8 4.0 70 of 89 1.98 / 3.85 s 49 s
10 4.0 53 of 74; 3 calls never started 1.88 / 4.37 s —

Such a deployment holds six calls. Ring to live was a number of its own: each call's process imported every installed vendor plugin before its pipeline was live (3–5 s on an idle platform, and slower with the platform's load); the worker now imports them in its own process, so LiveKit's forkserver preloads them once and every call's process inherits them (measured the next day: 0.1 s, at any load). A worker killed under that load: its calls end drained 21 s later and the other worker tells each caller, as on an idle platform. A second livekit-sip on another machine, on the platform's Redis and LiveKit, took half of six calls at once, answered as through one.

Where a call is recorded (2026-10-02). Three ways, measured on the same lab:

how per call memory every voice
egress, one room composite (decode, mix, encode in a process of its own) ~0.12 vCPU ~80 MB yes
egress, one track egress per voice (no transcode, a process per track) ~0.2 vCPU (0.08–0.12 a track) ~170 MB a track yes
the call's own session (livekit's recorder, the voices already decoded there) ~0.06–0.09 vCPU of the worker — yes: the room's other voices and the melody are laid in when it closes (the file decoded and encoded once more, ~1/40 of its length on a core, nothing held in memory)

The session records: on a deployment alone it moves the cost rather than removing it (at six calls the worker went from 1.78 to 2.31 cores and the recorder from 0.60 to 0, the platform at 3.4 either way), but it needs no egress at all, it scales with the workers wherever they run, and it is what the next paragraph's machine of workers measured with.

A machine of workers alone (a worker machine joined to the platform), the same callers and fakes, the platform keeping the media plane and the gateways, the recording in each call's process and the file in the bucket:

calls at once worker machine (8 vCPU) per call the platform (4 vCPU), no worker on it turns answered first audio p50 / p95 ring to live
8 1.5 cores 0.19 1.5 cores 96 of 96 1.23 / 1.30 s 0.1 s
16 2.8 cores 0.17 2.3 cores 185 of 208 1.23 / 1.30 s 0.1 s
24 3.5 cores 0.15 1.8 cores 274 of 274 1.23 / 1.30 s 0.1 s

A call costs ~0.15–0.19 vCPU of a worker machine, its recording included, so vCPU × 4 seats (32 on 8 vCPU) is ~60 % of the machine with every seat taken; and the platform, holding SIP, LiveKit, the gateways and Postgres for those calls, spends ~0.1 a call: a 4-vCPU platform carries the media of about 25 calls before it needs a LiveKit node or a SIP node of its own (above). First audio did not move from 8 to 24: the worker machine was never the bottleneck of these calls, the platform was when the workers shared it.

Two vCPU on each side (2026-10-02, the load lab with an e2-standard-2 platform and an e2-standard-2 worker, made and destroyed by Terraform): the calls that started all held, but no step started more than six calls, whatever was asked: the worker had 8 slots and LiveKit refused it at 0.7 of them (above, "Capacity is counted in calls"); read the rows as what six calls cost, not as where two vCPU stop.

asked started worker machine (2 vCPU) per call the platform (2 vCPU), no worker on it turns answered first audio p50 / p95
8 5 1.35 cores ~0.27 0.86 cores 56 of 56 1.27 / 1.37 s
10 6 1.60 cores ~0.27 1.01 cores 67 of 67 1.33 / 1.80 s
12 6 1.57 cores ~0.26 0.97 cores 67 of 67 1.36 / 1.68 s

On two vCPU a call costs the worker ~0.27 vCPU (more than on eight: the job processes' start and the event loop weigh more on fewer cores) and the platform ~0.16; six calls already put the worker near 0.8 of the machine, so a 2-vCPU worker machine is not the shape to run a fleet on.

The production shape, after the fix (2026-10-03: platform e2-standard-4, worker e2-standard-8 with its 32 slots, the lab made and destroyed by Terraform):

calls asked started worker machine (8 vCPU) per call the platform (4 vCPU) turns answered first audio p50 / p95
16 16 2.77 cores 0.17 1.14 cores 193 of 193 1.23 / 1.30 s
24 24 4.14 cores 0.17 1.72 cores 288 of 288 1.23 / 1.31 s
32 29 4.56 cores 0.16 1.50 cores 334 of 336 1.24 / 1.33 s

Twenty-nine calls held at 57 % of the machine, first audio unmoved. The three that did not start were refused by livekit-server, not by the worker: its log on the lab's platform says, for each, failed to send job request: no servers available. The worker had moved the framework's line to every slot, but still reported calls ÷ slots, and the server cut at its own 0.7 of them, a few calls late because the report is 2.5 s old. Reporting on LiveKit's scale (above) is the fix, and the same lab measured with it, LiveKit's log clean of refusals:

calls asked started worker machine (8 vCPU) per call the platform (4 vCPU) turns answered first audio p50 / p95
24 24 3.73 cores 0.16 1.51 cores 284 of 284 1.23 / 1.30 s
32 32 4.55 cores 0.14 1.89 cores 371 of 371 1.23 / 1.31 s
32, two a second 32 3.57 cores 0.11 1.84 cores 370 of 374 1.23 / 1.31 s

Every one of the 32 slots takes a call, at 57 % of the machine, first audio unmoved from 16 to 32, and a burst twice as fast as the report to LiveKit (2.5 s) lost none: LiveKit's log over the three runs, 88 jobs assigned, zero refused. The runs between the two tables that started 12 of 24 and 8 of 32 were a fault of the lab, not of the worker: it destroyed each worker machine with its worker still up, and LiveKit keeps such a worker registered for 15–20 minutes (below, "A worker that dies"), offering it calls it cannot take. The lab now stops the worker first.

The same lab given 16 slots on a 2-vCPU worker (--seats 16 --calls 8,12) showed what an oversized MAX_JOBS costs: the worker at 1.9 of its 2 cores, 78 of 89 and 95 of 127 turns answered, first audio p95 3.9 s. (It started 8 of 8 and 12 of 12, which proves nothing about the line: 12 of 16 is under the server's 0.7 of 16 plus the report's lag.)

The gateway hears every worker#

Every five seconds a worker posts its heartbeat, {fleet, worker, agent_name, active, max_jobs, load, draining} and its last minute, {ended, failed, errors, turns, first_audio_p95_s}, and the answer says whether it is cordoned and whether its fleet is full. A worker silent 30 s is no longer capacity; one silent an hour is forgotten. The roster is in memory, on every gateway: each keeps the heartbeats that reached it and says them to the others once a heartbeat, so a worker is counted on every gateway whichever it beats on, and a cordon set on one stands on all (the newest setting of a worker's cordon wins). A gateway that restarts has it back after one round of heartbeats; a heartbeat's full is answered from totals at most a second old. GET /v1/ops/fleet and fleet list read it.

A worker registers with LiveKit under its own name, <fleet>/<worker>.<its start> (pinecall/worker-scaled-production-5f654f5f59-zwgjp.1791067258), and says it in each heartbeat as agent_name — only once LiveKit has registered it: a worker beats from its start, and a machine still loading its plugins is counted but offered no call, since LiveKit has nobody to give the job to. LiveKit offers a job only to the workers registered under the name the job's dispatch carries, so a dispatch to that name reaches that worker and no other: the gateway chooses (below, "Who takes a call"), not LiveKit's draw. The start is in the name because a worker can come back under the same name — a pod's container started again after its node was reset — while LiveKit still holds the last process's dead socket (below, "A worker that dies"): the roster keys by the worker's name, so the gateway hears only the newest registration and never offers the dead one a call. Measured on staging on 2026-10-03, before the start was in the name: two of sixteen calls offered to a worker that had come back under its old name went unopened three times and reached the overflow.

A worker that is up but bad#

A worker's calls run in livekit's job processes, and each tells its worker's main process, over a datagram socket the worker binds (jobs/service/measures.py), what its batches say: a turn's first audio (e2e_latency), an error, and how the call ended. The heartbeat carries the last minute of it: the calls that ended and those that ended in an error, the error entries, the turns measured and their first audio at the p95 (from five turns). Every call.started names the worker that ran it (worker).

The roster stops counting a worker as accepting when its minute is past the line (fleet/service/roster.py): at least half the calls that ended in it ended in an error, over four calls at least, or first audio's p95 is over five seconds, over twenty turns at least. It is left out only while another worker of its fleet accepts and is not past the line, so the line never empties a fleet: a deployment of one worker per environment keeps counting its one, and a fleet whose every worker is past it counts them all. Such a worker reads failing in fleet list and in /metrics (pinecall_worker_state, with pinecall_worker_first_audio_p95_seconds), and the fleet's accepting and full count without it. LiveKit's own dispatch is by load and does not read the roster: the worker keeps its seats with LiveKit, and a worker that stays past the line is the operator's to cordon. A worker of an older release carries no minute and is never past the line.

Who takes a call#

LiveKit's own dispatcher offers a job once, to a worker drawn by the load each last reported, and remembers nothing: a worker that declines, or a dead one LiveKit still lists (up to 20 minutes for a machine that vanished, above), leaves the caller in silence (livekit-server pkg/service/agentservice.go, selectWorkerWeightedByLoad; pkg/agent/client.go, no retry). The gateway knows more, every worker's seats, calls and last heartbeat, five seconds old at most, so the gateway chooses.

The SIP rule and a visitor's token keep dispatching to the fleet by its plain name, which no worker holds, so LiveKit starts no job and keeps the dispatch on the room with the call's metadata. When a person is alone in a room, LiveKit's webhook says so (participant_joined, or an agent's participant_left after a hand-over), and the gateway reads the room's newest dispatch: one to a fleet that nobody took is the call to place. The room is kept in offers until a worker takes it or the room ends. A worker takes a room as it accepts the room's job from LiveKit, in its own process and before the job's process starts (POST /v1/fleet/rooms/{room}/taken, jobs/service/heartbeat.py); the gateway also takes an agent joining the room (LiveKit's webhook) and the worker opening the call as that word, whichever it hears first (fleet/service/offers.py, fleet/service/arrivals.py): a caller who hangs up before any worker took the call leaves nothing to offer, and a dispatch on a room that is gone would make the room again. An outbound call, a simulated caller and a call whose worker went away are offered the same way, by the endpoint that makes them. So the gateway needs LiveKit's webhook (livekit.yaml's webhook.urls), each environment's naming its environment (?world=sandbox), so the gateway asks the LiveKit the room is on: a deployment without it places no call. A room is dispatched on the LiveKit of its fleet's environment, which the fleets row says. The gateway offers it to the worker of the fleet heard in the last 12 s with the most seats free, by its LiveKit name (<fleet>/<worker>, above): no other worker can take it. A seat is taken from the moment a room is offered to its worker: the offer counts until the worker takes the room, and from then until that worker's next heartbeat, which is the first to say the call itself: a heartbeat counts the calls the worker runs and the jobs it accepted whose process has not started. A caller that can wait (a simulated one) is seated only where a seat is, asked for and taken in one step with the fleet's seats held for it, so several that ask at once are never sent to the same seat; it takes the seat before it opens its voice or its room, so a queue of callers holds nothing open. A person does not wait for a seat and a simulated caller does, so it is the one that leaves seats free: it takes a seat only while a quarter of the fleet's seats would still be free after it (two of eight, one of four; a fleet under four seats, or one whose workers count none, keeps none), and simulations never hold more than the other three quarters while a person's call finds a seat. The seats a waiting caller may take are shared between the orgs waiting for them. A caller told to wait stands in its fleet's line (the table seat_turns: its room, its org, when it first asked, when it took its seat), and a seat that frees goes to the org that holds the fewest seats of that fleet at that moment; among orgs that hold the same, and among one org's own callers, to the caller that has waited longest. An org alone in the line takes every seat there is, since nothing is held back for one that is not asking. Two orgs that evaluate at once come to half each and three to a third; an org that arrives while another holds everything is given the next seats that free, and no call on the line is ended to make room. The line is rows, read under the fleet's turn (a Postgres advisory lock), so the answer is the same whichever process asks. One of a process's own callers at a time asks Postgres for the turn, the others waiting in the process with nothing in hand: each waiting on the lock in a transaction of its own held a connection, and twenty placed together kept a gateway's whole pool there (2026-11-25). An ask that finds no connection free is a seat not got this time, asked for again two seconds on. A caller says it still waits each time it asks, every two seconds: one unheard for ten is passed over, and has its place again when it asks. Its seat is given back as its line closes or its room finishes; one nobody gave back stops counting as its org's after twenty minutes. Until 2026-11-25 a freed seat went to whichever caller asked first, and one org's comparison of sixty calls kept every other org's simulation waiting behind all of its own. LiveKit hears a worker's load every 2.5 s and the gateway its calls every 5 s, so a seat the heartbeat says free may still be full to LiveKit, which then gives the room's job to nobody: such a room is offered again, to another worker first and to the same one when no other has a seat. A simulated caller's room is never sent to the overflow: it waits in the table for a seat. A room no worker took 12 s after its offer is offered to another (LiveKit waits 10 s on a worker that does not answer; a worker that gets a job says so as it accepts it, in milliseconds). The twelve seconds measure that alone, a job LiveKit gave to nobody, and never how long a job takes to start: a worker starting many jobs at once takes over twelve seconds to join each room, and until 2026-11-25, when a room was its worker's only once its agent had joined, such rooms were rung again and the second job ended the call the first was holding. A job accepted that never starts (LiveKit assigned it to nobody after all, or no process could be launched for it) is given back by its worker (DELETE /v1/fleet/rooms/{room}/taken?worker=) and offered again. So is the room of a job that started and left before its call was open, whatever took it out (the gateway away past the job's wait, a refusal, a fault of the worker's own, its process told to stop): the job says the same word as it goes. What a job asks the gateway before its call is open (its routes, whose ring it is, its agent, its stages, what it plays a held caller) it asks again while the gateway is away or busy, thirty seconds in all, and the open itself for fifteen: on 2026-11-25 a gateway whose pool had no connection free for two seconds answered three jobs of twenty 503, each ended on that one answer, and their rooms, held for their worker since the accept, were rung by nobody while their callers waited 110 s. A process killed outright says nothing: its room stays its worker's until the fleet forgets it at 120 s. Should a room be rung twice all the same (a gateway that never heard the worker's word), the first job to open the call has it: the second, which finds another agent seated in the room, is answered 410 and leaves the room as it is, with nothing written and nothing sealed. After three offers, or when the workers of the fleet heard lately have no seat, the room goes to the fleet's overflow (<fleet>/overflow, below): the caller hears one sentence and a call back is written. A fleet none of whose workers was heard in 12 s is one a gateway that just started knows nothing of yet (the next heartbeats, five seconds, tell it): its room waits for the next sweep, for up to 12 s from the caller's arrival, and only then goes to the overflow. Any gateway sweeps the rooms every 3 s; an offer is taken by the update that finds the count it read, so two gateways never offer one room twice. A dispatch that names no agent is LiveKit's own automatic one, to the workers registered with no name, which none of ours is: the gateway reads no call off it. A room kept under a fleet that is no environment's (the operator renamed the fleet between the arrival and the sweep) is let go at its next offer, with one line in the journal, not swept until it ages out. fleet list says each fleet's rooms waiting for a worker in the last ten minutes, and /metrics as pinecall_fleet{what="waiting"}: a number that is not 0 is a call that LiveKit or a worker dropped. Each offer is a line in the gateway's journal, room <call>: offered to <fleet>/<worker>: 3 seats free, heard 2 s ago, so make logs | grep <call> says who took a call and why; doctor's offers line names a room kept past a minute, which only a deployment with no gateway sweeping leaves.

Full, at the endpoint#

When every worker of a fleet is at the line, the token endpoint answers 503, writes fleet.full on the agent's log, and names POST /v1/callbacks, so a page offers a call back before any room is made. A phone caller arriving at a full production fleet is answered by the overflow (the Deployment overflow-production), registered as <fleet>/overflow and offered a call by the gateway alone, when no worker has a seat or a room ran out of offers: one sentence, in the agent's language (English or Spanish, English for any other) unless PINECALL_OVERFLOW_SAYS names one for every call (a call back is promised to a caller with a number, never to a page's visitor), the caller's number onto the agent's log as callback.requested, and it hangs up. No ears, no model. An org's own concurrency is its concurrent_calls quota, counted on the calls this gateway serves in that environment and held at the endpoint, never mid-call: sandbox calls never use up production's.

Deploys drain, cordons shrink#

A worker told to stop takes no new call and drains what it holds for up to ten minutes, then ends what is left: each call's job has two and a half minutes to write the call's end, seal it and let its room go, in that order (A_JOB_ENDS_WITHIN_S in jobs/service/job.py, livekit's session_end_timeout). Kubernetes waits fifteen (the pod's terminationGracePeriodSeconds, 900). It beats to the gateway all the while, so the roster goes on counting the calls it holds. A cordon (fleet cordon, POST /v1/ops/fleet/{worker}/cordon) is told on the worker's next heartbeat: it takes no new call, finishes what it holds, beating until it has, and exits 3. In a cluster its Deployment starts the container again under the same name, which is still cordoned, so a cordon there is for looking, not for taking a worker out: a pod is taken out by deleting it (kubectl delete pod), which stops its worker the same way, drained.

A deploy never closes a fleet. Each environment's core workers are a Deployment that replaces one pod at a time and never has fewer than it asks for (maxUnavailable: 0, maxSurge: 1): the new pod is started and answering on its health port (its startup probe) before an old one is told to stop, and the old one drains its calls while the new one takes every new call of its environment. The scaled workers roll by Kubernetes' default, a quarter of them at a time, each old one draining its calls as it goes. No call is moved.

A worker that dies#

A worker killed, a machine gone or a job's process dead leaves its callers in rooms with nobody answering. LiveKit says so: its agent leaves without a goodbye (the connection lost, not closed), and LiveKit's webhook tells the gateway (POST /v1/livekit/webhook). If the call is still open and its caller still in the room, the call goes on in another worker. The gateway offers the room to the environment's fleet as it offers any call (above, "Who takes a call"), with a job that says the call's worker went away. The worker that takes it asks the gateway for the call (POST /v1/calls/{call}/taken-up) before it joins the room, and is answered how the call was opened, what was said on it and how many entries its log holds. It builds the session on that history and tells the caller first, in the agent's language: "We are sorry, there was a technical problem on our side. Please stay on the line, we are picking up right where we left off." Then the agent answers what the caller said last, if the loss cut its reply, and the call goes on: the same call, the same log, the same app holding it, its ceiling counted from its first start. The log says the loss once, as an error entry with the code worker_lost.

What is lost with the worker is what only it held. The sentence the agent was saying is not in the log, so the second worker does not know it; the tokens the first worker's models used are not counted; and a recorded call keeps the audio from the moment it was taken up, the first part having been on the disk of the machine that went.

The gateway does not wait for LiveKit to say the worker is gone. LiveKit takes about twenty seconds (it waits for the agent's connection to come back), and with only its word the caller sat in silence 23 to 26 s from the worker's pod deleted to the call handed on, measured on 2026-11-16 in three calls. A worker reads its call's commands from a stream it opens again half a second after it ends, so the gateway that serves the stream sees it cut the moment the worker dies. A stream still cut a second and a half later is a worker that is gone, or one the gateway cannot reach, which cannot run a call either: the gateway takes the agent out of the room, so the room never holds two, and offers the call (live/service/stranded.py, hand_on_cut). A worker that was alive after all finds itself removed from the room and leaves the call, and its room, to the one that took it up. A gateway told to stop ends every stream itself and hands nothing on; a machine that vanishes without closing its connections is still LiveKit's to report, twenty seconds later.

Two gateways give one answer. A deployment runs more than one gateway and a worker's requests reach whichever its connection lands on, so nothing of this is one gateway's memory. Three things are shared:

  • Who reads the call. A worker opens its stream again on any gateway, and the one it left sees a call nobody reads. Every gateway says the calls read from it, each second and at once when a stream begins (the signal's reading channel): a wait that runs out on one gateway while the worker reads from another hands nothing on. The gateway a worker read from last is the one that says it gone.
  • Which worker has the call. The log's head counts the workers that took the call up (call_log_head.taken_up). A take-up moves the count in one statement, from the value its asker read and only while no gateway is sealing the call, so two workers that ask at once are not both answered; a seal says which of the call's workers sends it and is checked against the head under the seal's lease, so the worker a call was taken from is refused by either gateway.
  • That the worker is gone. The gateway that hands a call on tells the roster its worker left (Roster.say_gone), and every gateway offers that worker nothing, this call or any other, until it beats again. Without it the gateway would choose it: heard seconds before, and a dead worker has every seat free. A worker that was alive after all beats within five seconds and is back.

How long a worker that came back was away is logged by the gateway each time a cut stream reads again ("reads its commands again, N s after its stream was cut"): that is what the wait (GONE_AFTER_S, 1.5 s) is to be judged against.

Measured on 2026-11-16 on production's sandbox, three simulated calls, the pod of the call's worker deleted at once while the agent answered: the call handed on 6.9, 7.3 and 7.2 s after the deletion, the second worker's first word to the caller at 8.9, 9.2 and 9.5 s, every call gone on with to its caller's goodbye, one call.started and one call.ended each. Those three were measured with a wait of three seconds. With the wait at a second and a half and the gateway's own times kept (three more calls, the same day): the stream was cut 3.0 s after the deletion, which is Kubernetes ending a deleted pod and not a worker dying; the call was offered 1.6 s after the cut and asked for by the second worker 0.3 to 0.6 s later; and the second worker's first word came 7.3, 8.7 and 12.2 s after the deletion, most of it the worker building the call's session before it speaks. With only the call's process killed and its worker left alive, which is a worker dying with nothing of Kubernetes in the way (two calls, the release of the shared count): the gateway saw the stream cut at once, offered the call 1.5 s later, the second worker took it up 0.4 s after that, and its first word came 3.7 and 4.6 s after the cut. The worker whose process was killed, alive and with every seat free, was offered neither call, and took calls again at its next heartbeat. In three of these five calls the hand-on, the take-up and the seal were not all answered by the same gateway.

One thing those calls found is mended. In 2 of the first 13 calls taken up, LiveKit (1.13.7) closed the room 26 ms after the caller left, as departure timeout, where a room is given 20 s after its last person leaves; a room an agent had left before is where it was seen. The second worker then wrote no end and sealed nothing, its job was stopped 150 s later, and the gateway's reaper ended the call as drained minutes after, with no summary and no recording. The worker was waiting, with no end, for the room to say the hold melody's track was unpublished, and a room that is gone says nothing; a room deleted under any call, taken up or not, did the same. The melody is let go of after two seconds without that answer (session/hold.py), and the call's end is written.

The call ends as drained, with one sentence and a call back for a phone caller, only when nobody can go on with it: no worker has a seat (the job goes to the overflow, which holds no call), the call never started, or the session to take it up cannot be built. That job says the overflow's PINECALL_OVERFLOW_SAYS, writes callback.requested on the agent's log, deletes the room and seals the call. Until 2026-11 that was the end of every call whose worker went away.

A worker that was lost to its room for a while and then comes back cannot end a call another one took up: the batch it sends late finds the log's count moved and writes nothing, and its seal is answered 410, on which it leaves the room standing. On a fleet of one worker, a dead worker's calls wait for it to come back (its Deployment starts it again in seconds), since the overflow opens only for a full fleet and a fleet nobody hears from is not full. A drain, a cordon and a call that ends leave on purpose, and are not this. If no job comes, the reaper seals the call after five quiet minutes, as before.

A machine that vanishes is worse than a worker that dies. A worker process that ends, even killed, closes its connection, and LiveKit forgets it at once. A machine that disappears whole (a VM deleted with the worker up, a kernel gone, a cable cut) closes nothing, and LiveKit 1.13.7 sets no read deadline on a registered worker (pkg/service/agentservice.go, after registration): it keeps pinging the dead socket until the kernel gives up, 15–20 minutes measured on 2026-10-03, and all that time it keeps offering that worker new calls, drawn by its last reported load, each offer waiting 10 s and then dropped with no retry. With one live worker beside the ghost, about half the new calls of that fleet are lost in silence until the ghost is gone. Every path the cluster drives — a release, KEDA letting a scaled worker go, kubectl delete pod — stops the worker before its pod goes (SIGTERM, then its drain), so none of them makes a ghost; a node lost to a fault does. Since the gateway chooses the worker (above, "Who takes a call") the ghost takes nothing: a worker unheard for 12 s is never offered a call, and one offered to it before that is offered again at 12 s. Measured on 2026-10-03 in the lab (two e2-standard-8 machines of 32 slots, 16 calls at one a second, the second machine powered off at once at the 8th call): 16 of 16 started; the 5 on the dead machine heard the sentence and ended as drained; the 2 the gateway had offered it before it was known dead were offered again at 12 s to the other and started; none went to the overflow, none was silent; 131 of 132 turns answered, first audio 1.23 / 1.31 s. With the gateway choosing, the same lab on one worker machine held its numbers: 24 of 24 (first audio 1.23 / 1.31 s), 32 of 32 (1.26 / 1.40 s, 378 of 382 turns) and 32 of 32 at two a second (1.24 / 1.32 s, 370 of 370), every call live 0.1 s after it rang.

Measured on 2026-10-01, when a call whose worker died ended there (a spoken call, its worker SIGKILLed 25 s in): 20.5 s from the kill to call.ended drained on the log — LiveKit's connection timeout for the agent, which leaves as CONNECTION_TIMEOUT — and the sentence's job on the other worker a second later; before LiveKit read its webhook, the same call waited for the reaper's five minutes. The sentence is said after call.ended is on the log: a client that hangs up on call.ended (the simulated caller of /v1/evals/voice does) leaves before it; a phone caller stays on the line and hears it.

The burst#

Each environment's core workers, on its media node, hold a quiet hour's calls; every call beyond them goes to a scaled worker, a pod of 32 seats alone on a node of the workers pool (e2-standard-8). How many of them a fleet runs is one number the gateway computes from the roster it already hears, GET /v1/fleet/wanted?scaled=<prefix>&seats=<n>&most=<n> → {fleet, wanted, active, seats} (fleet/service/demand.py), and KEDA keeps the Deployment at it, asking every 15 seconds with the environment's fleet key, which names the fleet (never the operator's: a read of one number needs no more); 422 without scaled and seats:

when the number
the core's seats keep busy (active / seats) at or under 60 % the scaled workers there are, or none
busy would pass 60 % what brings it back under, in whole workers of seats, the core's seats counted first, cut at most
busy would stay under 45 % (the target less 0.15) without one of them one fewer

The number is absolute: a pod still booting, not yet heard, is never asked for twice. Up is at once; down is one pod every five minutes, never sooner than ten minutes after the last change, and each pod let go drains its calls first (KEDA's ScaledObject, charts/pinecall/templates/ workers.yaml). A pod with no node to go to waits for the cluster autoscaler, which makes a node of the pool for it and removes a node once it is empty; nothing else sizes the pool, and its ceiling is Terraform's (workers_max). The ceiling of the pods is envs.<env>.workers.scaled.most in the chart's values, and their floor min: a scaled worker kept warm whatever the calls, so a burst finds its 32 seats at once instead of waiting the minute or two its node takes (the sandbox's is 1 since 2026-11-04, for ten simulations placed together; Keeping workers warm changes it in one line). A spoken simulation with no seat waits for one in its fleet's line, up to forty-five minutes, saying fleet.full on the agent's log; a real call goes to the overflow, and a golden run stops.

Measured on staging on 2026-10-03, with the lab (infra/lab/: SIP callers with real audio from a machine of their own, through the cluster's SIP node and LiveKit, the vendors faked on their own wire), production's environment, a turn every 10 s for two minutes, calls placed one a second:

the step started turns answered first audio p50 / p95 scaled workers · nodes after
4, on a cluster at rest 3 of 4: the fourth reached the overflow 33 of 33 1.32 / 2.22 s 1 · 1 (KEDA asked for one at the third call)
24 24 of 24 288 of 288 1.24 / 1.32 s 2 · 2
32 32 of 32 383 of 383 1.24 / 1.38 s 2 · 2
16, the node of the scaled worker holding the most calls reset at once at the 8th 16 of 16, none to the overflow; the calls on that node heard the sentence and ended drained 120 of 122 1.25 / 1.34 s 2 · 2
16, a release of a new image (make deploy) while they were up 16 of 16, none drained every caller turn 1.23 / 1.31 s —
8, Postgres's pod deleted 40 s in 8 of 8, 0 errors every caller turn — —

A scaled worker spent 0.25–0.31 cores a call. Production's four core seats, on the core node at the time, held on their 4-vCPU node beside the platform's services: two calls, first audio 1.24 / 1.32 s; four, 4 of 4 started and 46 of 46 turns answered at 1.26 / 1.39 s, the node at 57 %. The first step above, the first calls after a release, saw LiveKit's VAD run slower than real time on those workers and a p95 of 2.2 s; it did not come back. Postgres, deleted, stopped as CloudNativePG stops it, a smart shutdown that waited 180 s for its clients: the gateways' open connections went on serving and every call in flight was written whole, no new connection opened for three minutes, and the database was back at 3 min 4 s; charts/postgres now waits 15 s.

The core node, lost (its VM deleted, 2026-10-04): the node pool made another, kubeip gave it the same address, and the gateways answered again 7 minutes after the delete began, Postgres's disk attached to the new node; calls started on it as before. Every call of the moment is lost with the node: the core node's services are one of each.

Down, the same night with no call after 23:11 UTC: KEDA let the second scaled worker go at 23:17:53 and the last at 23:28:11, ten minutes apart as its window says; the cluster autoscaler deleted the first empty node at 23:30 and marked the second at 23:38, the workers pool back to zero nodes.

Keeping workers warm#

Each env's scaled workers are one line of the chart's values, envs.<env>.workers.scaled:

key what it is what it costs
min scaled workers kept up whatever the calls one node of the env's workers pool each, always on: an e2-standard-8, about US$195 a month on demand
most how many the fleet may grow to nothing until the calls ask for them
seats calls one scaled worker takes at once —

make fleet (the runtime's Makefile) changes that line and nothing else:

make fleet CLUSTER=production ENV=sandbox MIN=1          # one warm worker of 32 seats
make fleet CLUSTER=production ENV=sandbox MIN=0          # back to none: the fleet grows from the core alone
make fleet CLUSTER=production ENV=production MIN=2 MOST=5

It writes the line in the operator's values ($(OPS)/values/<CLUSTER>.yaml), commits it there when $(OPS) is a git repository, and releases charts/pinecall again at the image tag the release runs, read from Helm: no image is built and no code goes out. When the chart in this checkout differs from that image's commit it refuses and names make image && make deploy, since a chart the running image was not built with is a deploy, not a change of size. A value already written is released again all the same, and nothing moves.

Measured on production on 2026-11-05, ENV=sandbox MIN=1 (already 1): 72 s from the command to Helm's revision, the ScaledObject at min=1 max=3, the warm worker and every other pod kept as they ran. A higher MIN starts its pods at once and each waits the minute or two its node takes; a lower one lets them go as a lower call count would, one every five minutes, never sooner than ten minutes after the last change, each draining its calls first.

While min is 1 or more, Helm prints two warnings from KEDA: pollingInterval and cooldownPeriod only act when the floor is 0, the one being how often KEDA asks the gateway while the Deployment sits at none and the other how long it waits before going back to none. Above the floor the HPA's own behavior (the template's scaleDown) is what paces the way down, so both are expected and nothing is wrong.

The shape of the numbers#

50 000 calls a day · 4 min a call · 10 busy hours · ×2 at the peak
  = 50 000 × 4 ÷ 60 ÷ 10 × 2  ≈  667 calls at once

At 32 seats a scaled worker and 60 % busy, that is about 35 of them at the peak: for such a load, envs.production.workers.scaled.most: 35 in the chart's values and production's workers_max 35 in Terraform. The chart ships most: 10 for production and 3 for the sandbox, and Terraform the same ceilings.

The control plane, measured on 2026-10-01 with pinecall-runtime load from a machine of its own (the golden call as the script, 2.1 entries a second per call, every log read back and verified):

what measured so, per 1 000 calls at once
a gateway process 1 200 calls on four processes: 3.6 cores ~3 cores of gateway (~330 calls a core)
Postgres 1.9 cores at 1 200 calls, the gateways on the same machine the figure to plan with is the next-but-two row's: ~1.4 cores, measured with the gateways apart
append, worker to log p50 26 ms, p99 410 ms at 1 200 calls —
a gateway killed every minute 0 of 8 000 logs wrong; its calls go on on the others —
gateways on a machine of their own, the platform keeping Postgres 2 000 calls on six gateways (two on the platform, four apart): Postgres 2.6–3 cores, 9 017 calls sealed, 0 wrong ~1.4 cores of Postgres, linear from 1 200 to 2 000
a gateway machine killed for two minutes 1 200 calls: 6 778 opened and sealed, 0 refused, 0 wrong, 0 billed twice —
the media plane: two LiveKit nodes on one Redis lk load-test, voice rooms of two audio publishers and one subscriber, rooms spread across both nodes: 400 at once, 0 packets lost, 2.25 cores a node ~5–6 cores of SFU (~90 calls a core)
a worker on node 1 taking a room on node 2 the agent dispatched to rooms created on either node: every job assigned and joined (livekit 1.13.7) —
a machine of workers alone, the recording in the call's process (2026-10-02) 24 calls on 8 vCPU: 3.5 cores, first audio p95 1.3 s, every turn answered ~150 vCPU of workers (vCPU × 4 seats a machine)
the platform as the media plane alone 24 calls: 1.8 cores of SIP, LiveKit, gateways and Postgres ~0.1 a call: a 4-vCPU platform carries ~25 before a second media node

What this says of a cell: Postgres grows by about 1.4 cores per 1 000 calls at once, so a cell of 100 000 would need some 140 cores of one database, which no one machine holds; a cell is sized instead at 15 000–20 000 calls (a 32-core Postgres, ~50 gateway cores, ~1 000 worker machines) and the platform grows by cells. What saturated first at 2 000 calls was not Postgres but the platform's own two gateway processes and the proxy in front of them, on the same machine: in a cluster the gateways are pods of their own (gateway.replicas) and the balancer is Google's.