Request Journey
Here’s how requests flow through the gateway and why each step matters for your application.The Complete Path
*.phala.network.
SNI Routing (<1ms): Gateway extracts the hostname from the TLS handshake to determine which CVM and port to route to. No decryption of request data happens yet.
WireGuard Tunnel (<1ms): Traffic gets re-encrypted with WireGuard before forwarding to your CVM. Even after TLS termination at the gateway, your data stays encrypted until it reaches your container.
Container Processing: Inside the CVM’s trusted environment, traffic is decrypted and forwarded to your container on the specified port.
Total network overhead: approximately 2-3ms on top of your application’s response time for established connections.
How Routing Works
The gateway makes intelligent routing decisions based on URL patterns and health status.URL Pattern Routing
The URL structure tells the gateway how to handle your traffic:s for TLS passthrough when you need end-to-end encryption. Add g to enable HTTP/2 with ALPN negotiation for gRPC. For TLS passthrough use cases and security considerations, see TLS Passthrough.
Load Balancing
When you scale to multiple CVMs, the gateway automatically distributes traffic based on health and availability. Health Detection: The gateway tracks each instance using WireGuard handshakes. An instance is considered healthy if it completed a handshake within the last 5 minutes. Unhealthy instances are automatically removed from the rotation without any configuration needed from you. Instance Selection: The gateway uses a “connect top N” strategy, attempting to connect to multiple healthy instances and selecting the first one that responds successfully. This provides both load distribution and automatic failover. Session Handling: Currently there’s no session affinity. Each request may hit a different instance, so design your applications to be stateless or use external session storage like Redis. For WebSocket connections, the TCP connection stays with one instance for its lifetime, but reconnections might hit a different instance.Network Isolation
Each CVM gets complete network isolation from others and the host.CVM Boundaries
Your CVM operates in its own network segment with:- A unique WireGuard keypair generated on deployment
- An isolated IP address in the 10.0.0.0/8 range
- No routes to other CVMs on the same host
- No access to the host’s network services
Container Networking Inside CVM
Within your CVM, containers communicate normally through Docker’s bridge network:Performance Characteristics
Understanding performance helps you make architectural decisions.Latency Budget
Where latency comes from in your network stack:| Component | Latency | Can Optimize? |
|---|---|---|
| TLS handshake | 10-30ms (first connection) | Use connection pooling |
| Gateway routing | 1-2ms | No (fixed overhead) |
| WireGuard tunnel | <1ms | No (fixed overhead) |
| Your application | Variable | Yes - your code |
Throughput Capabilities
Practical limits you’ll encounter: Single connection: Limited by instance bandwidth, typically 1-10 Gbps depending on your CVM size. Concurrent connections: Each connection uses ~10-50KB of memory. A 4GB instance can handle thousands of concurrent connections. New connections/second: CPU-bound by TLS handshakes. Expect hundreds to low thousands per second depending on instance size.Scaling Strategies
Scale horizontally when you need:- More concurrent connections
- Higher new connection rate
- Automatic failover
- Maximum single-connection throughput
- Lowest possible latency
- Stateful services that can’t be distributed

