Gateway
Environment-scoped deployment gateway service
Location: go/apps/gateway/
CLI Command: unkey run gateway
What It Does
Gateway is an environment-scoped HTTP proxy service that receives requests from Ingress and routes them to the appropriate deployment instance.
Each environment has its own Gateway instance(s), and a single Gateway handles all deployments within that environment.
Gateway handles three main responsibilities:
- Deployment Validation: Ensures the requested deployment belongs to this Gateway's environment
- Instance Selection: Selects a healthy running instance for the deployment in the current region
- Request Proxying: Forwards the request to the selected instance and returns the response
Architecture
Environment-Scoped Design
Gateway is an environment-scoped service, meaning:
- Each environment (e.g., production, staging, dev) has its own Gateway instance(s)
- A single Gateway handles all deployments within its environment
- Ingress passes the
X-Deployment-IDheader to specify which deployment to route to - Gateway validates that the deployment belongs to its configured environment
Request Flow
How It Works
Gateway validates that the requested deployment belongs to its configured environment, then selects a healthy instance to proxy the request to.
Security Note: Deployments from wrong environments are masked as "not found" rather than "forbidden" to avoid leaking information about deployments in other environments.
Database Schema
Gateway uses the following tables:
Error Handling
Gateway uses structured error codes for consistent error handling:
Error Codes
Error Middleware
Gateway is not user-facing (only Ingress calls it), so it always returns JSON errors:
Ingress receives these errors and can decide how to present them to end users.
Configuration
Gateway is configured per-environment:
Key Configuration: EnvironmentID is required and determines which deployments this Gateway can serve.
Observability
Gateway uses structured logging and metrics for monitoring.