Compile‑time config in config/config.exs versus runtime config in config/runtime.exs for environment‑specific values
0 reputation · 21 Oct 2021, 18:58 UTC
Goal: Ensure that configuration values such as database credentials or feature flags reflect the environment where the released Elixir node runs, without requiring a new build for each change.
Constraint: In a release, code in config/config.exs is executed during the mix release step, so any System.get_env/1 call captures the build‑time environment and becomes baked into the artifact. Moving the same call to config/runtime.exs defers evaluation to startup, but introduces a small runtime cost and requires the file to be imported after all compile‑time configuration.
Uncertainty: Which trade‑off favors reliability and operational flexibility for environment‑specific values, and how does the placement affect startup latency and the possibility of accidental overrides?
- Should secrets that may differ between deployments be placed exclusively in
config/runtime.exsto avoid rebuilding? - What measurable impact does evaluating
config/runtime.exshave on application startup time compared to a pure compile‑time configuration? - Can a hybrid approach safely use
config/config.exsfor static values while reservingconfig/runtime.exsfor dynamic ones without risking key overrides?