Skip to content
Tech Atlas, home
Search
Esc
  • All roadmapsBrowse every learning path
  • ExploreFind a technology area
  • ProjectsGuided projects and builds
  • My AtlasYour learning dashboard
Lesson 5 of 6 · Concept · 30 min · revision 3

Schema changes, feature flags, GitOps, traffic splitting and service meshes

Master advanced continuous delivery: the expand-and-contract database migration pattern, feature flag lifecycle, pull-based GitOps reconciliation, and service mesh traffic splitting.

Contentsand lesson path

What you will learn

  • Define rollback criteria from health checks and error rates, keep schema changes backward compatible, and execute a rollback within a target time.
  • Explain pull-based GitOps delivery with Argo CD or Flux, and separate deploying code from releasing features with feature flags.

Prerequisites: Cloud Basics, Continuous Integration

01. Why it matters

Rolling, blue-green and canary rollouts all run two versions at the same time, and all of them promise a quick way back. Three things can quietly break that promise: a database change that the old version cannot handle, a feature that users see the moment its code is deployed, and a cluster whose real state no longer matches what the team thinks is deployed. This lesson covers the matching techniques: expand-and-contract schema changes, feature flags, and GitOps with weighted traffic routing.

02. Database Migrations Without Downtime: The Expand and Contract Pattern

The relational database is often the hardest part of continuous deployment. Containers can be created, destroyed and updated in seconds, but the database holds long-lived customer records and transactions that every version shares. If an engineer runs a traditional migration that renames a column (ALTER TABLE users RENAME COLUMN phone TO mobile_phone) during a rolling or blue-green rollout, the old application version (v1) starts failing as soon as it queries the old column name, and rolling back to v1 no longer works unless you also reverse the migration.

The Expand and Contract (Parallel Run) pattern spreads one schema change over three separate releases:

  • Phase 1 — Expand (Additive Migration): Add the new column or table while leaving the old schema completely intact (ALTER TABLE users ADD COLUMN mobile_phone VARCHAR(20)). Deploy an updated application version that writes data to both columns simultaneously while reading from the old column. Rolling back to the previous version stays safe, because the old column is still there and still written.

  • Phase 2 — Backfill and Switch: Run a background backfill job that copies historical data from the old column to the new one. Once every row has been copied and checked, deploy the next application version, which reads from the new column. It must keep writing both columns: if you roll back to the previous version, that version reads the old column again, so the old column has to stay up to date until the contract phase.

  • Phase 3 — Contract (Destructive Cleanup): Only after the new application release has run stably in production for a designated safety window (e.g. one week) and rollback to the pre-migration code is no longer permitted by policy, execute the destructive migration dropping the old column (ALTER TABLE users DROP COLUMN phone).

By decoupling schema expansion from schema deletion, engineering teams keep every version inside the migration window compatible with the schema, so they can roll back between adjacent releases without breaking the old code. Rolling back to a version older than the window is not covered. Expand and contract also does not remove locking: additive DDL can still lock or rewrite a table (for example CREATE INDEX without CONCURRENTLY, or adding a NOT NULL column with a default on older PostgreSQL and MySQL versions), and large backfills must be batched. Check the lock behaviour of each statement, prefer CREATE INDEX CONCURRENTLY and nullable columns, batch backfills, and set a lock_timeout on migrations.

03. Decoupling Deploy from Release: Feature Flags and Targeted Cohorts

Traditional deployment models treat code deployment and feature release as identical events: the moment binary files touch production servers, all users immediately see the new feature. If the feature causes bugs or usability issues, resolving it requires an emergency hotfix or a high-stress rollback.

Modern continuous delivery breaks this dependency using Feature Flags (Feature Toggles):

  1. Dark Launching: Code is deployed to production in a dormant state, protected by an evaluation check (if (flags.isEnabled("new_payment_flow", user))). The feature is deployed, but not released to the general public.

  2. Targeted Cohort Releases: The engineering team releases the feature incrementally: first to internal developers (user.isEmployee), then to beta testers (5% of users), then to a specific geographical region, and finally to 100% of global traffic. If an error spike is detected in the beta cohort, product managers or on-call SREs flip the flag off in a management console (LaunchDarkly, Unleash, Flipt), and the change reaches running services within seconds (depending on whether the SDK streams updates or polls for them), without deploying code or touching servers.

  3. Technical Debt and Flag Lifecycle: Feature flags introduce technical debt through branching conditionals. High-performing teams establish a strict lifecycle rule: once a feature reaches 100% rollout and remains stable for two weeks, an automated technical debt ticket is created to remove the flag check and dead code branches from the codebase.

TypeScript · Contextual feature flag evaluation with fallback error boundaries
interface UserContext {
  id: string;
  email: string;
  isBetaTester: boolean;
}

export async function getCheckoutEngine(user: UserContext) {
  // Evaluate flag against dynamic user context
  const isV2Enabled = await featureFlags.evaluate(
    "checkout_engine_v2",
    { key: user.id, custom: { isBeta: user.isBetaTester } },
    false, // Default fallback if flag service is unreachable
  );

  if (isV2Enabled) {
    return new ModernCheckoutEngineV2();
  }
  return new LegacyCheckoutEngineV1();
}

04. Declarative GitOps and Service Mesh Traffic Splitting

As deployment architectures mature, teams transition from push-based delivery pipelines (where CI runners execute kubectl apply using elevated cluster credentials) to Pull-Based GitOps (orchestrated by tools like Argo CD or Flux):

  • Git as the Single Source of Truth: The desired state of the clusters is declared in version-controlled Git repositories. People change production through pull requests, not with kubectl apply or kubectl edit; direct access is kept read-only for debugging.

  • Automated Reconciliation and Self-Healing: An in-cluster controller repeatedly compares live cluster state with the Git repository. If an engineer changes a replica count or an environment variable directly with the CLI, the controller reports the object as out of sync. Reverting it needs self-healing to be switched on: Argo CD does not undo live changes by default, but with selfHeal: true it syncs again within seconds of seeing the drift. If the drift keeps coming back, the controller waits longer between attempts (by default 2 seconds, then three times as long each time, up to 5 minutes). The Argo CD auto-sync page still says self-heal retries after "5 seconds by default", set by --self-heal-timeout-seconds; the controller's command reference lists that flag with no default, and lists the backoff flags with the defaults given above (2 seconds, a factor of 3, at most 300 seconds), which is how current releases behave. Flux corrects drift on each reconciliation interval (for example every 10 minutes). Argo CD checks Git itself every 2 to 3 minutes by default, or sooner with a webhook.

  • Traffic Splitting via Service Meshes and Gateway API: Advanced canary rollouts need to send a set share of requests (for example 1%) to the new version, or only the requests that carry certain HTTP headers (User-Agent: Internal-QA or Cookie: beta=true). While basic reverse proxies route traffic across IP endpoints, a Service Mesh (such as Istio or Linkerd) or Kubernetes Gateway API provides Layer 7 routing rules with weights: each backend gets its weight divided by the sum of weights, regardless of how many pods each version runs. The split is applied per request, so over a small number of requests the observed share wanders around the target.

By pairing GitOps declarative reconciliation with service mesh Layer 7 traffic routing and expand-and-contract database migrations, organizations can practise continuous deployment: shipping many small changes a day, each with a fast way to contain failures.

05. Check your understanding

Practice check · 3 questions

Traffic splits and feature-flag behaviour

Three questions on canary traffic shares and on how flags change and age.

Q1. One Kubernetes Service selects both the stable Deployment (10 pods) and a canary Deployment (1 pod). What share of requests does the canary get, and what gives it a 1% share without changing pod counts?
Q2. An engineer turns a feature flag off in the flag console. Why might some servers keep the new behaviour for a while?
Q3. A feature flag has been on for 100% of users for two months, and the old code path is still in the code. What is the main risk of leaving it there?
Practice only: not graded, not saved, not evidence.

06. Apply it

Plan one column rename as expand and contract, and release the code that uses the new column through a canary. This takes about 30 minutes and needs only a text editor; if you have a local PostgreSQL (for example in a container), run the SQL as well.

  1. The orders table has a column ship_addr that should become shipping_address. For each of the three releases, write the SQL it runs, which column the application reads, which columns it writes, and whether rolling back to the release before it is still safe, and why.
  2. Write the phase 2 backfill as one UPDATE that copies at most 1,000 rows each time it runs, for example UPDATE orders SET shipping_address = ship_addr WHERE id IN (SELECT id FROM orders WHERE shipping_address IS NULL AND ship_addr IS NOT NULL LIMIT 1000). Say how you will know that it has finished.
  3. The release that switches reads to the new column runs as orders-v3 next to orders-v2. Write a Gateway API HTTPRoute that sends requests with the header x-canary: true to orders-v3, and splits all other requests 99 to 1 between orders-v2 and orders-v3. The Gateway API traffic-splitting guide in the references shows the format.
  4. Write the Git change that rolls the canary back, and say what Argo CD with selfHeal: true does if someone changes the weights with kubectl edit instead.

Produce: one text file with the three releases, the backfill statement, the HTTPRoute and the rollback note. Check your plan against the callout above: no release may drop ship_addr while a version that reads it can still be rolled back to.

07. Review prompt

Detail the three phases of the Expand and Contract database migration pattern and explain why a destructive schema change in the same release as the code change removes the option of a quick rollback. Discuss how feature flags decouple deployment from release, and contrast pull-based GitOps automated reconciliation with traditional push-based deployment pipelines.

References

Your progress

Reading state

Sign in to save that you finished reading this lesson.

Sign in to mark reading complete

Prove this skill

10 questions · about 8 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.
Take the skill check