Overview
This page documents all environment variables used in the exchange platform, including their sources (ConfigMaps or Secrets), data types, and whether they are required or optional.Environment Variable Summary
| Variable | Service | Source | Type | Required | Default |
|---|---|---|---|---|---|
SERVER_ADDR | Backend Router | Secret | string | Yes | - |
DATABASE_URL | Backend, Engine, DB Processor | Secret/ConfigMap | string | Yes | - |
REDIS_URL | Backend, Engine, DB Processor, WebSocket | Secret/ConfigMap | string | Yes | - |
WS_STREAM_URL | WebSocket | ConfigMap | string | Yes | - |
POSTGRES_USER | PostgreSQL | ConfigMap | string | Yes | - |
POSTGRES_PASSWORD | PostgreSQL | ConfigMap | string | Yes | - |
POSTGRES_DB | PostgreSQL | ConfigMap | string | Yes | - |
Service-Specific Variables
Backend Router Service
Deployment:exchange-router-deploymentSource File: backend/deployment.yml:25-40
SERVER_ADDR
- Description: Server bind address and port for the backend router API
- Type: String (format:
host:port) - Source: Secret (
exchange-router-secret) - Required: Yes
- Example:
0.0.0.0:8080 - Usage: Defines where the HTTP server listens for incoming requests
DATABASE_URL
- Description: PostgreSQL database connection string
- Type: String (PostgreSQL URL format)
- Source: Secret (
exchange-router-secret) - Required: Yes
- Example:
postgres://root:[email protected]:80/exchange-db - Usage: Establishes connection to the PostgreSQL database
REDIS_URL
- Description: Redis connection string for caching and pub/sub
- Type: String (Redis URL format)
- Source: Secret (
exchange-router-secret) - Required: Yes
- Example:
redis://exchange-redis-service.default.svc.cluster.local:80 - Usage: Connects to Redis for session management, caching, and message queuing
PostgreSQL Database Service
Deployment:exchange-postgres-deploymentSource File: postgres-db/deployment.yml:20-35
POSTGRES_USER
- Description: PostgreSQL database superuser name
- Type: String
- Source: ConfigMap (
exchange-postgres-config) - Required: Yes
- Default:
root - Usage: Initial database user created during PostgreSQL initialization
POSTGRES_PASSWORD
- Description: Password for the PostgreSQL superuser
- Type: String
- Source: ConfigMap (
exchange-postgres-config) - Required: Yes
- Default:
root - Usage: Authenticates the database superuser
POSTGRES_DB
- Description: Name of the default database to create
- Type: String
- Source: ConfigMap (
exchange-postgres-config) - Required: Yes
- Default:
exchange-db - Usage: Database created automatically on first startup
Engine Service
Deployment:exchange-engine-deploymentSource File: engine/deployment.yml:18-28
DATABASE_URL
- Description: PostgreSQL connection string for the matching engine
- Type: String (PostgreSQL URL format)
- Source: ConfigMap (
exchange-engine-config) - Required: Yes
- Example:
postgres://root:[email protected]:80/exchange-db - Usage: Connects engine to database for order management and trade execution
REDIS_URL
- Description: Redis connection for order book caching and pub/sub
- Type: String (Redis URL format)
- Source: ConfigMap (
exchange-engine-config) - Required: Yes
- Example:
redis://exchange-redis-service.default.svc.cluster.local:80 - Usage: Publishes trade events and maintains in-memory order book state
Database Processor Service
Deployment:exchange-db-processor-deploymentSource File: db-processor/deployment.yml:18-28
DATABASE_URL
- Description: PostgreSQL connection for background processing
- Type: String (PostgreSQL URL format)
- Source: ConfigMap (
exchange-db-processor-config) - Required: Yes
- Example:
postgres://root:[email protected]:80/exchange-db - Usage: Processes database operations asynchronously
REDIS_URL
- Description: Redis connection for job queue processing
- Type: String (Redis URL format)
- Source: ConfigMap (
exchange-db-processor-config) - Required: Yes
- Example:
redis://exchange-redis-service.default.svc.cluster.local:80 - Usage: Consumes jobs from Redis queues for batch processing
WebSocket Service
Deployment:exchange-ws-stream-deploymentSource File: websocket/deployment.yml:20-30
WS_STREAM_URL
- Description: WebSocket server bind address and port
- Type: String (format:
host:port) - Source: ConfigMap (
exchange-ws-stream-config) - Required: Yes
- Default:
0.0.0.0:4000 - Usage: Defines where the WebSocket server listens for client connections
REDIS_URL
- Description: Redis connection for subscribing to real-time events
- Type: String (Redis URL format)
- Source: ConfigMap (
exchange-ws-stream-config) - Required: Yes
- Example:
redis://exchange-redis-service.default.svc.cluster.local:80 - Usage: Subscribes to Redis pub/sub channels for streaming trade updates to WebSocket clients
Redis Service
Deployment:exchange-redis-deploymentSource File: redis/deployment.yml The Redis service does not use any environment variables. It runs with default configuration from the
redis:6.2-alpine image.
Configuration Patterns
URL Formats
PostgreSQL Connection String
Format:username: Database user (default:root)password: User password (default:root)host: Service hostname using Kubernetes DNSport: Service port (PostgreSQL service exposes port 80, maps to container port 5432)database: Target database name (default:exchange-db)
Redis Connection String
Format:host: Service hostname using Kubernetes DNSport: Service port (Redis service exposes port 80, maps to container port 6379)
Service Discovery
All services use Kubernetes DNS for service discovery: Pattern:exchange-postgres-service.default.svc.cluster.local:80exchange-redis-service.default.svc.cluster.local:80
Port Mapping
| Service | Container Port | Service Port | Protocol |
|---|---|---|---|
| Backend Router | 8080 | 80 | HTTP |
| PostgreSQL | 5432 | 80 | PostgreSQL |
| Redis | 6379 | 80 | Redis |
| WebSocket | 4000 | 80 | WebSocket |
Configuration Examples
Local Development
For local development outside Kubernetes:Docker Compose
Equivalent Docker Compose configuration:Production Overrides
For production, use Secrets for sensitive variables:Required vs Optional Variables
Required Variables
These variables must be set for services to function: Backend Router:SERVER_ADDRDATABASE_URLREDIS_URL
POSTGRES_USERPOSTGRES_PASSWORDPOSTGRES_DB
DATABASE_URLREDIS_URL
DATABASE_URLREDIS_URL
WS_STREAM_URLREDIS_URL
Optional Variables
Currently, no optional environment variables are configured in the deployments.Best Practices
Security
-
Use Secrets for Credentials
-
Separate Sensitive from Non-Sensitive
- Store passwords, tokens, and connection strings with credentials in Secrets
- Store non-sensitive config like URLs without credentials in ConfigMaps
-
Avoid Hardcoding
- Never hardcode values directly in deployment YAML
- Always use ConfigMaps or Secrets
Naming Conventions
-
Use SCREAMING_SNAKE_CASE
DATABASE_URL✓database_url✗
-
Be Descriptive
WS_STREAM_URL✓ (clear abbreviation)URL✗ (too vague)
-
Follow Application Conventions
- Match variable names expected by the application code
- Document any transformations (e.g.,
database_urlin ConfigMap →DATABASE_URLin container)
Documentation
-
Document All Variables
- Purpose and usage
- Expected format and examples
- Source (ConfigMap or Secret)
- Whether required or optional
-
Version Control
- Track variable changes in Git
- Use meaningful commit messages when updating configurations
-
Environment Parity
- Keep development, staging, and production configurations consistent
- Use the same variable names across environments
Troubleshooting
Variable Not Set
Check if the environment variable is properly injected:ConfigMap or Secret Missing
Verify the source exists:Connection Issues
Validate URL formats:Service Discovery Problems
Verify DNS resolution:Restart Pods After Config Changes
Environment variables are loaded at container startup:Related Resources
- ConfigMaps - Detailed ConfigMap documentation
- Secrets - Secret management guide
- Kubernetes Environment Variables
- Kubernetes ConfigMap Reference
- Kubernetes Secret Reference

