Skip to content

Lesson 6 of 9 · 26m

Review Apps That Engineers Actually Use

Ephemeral merge-request environments with deterministic naming, safe teardown, realistic data, and cost controls.

Review apps are the difference between reading code and experiencing a change. They are also where teams accidentally create hundreds of abandoned namespaces, wildcard DNS entries, and cloud bills shaped like a crime scene. A useful review app system is ephemeral by design and boring to operate.

Name environments deterministically

review:
  stage: review
  script:
    - ./scripts/review/deploy "$CI_ENVIRONMENT_SLUG" "$CI_COMMIT_SHA"
  environment:
    name: review/$CI_COMMIT_REF_SLUG
    url: https://$CI_ENVIRONMENT_SLUG.review.example.com
    on_stop: stop-review
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'

CI_ENVIRONMENT_SLUG gives you a DNS- and filesystem-safe name derived from the environment. Use it consistently across deployment, DNS, Kubernetes namespace, database schema, and teardown. If each subsystem invents its own name, cleanup will miss something.

Stopping is part of the feature

stop-review:
  stage: review
  script:
    - ./scripts/review/destroy "$CI_ENVIRONMENT_SLUG"
  environment:
    name: review/$CI_COMMIT_REF_SLUG
    action: stop
  when: manual
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
      when: manual

Automatic stop on merge or branch deletion is ideal, but event delivery and lifecycle rules can fail. Add a scheduled sweeper that deletes review resources older than a fixed age. Ephemeral systems need a garbage collector.

Data realism without production leakage

A review app pointing at production data is not a review app; it is an incident generator. Use seeded synthetic data, anonymized snapshots with strong approval controls, or ephemeral databases created per review.

psql "$DATABASE_URL" -f db/schema.sql
psql "$DATABASE_URL" -f db/seed-review.sql

Keep secrets scoped to the review environment. Do not reuse production API keys because the sandbox integration is inconvenient. Test keys and limited scopes exist for this reason.

Cost and concurrency controls

Review apps multiply quickly. Limit who can create them, cap resources, scale to zero where possible, and expire environments aggressively. The default question should not be "why did it stop?" but "why is this still running?"

Field notes

  • Deterministic names make deployment, routing, and teardown agree with each other.
  • on_stop handles one path; a scheduled sweeper handles reality.
  • Never connect untrusted review code to production data or production credentials.
  • A review app is only useful if the merge request links directly to it.
  • Put resource quotas on ephemeral infrastructure before finance asks about the bill.

Was this lesson helpful?

Sign in to rate