Skip to main content

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

VariableServiceSourceTypeRequiredDefault
SERVER_ADDRBackend RouterSecretstringYes-
DATABASE_URLBackend, Engine, DB ProcessorSecret/ConfigMapstringYes-
REDIS_URLBackend, Engine, DB Processor, WebSocketSecret/ConfigMapstringYes-
WS_STREAM_URLWebSocketConfigMapstringYes-
POSTGRES_USERPostgreSQLConfigMapstringYes-
POSTGRES_PASSWORDPostgreSQLConfigMapstringYes-
POSTGRES_DBPostgreSQLConfigMapstringYes-

Service-Specific Variables

Backend Router Service

Deployment: exchange-router-deployment
Source 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
env:
  - name: SERVER_ADDR
    valueFrom:
      secretKeyRef:
        name: exchange-router-secret
        key: server_addr

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
env:
  - name: DATABASE_URL
    valueFrom:
      secretKeyRef:
        name: exchange-router-secret
        key: database_url

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
env:
  - name: REDIS_URL
    valueFrom:
      secretKeyRef:
        name: exchange-router-secret
        key: redis_url

PostgreSQL Database Service

Deployment: exchange-postgres-deployment
Source 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
env:
  - name: POSTGRES_USER
    valueFrom:
      configMapKeyRef:
        name: exchange-postgres-config
        key: POSTGRES_USER
This variable should be moved to a Secret for production environments. Storing credentials in ConfigMaps is not secure.

POSTGRES_PASSWORD

  • Description: Password for the PostgreSQL superuser
  • Type: String
  • Source: ConfigMap (exchange-postgres-config)
  • Required: Yes
  • Default: root
  • Usage: Authenticates the database superuser
env:
  - name: POSTGRES_PASSWORD
    valueFrom:
      configMapKeyRef:
        name: exchange-postgres-config
        key: POSTGRES_PASSWORD
This password is stored in plain text in a ConfigMap. Migrate to a Secret immediately for production use.

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
env:
  - name: POSTGRES_DB
    valueFrom:
      configMapKeyRef:
        name: exchange-postgres-config
        key: POSTGRES_DB

Engine Service

Deployment: exchange-engine-deployment
Source 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
env:
  - name: DATABASE_URL
    valueFrom:
      configMapKeyRef:
        name: exchange-engine-config
        key: database_url

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
env:
  - name: REDIS_URL
    valueFrom:
      configMapKeyRef:
        name: exchange-engine-config
        key: redis_url

Database Processor Service

Deployment: exchange-db-processor-deployment
Source 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
env:
  - name: DATABASE_URL
    valueFrom:
      configMapKeyRef:
        name: exchange-db-processor-config
        key: database_url

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
env:
  - name: REDIS_URL
    valueFrom:
      configMapKeyRef:
        name: exchange-db-processor-config
        key: redis_url

WebSocket Service

Deployment: exchange-ws-stream-deployment
Source 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
env:
  - name: WS_STREAM_URL
    valueFrom:
      configMapKeyRef:
        name: exchange-ws-stream-config
        key: ws_stream_url

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
env:
  - name: REDIS_URL
    valueFrom:
      configMapKeyRef:
        name: exchange-ws-stream-config
        key: redis_url

Redis Service

Deployment: exchange-redis-deployment
Source 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:
postgres://[username]:[password]@[host]:[port]/[database]
Example:
postgres://root:[email protected]:80/exchange-db
Components:
  • username: Database user (default: root)
  • password: User password (default: root)
  • host: Service hostname using Kubernetes DNS
  • port: Service port (PostgreSQL service exposes port 80, maps to container port 5432)
  • database: Target database name (default: exchange-db)

Redis Connection String

Format:
redis://[host]:[port]
Example:
redis://exchange-redis-service.default.svc.cluster.local:80
Components:
  • host: Service hostname using Kubernetes DNS
  • port: Service port (Redis service exposes port 80, maps to container port 6379)

Service Discovery

All services use Kubernetes DNS for service discovery: Pattern:
<service-name>.<namespace>.svc.cluster.local:<port>
Examples:
  • exchange-postgres-service.default.svc.cluster.local:80
  • exchange-redis-service.default.svc.cluster.local:80

Port Mapping

ServiceContainer PortService PortProtocol
Backend Router808080HTTP
PostgreSQL543280PostgreSQL
Redis637980Redis
WebSocket400080WebSocket

Configuration Examples

Local Development

For local development outside Kubernetes:
# Backend Router
export SERVER_ADDR="localhost:8080"
export DATABASE_URL="postgres://root:root@localhost:5432/exchange-db"
export REDIS_URL="redis://localhost:6379"

# Engine
export DATABASE_URL="postgres://root:root@localhost:5432/exchange-db"
export REDIS_URL="redis://localhost:6379"

# WebSocket
export WS_STREAM_URL="0.0.0.0:4000"
export REDIS_URL="redis://localhost:6379"

# PostgreSQL (if running manually)
export POSTGRES_USER="root"
export POSTGRES_PASSWORD="root"
export POSTGRES_DB="exchange-db"

Docker Compose

Equivalent Docker Compose configuration:
services:
  backend:
    environment:
      SERVER_ADDR: "0.0.0.0:8080"
      DATABASE_URL: "postgres://root:root@postgres:5432/exchange-db"
      REDIS_URL: "redis://redis:6379"

  engine:
    environment:
      DATABASE_URL: "postgres://root:root@postgres:5432/exchange-db"
      REDIS_URL: "redis://redis:6379"

  websocket:
    environment:
      WS_STREAM_URL: "0.0.0.0:4000"
      REDIS_URL: "redis://redis:6379"

  postgres:
    environment:
      POSTGRES_USER: "root"
      POSTGRES_PASSWORD: "root"
      POSTGRES_DB: "exchange-db"

Production Overrides

For production, use Secrets for sensitive variables:
env:
  # From Secret
  - name: DATABASE_URL
    valueFrom:
      secretKeyRef:
        name: exchange-production-secret
        key: database_url
  
  # From ConfigMap (non-sensitive)
  - name: WS_STREAM_URL
    valueFrom:
      configMapKeyRef:
        name: exchange-production-config
        key: ws_stream_url

Required vs Optional Variables

Required Variables

These variables must be set for services to function: Backend Router:
  • SERVER_ADDR
  • DATABASE_URL
  • REDIS_URL
PostgreSQL:
  • POSTGRES_USER
  • POSTGRES_PASSWORD
  • POSTGRES_DB
Engine:
  • DATABASE_URL
  • REDIS_URL
DB Processor:
  • DATABASE_URL
  • REDIS_URL
WebSocket:
  • WS_STREAM_URL
  • REDIS_URL

Optional Variables

Currently, no optional environment variables are configured in the deployments.

Best Practices

Security

  1. Use Secrets for Credentials
    # Good: Using Secret
    - name: DATABASE_URL
      valueFrom:
        secretKeyRef:
          name: exchange-secret
          key: database_url
    
    # Bad: Hardcoded value
    - name: DATABASE_URL
      value: "postgres://root:root@..."
    
  2. 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
  3. Avoid Hardcoding
    • Never hardcode values directly in deployment YAML
    • Always use ConfigMaps or Secrets

Naming Conventions

  1. Use SCREAMING_SNAKE_CASE
    • DATABASE_URL
    • database_url
  2. Be Descriptive
    • WS_STREAM_URL ✓ (clear abbreviation)
    • URL ✗ (too vague)
  3. Follow Application Conventions
    • Match variable names expected by the application code
    • Document any transformations (e.g., database_url in ConfigMap → DATABASE_URL in container)

Documentation

  1. Document All Variables
    • Purpose and usage
    • Expected format and examples
    • Source (ConfigMap or Secret)
    • Whether required or optional
  2. Version Control
    • Track variable changes in Git
    • Use meaningful commit messages when updating configurations
  3. 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:
# Get pod name
kubectl get pods -l app=exchange-router

# Check all environment variables
kubectl exec <pod-name> -- env

# Check specific variable
kubectl exec <pod-name> -- env | grep DATABASE_URL

ConfigMap or Secret Missing

Verify the source exists:
# Check ConfigMaps
kubectl get configmap exchange-engine-config

# Check Secrets
kubectl get secret exchange-router-secret

# View ConfigMap data
kubectl describe configmap exchange-engine-config

Connection Issues

Validate URL formats:
# Test PostgreSQL connection
kubectl exec <pod-name> -- psql $DATABASE_URL -c "SELECT 1"

# Test Redis connection
kubectl exec <pod-name> -- redis-cli -u $REDIS_URL ping

Service Discovery Problems

Verify DNS resolution:
# Check if service exists
kubectl get service exchange-postgres-service

# Test DNS from pod
kubectl exec <pod-name> -- nslookup exchange-postgres-service.default.svc.cluster.local

# Test connectivity
kubectl exec <pod-name> -- nc -zv exchange-postgres-service 80

Restart Pods After Config Changes

Environment variables are loaded at container startup:
# Restart deployment
kubectl rollout restart deployment exchange-router-deployment

# Or delete pods to force recreation
kubectl delete pod -l app=exchange-router

Build docs developers (and LLMs) love