We compare the costs, latency, and engineering trade-offs of Next.js middleware routing versus dedicated Rust edge gateways.
When building high-traffic platforms, routing incoming traffic with high throughput and low cost becomes one of the most important architectural decisions. This article explores how Next.js Edge Middleware compares with dedicated Rust gateways built using Actix Web and Axum, examining latency, scalability, infrastructure costs, developer productivity, and real-world deployment strategies for modern internet-scale systems.
Modern web applications rarely struggle because of databases first.
They struggle because of traffic routing.
Every incoming request must be authenticated, localized, rate limited, routed, logged, traced, and eventually forwarded to the correct service.
At small scale, this layer is almost invisible.
At internet scale, it becomes one of the most expensive components in your infrastructure.
The question many engineering teams eventually face is:
Should routing happen inside Edge Middleware, or should we build a dedicated high-performance gateway?
This decision affects:
Infrastructure cost
Global latency
Throughput
Operational complexity
Engineering productivity
Future scalability
For years, the default answer was to place everything inside reverse proxies like NGINX or HAProxy.
Today, platforms like Next.js, Vercel, and Cloudflare Workers allow developers to execute JavaScript before requests even reach an application server.
At the same time, organizations handling millions of requests every minute increasingly deploy Rust-powered gateways using frameworks like Actix Web and Axum to maximize throughput while minimizing infrastructure cost.
This article explores both approaches, their strengths, limitations, and where each fits in a production architecture.
Before comparing technologies, it's important to understand what 100k RPS actually means.
100,000 requests every second equals:
| Metric | Value |
|---|---|
| Per Second | 100,000 |
| Per Minute | 6 Million |
| Per Hour | 360 Million |
| Per Day | 8.64 Billion |
Very few startups begin at this scale.
However, systems serving:
SaaS platforms
Banking APIs
Social media
Gaming backends
Streaming platforms
AI inference APIs
E-commerce marketplaces
can eventually reach this level during peak traffic.
At these volumes, even 1 millisecond of additional latency becomes expensive.
Saving:
2 ms
5 ms
10 ms
across billions of requests produces enormous reductions in compute costs.
Next.js Middleware executes before the request reaches pages or API routes.
Instead of running inside a traditional Node.js server, middleware executes inside an Edge Runtime, allowing request processing closer to end users.
Typical middleware tasks include:
Authentication
Authorization
URL rewrites
Redirects
Locale detection
Cookie inspection
Security headers
A/B testing
Request enrichment
Middleware executes before routing resolution, making it ideal for lightweight request handling. Recent versions of Next.js also support a Node.js runtime option for middleware, though Edge remains the default execution model. oai_citation:0‡Next.js
Unlike a traditional server process, Edge Middleware executes inside lightweight runtime isolates.
Instead of:
Incoming Request
↓
Node Server
↓
Application
the flow becomes:
Incoming Request
↓
Edge POP
↓
Middleware
↓
Destination
This architecture dramatically reduces latency for users located far from your origin server.
Because middleware executes geographically closer to users, it is especially effective for:
Redirect decisions
Localization
Cookie parsing
Session validation
Authentication tokens
Simple routing logic
The tradeoff is that Edge runtimes intentionally expose only a subset of Node.js APIs to keep execution lightweight and portable. oai_citation:1‡Next.js
Since execution happens near users, requests avoid unnecessary round trips.
Instead of:
London
↓
Virginia
↓
Response
routing decisions happen inside European edge locations.
The improvement is especially noticeable for:
Authentication
Redirects
Country detection
Feature flags
Most frontend engineers already understand TypeScript.
Instead of introducing another language and deployment pipeline, middleware integrates directly into existing Next.js projects.
A single repository can manage:
Frontend
Middleware
API routes
without additional infrastructure.
Middleware integrates tightly with:
NextRequest
NextResponse
Rewrites
Redirects
Cookies
Headers
making routing logic concise and maintainable.
Platforms automatically deploy middleware worldwide.
Developers don't manage:
Regions
Load balancers
Geo-routing
Edge synchronization
The platform handles deployment.
Edge Middleware is intentionally optimized for lightweight request processing.
It is not a replacement for high-performance backend services.
Common limitations include:
Restricted runtime APIs
Limited execution time
Smaller memory budgets
No unrestricted filesystem access
Reduced support for native Node.js modules
Platform-specific execution constraints
These constraints encourage middleware to remain lightweight rather than becoming a full application server. oai_citation:2‡Next.js
Rust approaches the problem differently.
Instead of executing tiny request handlers at the edge, organizations deploy dedicated gateway services built specifically for performance.
Popular frameworks include:
Actix Web
Axum
Hyper
Tower
Unlike JavaScript runtimes, Rust applications compile directly into native machine code.
There is:
no garbage collector
no JIT compilation
no runtime interpreter
This gives engineers precise control over memory allocation, concurrency, and threading.
Companies increasingly adopt Rust because it combines:
Memory safety
High throughput
Low latency
Predictable performance
without sacrificing developer control.
Rust's ownership model eliminates entire classes of runtime memory errors while allowing applications to perform close to C and C++ speeds. oai_citation:3‡arXiv
Although both frameworks are production-ready, they prioritize different goals.
| Feature | Actix Web | Axum |
|---|---|---|
| Performance | Excellent | Excellent |
| Ecosystem | Mature | Rapidly Growing |
| Middleware | Native | Tower-based |
| Async Runtime | Tokio | Tokio |
| Learning Curve | Moderate | Easier |
| Flexibility | High | Very High |
Axum integrates deeply with the Tower ecosystem, enabling reusable middleware composition and service layers. oai_citation:4‡Docs.rs
One of the biggest misconceptions in backend engineering is that frameworks alone determine performance.
They don't.
Performance is a combination of:
That said, the underlying runtime still has a measurable impact.
For simple HTTP workloads, Rust frameworks consistently rank among the fastest production-ready web frameworks because they compile to native code and execute on the Tokio asynchronous runtime with minimal overhead. Independent benchmarking projects also show that Actix Web and Axum often perform nearly identically, suggesting framework choice is more about ergonomics than raw speed. oai_citation:0‡NpgsqlRest
Unlike managed runtimes that depend on garbage collection or JIT compilation, Rust applications execute as native binaries.
A request typically flows through:
TCP Socket
│
▼
Linux Kernel
│
▼
Tokio Runtime
│
▼
Hyper HTTP
│
▼
Axum / Actix
│
▼
Business Logic
Every layer is optimized for asynchronous, non-blocking execution.
Tokio schedules thousands of concurrent tasks efficiently while Hyper provides a low-overhead HTTP implementation. Axum builds on top of Hyper and Tower rather than introducing an entirely separate middleware ecosystem, keeping overhead low. oai_citation:1‡Axum
When evaluating routing layers, engineers should look beyond average latency.
Important metrics include:
| Metric | Why It Matters |
|---|---|
| Average | Overall performance |
| Median (P50) | Typical user experience |
| P95 | Heavy load behaviour |
| P99 | Worst production latency |
| Maximum | Outlier requests |
A system with:
may deliver a noticeably worse experience than one with:
Predictability matters as much as speed.
Memory usage is often ignored until infrastructure costs begin to grow.
Edge middleware generally operates within platform-defined memory budgets designed to encourage lightweight execution.
A dedicated Rust gateway, however, runs under your own operating system and infrastructure.
Advantages include:
These characteristics are a major reason Rust is increasingly adopted for networking infrastructure and high-performance services. oai_citation:2‡arXiv
CPU efficiency directly affects cloud spending.
Imagine two gateways:
Gateway A
Gateway B
If both deliver the same throughput, Gateway B allows significantly higher request density per instance before scaling out.
Rust's compiled execution model and asynchronous runtime often provide excellent CPU efficiency, especially for network-bound workloads. oai_citation:3‡NpgsqlRest
Infrastructure cost isn't only about server pricing.
It includes:
Advantages
✅ No server maintenance
✅ Automatic scaling
✅ Global deployment
✅ Zero infrastructure management
Tradeoffs
For many startups, these tradeoffs are worthwhile because they eliminate operational complexity.
Running a Rust gateway on virtual machines or Kubernetes shifts responsibility to your team.
Advantages include:
Tradeoffs include:
Illustrative architecture comparison (actual costs vary based on traffic patterns, providers, regions, cache hit rates, and business logic).
| Scale | Edge Middleware | Rust Gateway |
|---|---|---|
| Startup | Excellent | Overkill |
| 1M req/day | Excellent | Good |
| 20M req/day | Excellent | Good |
| 100M req/day | Good | Excellent |
| 1B+ req/day | Expensive | More Cost Efficient |
The key insight is that developer productivity often outweighs infrastructure savings early on, while mature high-volume platforms increasingly optimize for infrastructure efficiency.
Large organizations rarely expose application servers directly.
Instead, production traffic commonly follows an architecture similar to:
Internet
│
▼
Global CDN
│
▼
Load Balancer
│
▼
Rust Gateway Cluster
│
┌────┴────┐
▼ ▼
Auth API Router
│ │
└────┬────┘
▼
Application Services
▼
Database
Each gateway instance remains stateless, allowing horizontal scaling.
Authentication is one of the strongest use cases for Edge Middleware.
Typical flow:
User
│
▼
Edge Middleware
│
Verify JWT
│
├──── Invalid → Reject
│
▼
Rust Gateway
│
Business Logic
▼
Database
Benefits:
A Rust gateway can integrate directly with:
This enables advanced routing such as:
At high throughput, monitoring becomes mandatory.
A production gateway should expose:
Popular tooling includes:
High-scale systems should assume failures are inevitable.
Examples include:
Designing graceful degradation and retry strategies is more important than maximizing theoretical throughput.
For most organizations, the best solution is not choosing one over the other.
Instead, combine both technologies.
User
│
▼
CDN
│
▼
Next.js Edge Middleware
│
├── Locale Detection
├── Authentication
├── Redirects
├── Cookies
└── Feature Flags
│
▼
Rust Gateway
│
├── Rate Limiting
├── API Routing
├── Business Logic
├── Write Operations
├── Event Processing
└── Service Mesh
│
▼
Microservices
│
▼
Database
This approach leverages the strengths of each layer:
Edge Middleware
Rust Gateway
Choose Edge Middleware if your application primarily requires:
A dedicated Rust gateway becomes compelling when you need:
There is no universal winner.
Edge Middleware and Rust gateways solve different layers of the same problem.
Use Next.js Edge Middleware for work that benefits from global proximity to users:
Use a Rust gateway for workloads that demand maximum efficiency:
For organizations expecting rapid growth, the hybrid model provides the best balance of developer velocity, operational flexibility, and long-term infrastructure efficiency.
The most resilient architectures aren't built by forcing every request through a single technology stack—they're built by placing each responsibility in the environment where it performs best.