Yesterday I wrote about enabling IPv6 in my side project. Today I didn't just talk about it — I built it. And the smartest call I made wasn't flipping a single switch; it was wrapping IPv4 support behind a feature flag, giving it a gentle sunset instead of a sudden death. If you've ever wondered how to retire old code, phase out legacy protocols, or ship breaking changes without breaking your users — this one's for you.

🧩 What Even Is a Feature Flag?

At its simplest: a conditional that lets you toggle behaviour at runtime without rewriting code or redeploying. No #ifdef hacks, no recompiling. Just a gatekeeper.

For my IPv4 → IPv6 shift, it looks roughly like this:

if featureFlags.Enabled("enable-ipv4") { // bind to 0.0.0.0, handle legacy connections } else { // only listen on :: — dual-stack where needed } 

It’s not "is this feature done?" — it’s "is this feature still wanted?" And that’s the difference between launching something and retiring something safely.

🚪 Why Exit Strategies Matter More Than Launch Strategies

We love talking about shipping new things. We barely talk about removing old ones. But every piece of code you write will eventually need to leave the codebase. Without a plan, that code becomes technical debt that haunts you for years.

A good exit strategy answers three questions:

  1. When will we turn it off for good? — Set a date or usage threshold
  2. How will users know? — Warnings, logs, communications
  3. What happens if we're wrong? — A rollback path that doesn't mean reverting the whole world

Feature flags are the perfect implementation of that third answer. They turn "oh no I broke everything" from a full revert-and-panic situation into "flip one switch while I fix it".

📋 My IPv4 Exit Plan (Real-World Example)

Here's exactly what I'm doing, step-by-step, because concrete examples beat theory:

Phase Action Timeline
✅ Done Add enable-ipv4 flag, default = true Day 1
⏳ Next 2 weeks Log a warning when someone connects via IPv4 Day 2–14
⏳ Week 3 Flip default = false; keep flag available Day 15
⏳ Month 2 Remove flag entirely + clean up old code ~60 days from now

The golden rule: Keep the ability to turn it back on long enough to sleep well. Remove it only when you're certain nobody needs it anymore.

⚠️ The Hidden Traps Nobody Warns You About

Three lessons I've learned the hard way:

1. Flags are NOT permanent code

Every flag you add is debt you must pay back. If you forget to remove it, you'll eventually have a codebase full of legacy_auth_v2_deprecated_final_true flags that nobody dares touch. Treat every flag as temporary. Write the removal ticket the moment you create the flag.

2. Two types of flags — don't mix them

  • Release flags — Hide unfinished work, removed after launch
  • Experiment/operational flags — Control behaviour for users or environments, temporary by design

My IPv4 flag? It's a sunset flag — a special kind that controls removal rather than introduction. Still needs removing. Still needs a date.

3. Don't gate behaviour that changes data

If your old path writes one format and the new path writes another, a toggle means you can get mixed data. My IPv4/IPv6 change is purely about transport — safe to toggle. If behaviour changes your data schema? You need migrations first. Flags don't fix bad data transitions.

🧠 The Mental Shift

We think in terms of versions and deployments: v1, then v2, done. But the real world is messy. Users upgrade slowly. Bite-sized edge cases emerge only after traffic hits. Feature flags let you say:

"This new world is ready. We're living there now. But if anything goes wrong, the old door stays unlocked — just for a little while longer."

That's not lack of confidence. That's engineering maturity.

✍️ Today's Takeaway

Your code isn't done when the new feature works. It's done when you can safely retire the old one. Feature flags aren't just for launching — they're your best tool for graceful exits, deprecations, and that quiet confidence that even if you get it wrong today, you can fix it before anyone notices.

Now if you'll excuse me, I've got a feature flag to flip — and then a removal reminder to put in my calendar.