Backend Router Deployment
The backend router handles HTTP API requests and routes them to appropriate services. Location:backend/deployment.yml
- Resource Management: CPU requests of 300m with limits up to 2000m for handling variable load
- Secret Management: All sensitive configuration loaded from
exchange-router-secret - Single Replica: Runs one instance (scaled via HPA when needed)
- Port Configuration: Exposes container port 8080
WebSocket Stream Deployment
Handles real-time WebSocket connections for live market data streaming. Location:websocket/deployment.yml
- ConfigMap Configuration: Non-sensitive config from
exchange-ws-stream-config - WebSocket Port: Listens on port 4000 for WebSocket connections
- Redis Integration: Connects to Redis for pub/sub messaging
- Stateless Design: Single replica for WebSocket handling
PostgreSQL Database Deployment
Stateful deployment for the PostgreSQL database with persistent storage. Location:postgres-db/deployment.yml
- Persistent Storage: Mounts PVC for data persistence across pod restarts
- SubPath Mount: Uses
postgres-datasubPath to isolate database files - Standard Image: Uses official PostgreSQL 12.2 image
- Configuration: Database credentials loaded from ConfigMap
- Single Instance: One replica for database consistency
Redis Deployment
In-memory data store for caching and pub/sub messaging. Location:redis/deployment.yml
- Alpine Image: Lightweight Redis 6.2 Alpine variant
- Persistent Storage: Data persists across restarts via PVC
- Standard Port: Exposes Redis on default port 6379
- SubPath Mount: Isolates Redis data in
redis-datasubdirectory
Engine Deployment
Core matching engine that processes order book operations. Location:engine/deployment.yml
- In-Memory Processing: No persistent storage (stateless)
- Database Connection: Connects to PostgreSQL for order persistence
- Redis Integration: Uses Redis for pub/sub and caching
- ConfigMap Configuration: Database and Redis URLs from ConfigMap
Database Processor Deployment
Asynchronous worker that processes database operations from Redis queue. Location:db-processor/deployment.yml
- Queue Worker: Processes messages from Redis queue
- Database Writer: Writes processed data to PostgreSQL
- Stateless Design: No local storage requirements
- ConfigMap Configuration: Connection strings from ConfigMap
Common Deployment Patterns
Labels and Selectors
All deployments use consistent labeling:app: <service-name>- Used for pod selection and service routing- Labels match between
selector.matchLabelsandtemplate.metadata.labels
Environment Configuration
Two approaches used across deployments:-
Secrets (backend router):
-
ConfigMaps (other services):
Replica Strategy
All deployments currently run withreplicas: 1:
- Backend router uses HPA for auto-scaling
- Stateful services (database, Redis) require single instance
- Other services can be manually scaled if needed
Deployment Operations
Apply a Deployment
Check Deployment Status
Scale a Deployment
Update Container Image
View Deployment Logs
Best Practices
- Resource Limits: Define CPU/memory requests and limits for predictable scheduling
- Health Checks: Add readiness and liveness probes for production deployments
- Image Tags: Use specific commit SHAs instead of
latestfor reproducibility - Configuration Management: Use ConfigMaps for non-sensitive data, Secrets for sensitive data
- Rolling Updates: Default strategy ensures zero-downtime deployments
- Persistent Data: Use PVCs for stateful services (database, cache)

