Blog
  • AI Gateway
  • AI Security
  • AIOps
  • API Security
  • API Gateway
|
    • API Management
    • API Development
    • API Design
    • Automation
    • Service Mesh
    • Insomnia
    • View All Blogs
  1. Home
  2. Blog
  3. Engineering
  4. Deep Dive into Kong Gateway's New Rust-Based Router
Engineering
July 18, 2024
3 min read

Deep Dive into Kong Gateway's New Rust-Based Router

Guanlan Dai

What is the Expressions Router?

The router component in the Kong Gateway is a crucial element for traffic handling, allowing the definition of specific matching rules to identify and process client requests. As a core component of the gateway, the router plays a vital role in ensuring the functionality, flexibility, security as well as performance of the gateway.

In the 3.0 version update of the Kong API Gateway, the routing system was completely rewritten in Rust — a memory-safe and efficient language. A concise DSL (Domain Specific Language) was designed to define routing rules efficiently, called the "Expressions Router." The new design reduced the routing construction time by 75% when handling up to 10,000 routing rules, significantly decreasing from 20 seconds to 5 seconds.

Example: Exact Match

Example: Regex Match

We utilized the high-performance pest library from the Rust ecosystem to parse our DSL, with the entire grammar description being about 40 lines.

In Kong, you can add an Expressions route through the Admin API POST method:

Router Optimization

This DSL offers many convenient features, such as prefix matching (^=), suffix matching (=^), and IP address ranges in IpCidr format, allowing users to avoid expensive regular expressions. The enhanced expressive power can describe complex routing requirements in a single routing rule, reducing the number of rules needed.

The new design optimizes the order of checks and allows bypassing costly checks when appropriate. Expression routes are always evaluated in descending order of priority. Therefore, when configuring routes, you should set higher priority for more likely matches to improve efficiency: 

Example of a likely match route:

Example of an unlikely match route:

Additionally, version 3.0 introduces condition-triggered partial route reconstruction, effectively avoiding the time consumption of global route reconstruction. In scenarios with many routes, benchmark tests show that the P99 time for route reconstruction reduced from 1.5 seconds to 0.1 seconds.

For more optimizations, refer to Kong’s official documentation: Kong Documentation.

Migration Path Between Old and New Routes (New Feature in Version 3.7)

In the latest 3.7 version of Kong Gateway, the routing system has been further enhanced with a key feature: migration support for Expressions routes, allowing customers to run both traditional JSON-based routes and new Expressions routes in tandem.

Youtube thumbnail

Kong Gateway now supports configuring both JSON and Expressions routes in a single control plane, enabling teams to gradually migrate routes to the Expression language based on business needs. Comprehensive GUI support is also provided, with syntax highlighting and auto-completion.

Youtube thumbnail

This update ensures users can smoothly transition from the Traditional routing system to the new Expressions routing system without service interruption or complex operations. For those still using Traditional routing methods, we strongly recommend upgrading to the new Expressions routes for a more efficient and flexible routing management experience.

Shared the Same Codebase for Front-end and Backend

An interesting technical highlight is developing a resty-router library on the backend, invoking Rust implementations through FFI, and integrating it into OpenResty’s backend ecosystem.

Using WebAssembly (WASM) via wasm-bindgen and wasm-pack, we added macros in the Rust code to enable the core functions used in modern browsers. This allowed us to encapsulate the core developed in Rust into a fully-typed TypeScript codebase, and achieve complex features like interactive editors and playgrounds after integration with Vue components.

Example of frontend WASM interface:

Example of backend FFI interface:

Thanks to the common library used by both the frontend and backend, users can intuitively write Expressions with syntax highlighting and auto-completion in the browser and test and verify routing rules in the playground. The frontend UI runs the same code in the browser as Gateway would have used during proxying, eliminating any chance of implementation mismatch and potential inconsistent behaviors. 

You may visit the Expressions Language reference page to learn more about the features of the language, as well as How to Configure Routes using Expressions to learn more about how to get started routing traffic with expressions inside Kong Gateway.

Source Code References

  • Rust Router Implementation Base Library
  • DSL Grammar Description Source Code
  • Frontend WASM Binding Rust Source Code
Kong GatewayRust

More on this topic

Videos

From Alert to Action: AI-Driven API Outage Analysis

Videos

Centralized Decentralization: Migration from Azure to Kong

See Kong in action

Accelerate deployments, reduce vulnerabilities, and gain real-time visibility. 

Get a Demo
Topics
Kong GatewayRust
Share on Social
Guanlan Dai

Recommended posts

Kong AI/MCP Gateway and Kong MCP Server Technical Breakdown

Kong Logo
EngineeringDecember 11, 2025

In the latest Kong Gateway 3.12 release , announced October 2025, specific MCP capabilities have been released: AI MCP Proxy plugin: it works as a protocol bridge, translating between MCP and HTTP so that MCP-compatible clients can either call exi

Jason Matis

How to Build a Multi-LLM AI Agent with Kong AI Gateway and LangGraph

Kong Logo
EngineeringJuly 31, 2025

In the last two parts of this series, we discussed How to Strengthen a ReAct AI Agent with Kong AI Gateway and How to Build a Single-LLM AI Agent with Kong AI Gateway and LangGraph . In this third and final part, we're going to evolve the AI Agen

Claudio Acquaviva

How to Track Service Level Objectives with Kong and OpenTelemetry

Kong Logo
EngineeringFebruary 6, 2025

In this blog post, we will explore how organizations can leverage Kong and OpenTelemetry to establish and monitor Service Level Objectives (SLOs) and manage error budgets more effectively. By tracking performance metrics and error rates against pred

Sachin Ghumbre

RAG Application with Kong AI Gateway, AWS Bedrock, Redis and LangChain

Kong Logo
EngineeringOctober 17, 2024

For the last couple of years, Retrieval-Augmented Generation (RAG) architectures have become a rising trend for AI-based applications. Generally speaking, RAG offers a solution to some of the limitations in traditional generative AI models, such as

Claudio Acquaviva

Down the Rabbit Hole: A Performance Regression Mystery

Kong Logo
EngineeringApril 15, 2024

How does Kong Engineering approach Gateway performance benchmarks? At Kong, we take the robustness and performance of our gateway product seriously, dedicating ourselves to maintaining high standards through a robust internal benchmark framework and

Qiqi Zhang

Announcing Standard Webhooks

Kong Logo
EngineeringDecember 13, 2023

We're pleased to announce the launch of Standard Webhooks!  Kong has been part of the Technical Committee of this standard with other great companies like Svix (the initiator of the project), Ngrok, Zapier, Twillio, Lob, Mux, and Supabase. This was

Vincent Le Goff

Kong Konnect EKS Marketplace Add-on for Kong Gateway Data Planes

Kong Logo
EngineeringDecember 7, 2023

Today, we’re excited to release the Kong Konnect EKS Marketplace add-on as a means to deploy your Kong Gateway dataplanes in AWS. The add-ons are a step forward in providing fully managed Kubernetes clusters. It is here to simplify the post-procurem

Danny Freese

Ready to see Kong in action?

Get a personalized walkthrough of Kong's platform tailored to your architecture, use cases, and scale requirements.

Get a Demo
Powering the API world

Increase developer productivity, security, and performance at scale with the unified platform for API management, AI gateways, service mesh, and ingress controller.

Sign up for Kong newsletter

    • Platform
    • Kong Konnect
    • Kong Gateway
    • Kong AI Gateway
    • Kong Insomnia
    • Developer Portal
    • Gateway Manager
    • Cloud Gateway
    • Get a Demo
    • Explore More
    • Open Banking API Solutions
    • API Governance Solutions
    • Istio API Gateway Integration
    • Kubernetes API Management
    • API Gateway: Build vs Buy
    • Kong vs Postman
    • Kong vs MuleSoft
    • Kong vs Apigee
    • Documentation
    • Kong Konnect Docs
    • Kong Gateway Docs
    • Kong Mesh Docs
    • Kong AI Gateway
    • Kong Insomnia Docs
    • Kong Plugin Hub
    • Open Source
    • Kong Gateway
    • Kuma
    • Insomnia
    • Kong Community
    • Company
    • About Kong
    • Customers
    • Careers
    • Press
    • Events
    • Contact
    • Pricing
  • Terms
  • Privacy
  • Trust and Compliance
  • © Kong Inc. 2026