Environment Configuration Management
Confiance : medium
environment-configurationconfiguration-driftvercel-deploymentdevelopment-production-paritysecret-management
Systematic approach to managing application configuration across development, staging, and production environments, with emphasis on preventing configuration drift and ensuring consistent behavior across deployments.
Configuration Drift Patterns
Service Integration Mismatches
Common scenario where development and production environments use different service configurations:
- Development: Local database, test API keys, development service endpoints
- Production: Cloud database, production API keys, live service endpoints
- Drift Risk: Service project IDs, slugs, or regional endpoints differing between environments
Regional Service Configuration
Many SaaS services operate multiple regional instances that must be consistently configured:
- Sentry: EU region (
de.sentry.io) vs US region (sentry.io) - AWS: Regional endpoints and data residency requirements
- Database services: Geographic distribution and latency considerations
Vercel Environment Management
Environment Variable Hierarchy
Vercel applies environment variables in specific precedence order:
- Preview/Production environment-specific variables
- Branch-specific environment variables
- Global environment variables
- Local
.env.localfiles (development only)
Configuration Validation
Implement startup validation to catch configuration issues early:
// lib/config-validation.ts
const requiredEnvVars = [
'DATABASE_URL',
'SENTRY_DSN',
'SENTRY_ORG',
'SENTRY_PROJECT',
'EASYBEER_API_AUTH'
];
export function validateConfiguration() {
const missing = requiredEnvVars.filter(key => !process.env[key]);
if (missing.length > 0) {
throw new Error(`Missing required environment variables: ${missing.join(', ')}`);
}
// Additional validation for format/values
if (!process.env.DATABASE_URL?.startsWith('postgresql://')) {
throw new Error('Invalid DATABASE_URL format');
}
}
Development-Production Parity
Database Configuration
Ensure database schemas and connection patterns match:
- Schema migrations: Applied consistently across environments
- Connection pooling: Similar configuration to catch pool exhaustion issues
- Feature flags: Consistent state to avoid behavioral differences
External Service Configuration
- API endpoints: Use consistent service tiers and regions
- Authentication: Validate token scopes match required permissions
- Rate limits: Configure development limits to simulate production constraints
Deployment Automation
- Infrastructure as Code: Terraform or similar for reproducible environments
- Configuration templates: Generate environment-specific configs from templates
- Validation pipelines: Automated configuration testing before deployment
Secret Management Patterns
Rotation Strategy
- API keys: Regular rotation with overlap periods for zero-downtime updates
- Database credentials: Coordinated rotation across application instances
- Service tokens: Automated rotation where supported by provider APIs
Scope Management
- Principle of least privilege: Grant minimum required permissions
- Service-specific tokens: Separate tokens for different integrations
- Environment isolation: Production secrets never shared with development
Configuration Testing
Smoke Tests
Automated validation that configuration enables basic functionality:
// scripts/config-smoke-test.ts
export async function testConfiguration() {
// Test database connectivity
await testDatabaseConnection();
// Test external service APIs
await testSentryAPI();
await testEasyBeerAPI();
// Validate configuration consistency
await validateServiceRegions();
}
Integration Test Environment
- Staging environment: Mirror of production configuration with test data
- Configuration drift detection: Automated comparison between environments
- Deployment testing: Validate configuration changes before production deployment
Debugging Configuration Issues
Configuration Audit Trail
- Change tracking: Log all configuration changes with timestamps and authors
- Rollback capability: Maintain previous configuration versions for quick rollback
- Access monitoring: Track who accessed which configuration values when
Runtime Configuration Inspection
- Health check endpoints: Expose non-sensitive configuration for debugging
- Configuration validation endpoints: Test configuration without side effects
- Environment comparison tools: Compare active configuration across environments
Best Practices
Configuration as Code
- Version control: Store configuration templates in git
- Review process: Configuration changes require peer review
- Automated deployment: Configuration updates through CI/CD pipelines
Documentation
- Configuration catalog: Document purpose and format of each variable
- Dependency mapping: Track which services depend on which configuration
- Troubleshooting guides: Common configuration issues and solutions
Monitoring
- Configuration drift alerts: Notify when environments diverge
- Service health monitoring: Track external service connectivity and performance
- Configuration usage tracking: Monitor which configuration values are actually used
See also
- production-debugging
- sentry-integration
- Vercel Deployment
- Secret Management Patterns