Develop for Environment Specific Configuration

There is a pattern I see often among junior/associate developers when it comes to handling environment-specific configuration. The observed pattern could be summarized as junior developers creating separate fields for development and production environments in the application, misunderstanding the need for a single environment-aware configuration, resulting in duplicated logic to handle different keys based on the environment.

An example of this in action is there will be a request to add a field in the admin area of a website to store a key for some purpose. We would typically have a dev key and a production key so depending on the environment we would use the appropriate key. The junior developer might see this and understand the request to be: “Create two fields in the admin, one for each environment”. After which they also add logic into the code base to check which environment the application is running and read the correct key. I was not clear at first about how to explain this, but I see now it comes down to understanding, or maybe not understanding environment-specific configuration. Understanding that we have multiple versions of the application (development and production), each with its databases, and so we just need to define the configuration once, in each version of the app.

It’s come up enough that I want to call it out, to help people on the path to thinking like a software engineer.

When thinking about environment-specific configuration there are some good practices to remember:

#devops