System Overview
Unkey’s architecture consists of multiple specialized services that work together to provide API authentication, authorization, and management capabilities:Core Services
API
Primary RPC-style HTTP API for key verification and management
Frontline
Multi-tenant ingress for TLS termination and routing
Sentinel
Per-environment gateway for routing and middleware policies
Vault
Centralized encryption service for key material management
Control Plane
Deployment orchestration and workflow management
Krane
Kubernetes control agent for resource reconciliation
API Service
The API service is the primary interface for users to interact with Unkey. It exposes an authenticated RPC-style HTTP API for all CRUD operations on keys, APIs, identities, and permissions. Key responsibilities:- Key verification and authentication
- Rate limiting and usage tracking
- Key and API management operations
- Audit logging for security events
- Analytics event collection
- Panic recovery and tracing
- ClickHouse request metrics
- Structured logging with request IDs
- Error translation using fault codes
- One-minute timeout enforcement
- Request validation
- MySQL: Control plane data (keys, APIs, identities, permissions)
- Redis: Rate limiting counters and cache
- ClickHouse: Verification events and analytics (optional)
- Vault: Encryption and secret handling via RPC
- Control API: Deployment operations via RPC
7070: HTTP API2112: Prometheus metrics7946/7947: Gossip cluster (TCP/UDP)
ClickHouse is optional. When not configured, analytics writes become no-ops.
Frontline
Frontline is the multi-tenant ingress service that sits at the edge of the network. It terminates TLS connections, performs SNI routing, and forwards requests to the appropriate per-environment sentinel. Key responsibilities:- TLS termination with dynamic certificate selection
- SNI-based routing to environments
- Cross-region request forwarding
- Certificate and routing caching
- First Unkey-owned hop for inbound traffic
- Reads routing data from MySQL control plane
- Maintains short-lived caches to avoid database round trips
- Handles failover when regions are unavailable
- MySQL: Environment routing and certificate data
- Vault: Certificate retrieval via RPC
7070: HTTP7443: HTTPS9090: Prometheus metrics
Sentinel
Sentinel is the per-environment gateway that routes requests from Frontline to specific deployments and enforces middleware policies before requests reach user workloads. Key responsibilities:- Resolve deployment IDs to running instances
- Evaluate middleware policies (KeyAuth, rate limiting)
- Forward requests to selected instances
- Record request telemetry
- One sentinel per environment
- Uses deployment ID header (
X-Deployment-Id) for routing - Filters instances by region and status
- Caches deployment and instance data with stale-while-revalidate
- Gossip-based cache invalidation across sentinel nodes
- MySQL: Deployment and instance data
- ClickHouse: Request telemetry (optional)
8080: HTTP gateway9090: Prometheus metrics
Vault
Vault is Unkey’s centralized encryption service that manages data encryption keys (DEKs) and enables runtime services to encrypt/decrypt sensitive payloads without embedding key material in application code. Key responsibilities:- Issue and store DEKs per keyring
- Encrypt and decrypt payloads with DEKs
- Validate encrypted payload structure
- Re-encrypt payloads during key rotation
- KEK (Key Encryption Key): Master key for encrypting DEKs
- DEK (Data Encryption Key): Per-keyring data key for payload encryption
- Uses AES-256-GCM encryption
Liveness: Health check endpointEncrypt: Encrypt payloads with latest DEKDecrypt: Validate and decrypt payloadsReEncrypt: Rotate to latest DEK
- Encrypted DEKs stored in S3-compatible object storage
- Object path:
keyring/<ring_id>/<dek_id> LATESTpointer tracks newest DEK per keyring
- In-memory cache with 1-hour freshness
- 24-hour stale tolerance
- Up to 10,000 DEKs per instance
- S3-compatible storage: DEK persistence
8060: HTTP RPC endpoint
Control Plane
The control plane consists of two components: the Control API and Control Worker. Together they manage deployment intent, orchestration workflows, and background maintenance.Control API
Key responsibilities:- System of record for deployment intent
- Accept changes from dashboard and automation
- Persist configuration in MySQL
- Trigger worker workflows for async operations
- MySQL: Deployment configuration and state
- Restate: Workflow orchestration
- GitHub: App integration for CI/CD
8080: HTTP API9090: Prometheus metrics
Control Worker
Key responsibilities:- Execute deployment workflows
- Manage TLS certificates via ACME
- Assign and update routes
- Background maintenance jobs (quota checks, key refills)
- Deployment creation and updates
- Certificate issuance and renewal
- Custom domain provisioning
- GitHub App integration
- MySQL: Deployment state
- ClickHouse: Analytics data
- Vault: Secret handling via RPC
- Container Registry: Image push/pull
- Route53: DNS and ACME challenges
9080: Restate ingress9090: Prometheus metrics
Krane
Krane is Unkey’s in-cluster Kubernetes control agent that reconciles control plane intent into Kubernetes resources and reports actual state upstream. Key responsibilities:- Reconcile user workloads as ReplicaSets
- Reconcile sentinel infrastructure (Deployments, Services, PDBs)
- Manage Cilium network policies
- Report deployment and sentinel status
- Decrypt workload secrets via Vault
- Deployment controller: Manages user workload ReplicaSets
- Sentinel controller: Manages routing infrastructure
- Cilium controller: Manages network policies
- Resync loop: Corrects drift every minute
- Uses server-side apply for all resources
- Streaming desired state from control plane
- Kubernetes watches for actual state
- Labels all managed resources with
app.kubernetes.io/managed-by=krane
- Runs workloads with
RuntimeClassName: gvisor - Tolerates
karpenter.sh/nodepool=untrustedtaint - Topology spread across availability zones
- Control API: Deployment intent stream
- Vault: Secret decryption via RPC
- Kubernetes API: Resource management
8080: HTTP API9090: Prometheus metrics
Preflight
Preflight is the Kubernetes admission webhook that enforces platform requirements during pod creation, keeping workload manifests minimal while ensuring proper secret handling and registry access. Key responsibilities:- Inject init container and secrets wiring
- Rewrite container entrypoints to use inject binary
- Add registry pull secrets for private images
- Clean up expired pull secrets
- API server calls
/mutatewebhook - Preflight checks for
unkey.com/deployment.idlabel - Returns JSON patch to inject secrets infrastructure
- Mutated pod runs with proper credentials
- On-demand Depot tokens for
registry.depot.dev - Registry aliases for hostname rewriting
- Kubernetes keychain integration
443: Service port (maps to8443container)
Data Flow Patterns
Key Verification Flow
Deployment Creation Flow
Cache Invalidation
Unkey uses gossip-based cache invalidation to maintain consistency across distributed service instances:- API Service: Key, API, and rate limit namespace caches
- Sentinel: Deployment and instance route caches
- Frontline: Certificate and environment route caches
- Nodes subscribe to invalidation messages
- Cache changes broadcast to cluster
- Uses ordering mechanism (timestamps/Lamport clocks)
- Falls back to local-only invalidation on gossip failure
- Stale-While-Revalidate (SWR): Serve stale data while refreshing
- TTL-based: Expire after time threshold
- Event-based: Invalidate on mutation events
Technology Stack
Backend Services
Backend Services
- Language: Go 1.25+
- Build System: Bazel
- RPC Framework: Connect RPC (gRPC-compatible)
- Protocol: Protocol Buffers v3
- HTTP Framework: Chi router
- Tracing: OpenTelemetry
Data Stores
Data Stores
- Primary Database: MySQL 8.0+
- Cache & Rate Limiting: Redis 8.0+ (or Dragonfly)
- Analytics: ClickHouse 23.0+
- Object Storage: S3-compatible (MinIO, AWS S3)
- Workflow Engine: Restate
Infrastructure
Infrastructure
- Container Runtime: Docker / containerd
- Orchestration: Kubernetes 1.28+
- Isolation: gVisor (RuntimeClassName)
- Networking: Cilium CNI with network policies
- Node Provisioning: Karpenter
- Service Mesh: Native Kubernetes Services
Observability
Observability
- Metrics: Prometheus with Grafana
- Tracing: OpenTelemetry to OTLP endpoint
- Logs: Structured JSON with request IDs
- Profiling: pprof endpoints (authenticated)
- Alerting: Alertmanager with incident.io integration
Security
Security
- Encryption: AES-256-GCM for data at rest
- TLS: Automatic certificate management via cert-manager
- ACME: Let’s Encrypt with Route53 DNS validation
- Secrets: External Secrets Operator with AWS Secrets Manager
- Network Policies: Cilium L3/L4/L7 policies
High Availability Design
Unkey’s architecture is designed for high availability through several mechanisms:Stateless Services
All core services (API, Frontline, Sentinel) are stateless and can scale horizontally:- Multiple replicas per service
- Load balanced across availability zones
- No shared local state between instances
- Graceful shutdown with connection draining
Data Layer Redundancy
- MySQL: Primary/replica configuration with automatic failover
- Redis: Sentinel mode or cluster for HA
- ClickHouse: Replicated tables across shards
- S3: Cross-region replication for vault storage
Regional Isolation
- Services deployed in multiple geographic regions
- Frontline routes to nearest available region
- Regional failure triggers automatic cross-region routing
- Each region operates independently
Circuit Breakers
All service-to-service communication includes:- Timeout enforcement (default 1 minute)
- Retry with exponential backoff
- Circuit breaker patterns for failing dependencies
- Graceful degradation when optional services unavailable
Deployment Architecture
Unkey supports multiple deployment models:Unkey-Managed Cloud
- Fully managed by Unkey team
- Multi-tenant infrastructure
- Global edge deployment
- Automated scaling and updates
Customer-Managed (Self-Hosted)
- Deploy in your own infrastructure
- Full control over data and resources
- Kubernetes-based deployment
- Helm charts provided
Performance Characteristics
API Latency
P50: <10ms
P99: <50ms
Measured from edge to response
P99: <50ms
Measured from edge to response
Throughput
Per Instance: 10,000+ req/s
Horizontally Scalable: Add replicas for capacity
Horizontally Scalable: Add replicas for capacity
Cache Hit Rate
Key Verification: >95%
Route Resolution: >99%
With proper TTL configuration
Route Resolution: >99%
With proper TTL configuration
Availability
Data Plane: 99.99%
Control Plane: 99.9%
Independent availability zones
Control Plane: 99.9%
Independent availability zones
Related Documentation
- Deployments - Regional deployment model and infrastructure
- Self-Hosting - Run Unkey in your own environment
- Configuration Reference - Service configuration options