Video in progress

Staff 🧪 Testing

The shared staging environment for microservices is always broken. How do you redesign the integration test environment?

Instead of one shared staging, I make short-lived (ephemeral) environments per PR and make contract tests the main layer of defense. I keep the shared staging only for a limited set of smoke and e2e flows before a release.

📖 Answer

Why shared staging breaks: 15 teams deploy at the same time, someone applies a migration halfway, someone deletes test data, and when one service goes down everyone says "it doesn't work on staging". The result is e2e tests red for weeks, nobody trusts them, and releases wait for "fixing staging".

The layered solution:

  1. Contract tests are the main guarantee of the agreement between services. They run in each service's CI without starting the other services. Most integration bugs get caught here.
  2. Ephemeral environments. When a PR is opened, a separate namespace in Kubernetes: the changed service plus its direct dependencies. For the rest, either shared stable versions or stubs. With request-level routing (routing a request to the PR version based on a header), you don't have to copy the entire cluster.
  3. Shared staging only for release candidates, with strict control over who deploys, and the data restored every night.

Trade-offs:

  • The infrastructure cost and complexity of ephemeral environments: DB snapshots, certificates, secrets. In a small organization this can be overkill.
  • Relying on stubs moves you away from integration reality, so stubs must be generated from contracts, not written by hand.
  • Data: a minimal synthetic seed for each environment, not a copy of prod.

How I measure: the "green" percentage of e2e tests, the time spent waiting for staging, and most importantly where integration bugs are being found: in the PR, on staging or in prod. The goal is to shift the point of discovery to the left.