Environment file setup
The platform uses.env files for configuration. Two example files are provided:
- Project root -
.env.examplefor local development - Docker directory -
docker/.env.examplefor containerized deployment
Local development
Docker deployment
Configuration categories
Database configuration
PostgreSQL database connection settings.PostgreSQL username for authentication.Default:
rootPostgreSQL password for authentication.Default:
rootPostgreSQL server hostname.Local development:
localhostDocker deployment: exchange-postgresPostgreSQL server port.Default:
5000 (local) or 5432 (Docker)PostgreSQL database name.Default:
exchange-dbMaximum number of connections in the database connection pool.Adjust based on expected load and server capacity.
Complete PostgreSQL connection string used by SQLx.Format:
postgres://user:password@host:port/databaseThis variable uses variable substitution from the other
PG__* variables.Docker-specific database variables
These variables are used in Docker Compose for PostgreSQL container setup:PostgreSQL container hostname.
PostgreSQL database name (Docker container).
PostgreSQL username (Docker container).
PostgreSQL password (Docker container).
PostgreSQL internal port in Docker.
Redis configuration
Redis is used for pub/sub messaging and caching.Complete Redis connection URL.Local development:
redis://localhost:6380Docker deployment: redis://exchange-redis:6379Service configuration
Router (REST API) server bind address and port.Format:
host:portWebSocket streaming service bind address and port.Format:
host:portBuild-time configuration
Controls SQLx compile-time query verification.Values:
true- Skip compile-time query verification (faster builds)false- Verify queries against database at compile time
In Dockerfiles, this is set to
true to enable offline builds without database access.Rust logging level.Values:
trace, debug, info, warn, errorConfiguration examples
Local development
.env
Docker deployment
docker/.env
Production deployment
.env
Environment validation
The Exchange platform uses theconfik crate for configuration management with automatic validation.
If required environment variables are missing, services will fail to start with clear error messages.
Security considerations
- Never commit
.envfiles to version control - Use strong passwords in production (minimum 20 characters)
- Rotate credentials regularly
- Use secrets management tools (AWS Secrets Manager, HashiCorp Vault, etc.)
- Restrict database access to application servers only
- Enable SSL/TLS for database and Redis connections in production
SQLx offline mode
The platform uses SQLx’s offline mode for Docker builds:Preparing the query cache
If you modify database queries, regenerate the query cache:.sqlx directory.
Building with offline mode
.env:
PostgreSQL tuning
Max connections
In Docker Compose, PostgreSQL is configured with:- Number of service instances
PG__POOL_MAX_SIZEsetting- Expected concurrent load
max_connections >= (number_of_services × pool_size) + 10
Shared memory
Redis tuning
Persistence settings
--save 20 1- Save to disk if at least 1 key changed in 20 seconds--loglevel warning- Reduce log verbosity
Troubleshooting
Database connection fails
Verify your configuration:Redis connection fails
Environment variables not loading
Ensure you’re loading the.env file:
Next steps
- Learn about local development
- Deploy with Docker
- Set up production deployment