Environment Variables for Configuration
Context
Microservices are being adopted. Configuration values are hard-coded. Configurations don't change at runtime very often.
Problem
- Reconfiguration of a microservice instance requires rebuilding the deployment artifact.
- The rebuild of deployment artifacts to reconfigure a service instance takes time and resources
- Managing different all the deployment environments becomes complex
Solution
Configure the microservice instances via environment variables.
Those environment variables are read once at the start of the deployment artifact. Before starting the microservice, the configuration can be adjussted by using environment variables.
It is a good practice to document all required environment variables.
Maturity
Proposed, to be evaluated.
Sources of Evidence
L3:
- Context: example tech stack of Backtory
- Spring boot with embedded application server
- uses OS's env variables for configuration
- Spring Cloud context + cpmfog server tp separate config from source code
L12:
- Context: example tech stack of Backtory
- Spring boot with embedded application server
- uses OS's env variables for configuration
- Spring Cloud context + cpmfog server tp separate config from source code
L31:
- Context Migration practice MP13: Containerize services
- Good practice to add env variables as high priority source for populating software configuration
- Config keys can have different values in different environments
- e.g. DB URL, credentials
- injected during container creation phase
- List of required env variables => good practice to make stakeholders aware of those changing variables
Interview A:
- Inconsistency with environment variables caused crashing services
- forgotten to configure
- not required anymore since reasons