Call queue management with Twilio
Handle high-volume calls with Twilio queues when hitting Vapi concurrency limits
Overview
When your application receives more simultaneous calls than your Vapi concurrency limit allows, calls can be rejected. A call queue system using Twilio queues solves this by holding excess calls in a queue and processing them as capacity becomes available.
In this guide, you’ll learn to:
- Set up Twilio call queues for high-volume scenarios
- Implement concurrency tracking to respect Vapi limits
- Build a queue processing system with JavaScript
- Handle call dequeuing and Vapi integration seamlessly
This approach is ideal for call centers, customer support lines, or any application expecting call volumes that exceed your Vapi concurrency limit.
Prerequisites
Before implementing call queue management, ensure you have:
- Vapi Account: Access to the Vapi Dashboard with your API key
- Twilio Account: Active Twilio account with Account SID and Auth Token
- Twilio CLI: Install from twil.io/cli for queue management
- Phone Number: Twilio phone number configured for incoming calls
- Assistant: Configured Vapi assistant ID for handling calls
- Server Environment: Node.js server capable of receiving webhooks
You’ll need to know your Vapi account’s concurrency limit. Check your plan details in the Vapi Dashboard under billing settings.
How it works
The queue management system operates in three phases:
Incoming calls are automatically placed in a Twilio queue when received
Server monitors active Vapi calls against your concurrency limit
When capacity is available, calls are dequeued and connected to Vapi
Call Flow:

- Incoming call → Twilio receives call and executes webhook
- Queue placement → Call is placed in Twilio queue with hold music
- Automatic processing → Server automatically checks queue every 1 second
- Capacity check → Server verifies if Vapi concurrency limit allows new calls
- Dequeue & connect → Available calls are dequeued and connected to Vapi assistants
- Concurrency tracking → System tracks active calls via end-of-call webhooks
Implementation Guide
Create Twilio Queue
First, create a Twilio queue using the Twilio CLI to hold incoming calls.
Expected Response:
Save the queue sid
(e.g., QUaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
) - you’ll need this for queue operations.
Configure Phone Number Webhook
Configure your Twilio phone number to send incoming calls to your queue endpoint.
- Go to Twilio Console > Phone Numbers
- Select your phone number
- Set A call comes in webhook to:
https://your-server.com/incoming
- Set HTTP method to
POST
- Save configuration
Set up Server Environment
Create your Node.js server with the required dependencies and environment variables.
Install Dependencies:
Environment Variables (.env):
Implement Queue Management Server
Create the main server file with queue handling, concurrency tracking, and Vapi integration.
Configure Vapi Webhooks for Call Tracking
Configure your Vapi assistant to send end-of-call-report webhooks for accurate concurrency tracking.
Assistant Configuration: You need to configure your assistant with proper webhook settings to receive call status updates.
The webhook will be sent to your server URL with the message type end-of-call-report
when calls end. This allows you to decrement your active call counter accurately. See the Assistant API reference for all available server message types.
Webhook Payload Example:
Your /call-ended
endpoint will receive a webhook with this structure:
Test the Queue System
Deploy your server and test the complete queue management flow.
Start Your Server:
Test Scenarios:
- Single call: Call your Twilio number - should connect immediately
- Multiple calls: Make several simultaneous calls to test queuing
- Capacity limit: Make more calls than your
MAX_CONCURRENCY
setting - Queue processing: Check that calls are processed as others end
Monitor Queue Status:
Automatic Queue Processing
The system includes automatic queue processing that runs continuously to ensure optimal call handling:
How It Works
- Smart checking: Only runs
processQueue()
whencallsInQueue > 0
- Queue counter tracking: Increments when calls enter queue, decrements when processed
- 1-second intervals: The server checks for queued calls every second
- Efficient processing: Only processes calls when both capacity is available AND calls are waiting
- Error handling: Continues running even if individual queue checks fail
Benefits
Calls are processed within 1 second of capacity becoming available
No need to manually trigger queue processing - it happens automatically
System continues running even if individual API calls fail
Handles high-volume scenarios without missing queued calls
Performance Considerations
- Minimal API Calls: Only queries Twilio API when
callsInQueue > 0
- Counter Synchronization: Automatically syncs queue counter with actual Twilio queue state
- Efficient Resource Usage: Avoids unnecessary processing when queue is empty
- Graceful Degradation: Handles temporary API failures without crashing
- Smart Logging: Provides clear visibility into queue and active call counts
The automatic processing ensures that as soon as a Vapi call ends and creates capacity, the next queued call will be processed within 1 second, providing near-real-time queue management.
Troubleshooting
Calls not being dequeued
Common causes:
- Server not receiving call-ended webhooks (check webhook URLs)
- Concurrency counter stuck (restart server to reset)
- Vapi API errors (check API key and assistant ID)
Solutions:
- Verify webhook URLs are publicly accessible
- Add logging to track concurrency changes
- Test Vapi API calls independently
Queue filling up but not processing
Check these items:
MAX_CONCURRENCY
setting is appropriate for your Vapi plan- Queue processing is being triggered (check logs)
- No errors in Vapi TwiML generation
Debug steps:
- Call
/process-queue
endpoint manually - Check
/health
endpoint for current capacity - Review server logs for error messages
Calls dropping or hanging up
Potential issues:
- Invalid phone number format (use E.164 format)
- Incorrect Vapi configuration (phone number ID, assistant ID)
- Network timeouts during TwiML generation
Solutions:
- Validate all phone numbers before processing
- Add timeout handling to API calls
- Implement retry logic for failed Vapi requests