Skip to content
mentoor

Topic 5 of 5 · 5 min read

Environment config and feature flags

Goal: Identify a config change in an agent's diff that behaves differently in production and decide how to make it safe.

A config change is code that behaves differently depending on where it runs: ask what this value will be in production, not on your machine.

Check yourself · 1 of 3

A diff changes a setting's default from false to true. Why does this need care?

Choose one answer

Why it matters

Config looks boring, so it gets skimmed. But a changed default, a timeout, a URL or a flag decides how the live system behaves. An agent sees only the files in front of it. It cannot know your production values, so it guesses, or it hard-codes what it sees in the dev setup. The Twelve-Factor guide puts it simply: config that varies between deploys belongs in the environment, not in the code.

What to check

  1. Changed defaults. A default of false becoming true, a retry count rising, a timeout dropping. Defaults apply wherever nobody overrode the value, and production is often that place.
  2. Hard-coded environment values. A production URL in test code, so tests hit real systems. Or a localhost URL in code that ships.
  3. Secrets in config files. Real keys in config.yaml or an example file. They belong in a secret store, with an empty placeholder in the example.
  4. Differences between environments. Does the value exist in staging and production, or only in the developer's .env? A new required variable missing in production fails at startup, or worse, silently uses a fallback.
  5. Feature flags. A flag that defaults on exposes unfinished work to everyone. A flag that should be temporary needs an owner and a removal date, or dead branches pile up.
  6. Safe failure. If the variable is missing, should the app refuse to start, or run with a risky default? Prefer to fail loudly.

Before and after

- DEBUG = env("DEBUG", "false")
+ DEBUG = env("DEBUG", "true")
+ PAYMENTS_URL = "https://api.payments.example.com"

The agent made debug mode the default so the local run shows errors, and wrote the production payments URL directly. In production, an unset variable now turns on debug output, and a test run would call the live payment service. The fix keeps false as the default, reads the URL from the environment and fails at startup when it is absent.

What goes wrong

  • A feature flag set to on in the diff, merged before the feature is ready.
  • A new variable added to code and to .env.example, but never to the production deploy.
  • Staging and production drift apart because nobody lists the differences.

Examples

The debug default

An agent changes a default to DEBUG=true so local errors are visible. Production does not set DEBUG, so the stack traces and internal settings now appear in public error pages. The default must stay safe, with local overrides in the developer's own .env.

The flag left on

A new checkout page ships behind NEW_CHECKOUT but the diff sets it to true in the base config to test it. Every customer sees the half-finished page after deploy. Flags for unfinished work default to off.

Key points

  • Ask what each changed value will be in production, not on the developer's machine.
  • A changed default applies everywhere nobody overrides it, which is often production.
  • Keep environment-specific URLs and keys in the environment, not in code or committed files.
  • A new required variable must be added to every deploy target before merging.
  • Give each feature flag a safe default, an owner and a removal plan.

Common mistakes

  • Skimming config files because there is no logic in them.
  • Testing only with the developer's .env and never with production-like values.
  • Hard-coding a production URL or key because it was the quickest way to make a test pass.
  • Adding a feature flag with no safe default and no plan to remove it.

Check yourself · 2 of 3

Where should a production API key live?

Choose one answer

Check yourself · 3 of 3

A new feature flag is added for unfinished work. What default is safest?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic