Back to Insights
VoIP Engineering

Least Cost Routing (LCR) in VoIP: How It Works and How to Implement It

Telephony Engineering Team
4 min read
Least Cost Routing (LCR) in VoIP: How It Works and How to Implement It

Least cost routing (LCR) selects, for each call, the carrier route with the lowest price for that destination, while falling back to alternatives if the preferred route fails. Done well it lowers termination spend. Done naively it quietly degrades call quality and completion.

How LCR Works

  1. You hold rate decks from multiple carriers, each listing a price per destination prefix.
  2. For a dialed number, find the longest matching prefix in each deck.
  3. Rank carriers by price for that prefix.
  4. Try the cheapest first. If it fails (busy, 503, timeout), advance to the next route.

Route failures at the carrier level are normal. The ordered list effectively becomes a failover chain.

Why Pure Cost Ranking Fails

A route that is 5 percent cheaper but completes 10 percent fewer calls costs you more in lost conversations, retries, and support. Mature routing weighs:

  • ASR (answer-seizure ratio) per carrier and destination
  • Post-dial delay
  • Audio quality (MOS, jitter, packet loss, see VoIP quality testing)
  • Caller ID handling and attestation (see STIR/SHAKEN)
  • Capacity and concurrency limits per trunk
  • Reliability history

A practical scoring method blends cost with quality and applies a minimum quality threshold below which a carrier is skipped regardless of price.

Implementation Patterns

In Kamailio: the lcr module stores gateways and rules in a database and returns an ordered list to try with a failure route, or use dispatcher for weighted/priority sets (see Kamailio dispatcher configuration).

In FreeSWITCH: build the bridge string dynamically from a routing API using multiple gateways separated by | for sequential failover.

Table design: destination prefix, carrier, price, priority, enabled flag, and effective dates.

Operating LCR

  • Update rate decks automatically when carriers send changes, with validation to catch format errors that would zero a price
  • Measure per-route KPIs from CDRs (see call detail records explained)
  • Dial a small share of traffic through new carriers to evaluate before shifting volume
  • Set per-carrier concurrency and CPS caps to avoid congestion rejections
  • Alert on sudden ASR drops, which often indicate a carrier problem

LCR and Customer Pricing

Margin is the difference between what you charge and what you pay. The billing side is covered in VoIP billing system architecture, and large buyers can improve economics through direct carrier agreements (see BYOC economics).

Pitfalls

  • Rate deck errors that make an expensive route look free
  • Ignoring minimum billing increments, which change the true price of short calls
  • Failover loops that retry the same failing carrier
  • No visibility into why a route was chosen. Log the decision.

Want routing that balances cost, quality, and failover? Our Kamailio load balancing team builds carrier routing engines for wholesale and enterprise networks.

Discussion

0

Join the conversation

Sign in with your preferred account to comment, reply, and keep the discussion useful for other engineers.

Takes a few seconds. No separate password required.

C

Controva LLC

Engineering Team

We build digital empires that scale. Specializing in high-performance web architecture, AI automation, and headless commerce.

Work with us

Share this article