Skip to the page

Testing a UI feature and estimating · senior

Testing flag rollouts and frontend-backend contracts

A flag rollout needs tests for both variants and a written go or no-go rule. A contract between frontend and backend must be checked against the real provider, not only against mocks.

The notes

What you must know

  • Test both variants: unit and integration tests with the flag injected (a provider or test helper), and end-to-end tests with an override (a query parameter or cookie that works only in test environments).
  • Sticky bucketing by a hash of the user id, never random per page view. Logged-out users get a stable anonymous id.
  • At 5% watch error rate, Web Vitals and search success, split by variant and compared with the control group, against a written go or no-go rule.
  • Flag service down: a safe default (the old search), a timeout and the last cached values. Server rendering and CDN: the variant is part of the cache key or the page is not shared-cached. Deciding on the server avoids hydration mismatches.
  • Removal: create a ticket and a date with the flag, and remove the dead path together with its tests.
  • Consumer-driven contracts: the frontend writes tests that record the requests and response shapes it needs. The provider runs that contract in its own CI and fails if a change breaks it. A broker stores versions and answers "can I deploy?".
  • MSW mocks are only the frontend assumption; a contract is checked against the real provider. OpenAPI types help only if the spec is true and kept up to date, and only at build time. Runtime validation (zod) at the API boundary catches drift in production.
  • Order of adoption: an OpenAPI diff check for breaking changes and zod parsing with error reporting first, then Pact for the most critical APIs. Read tolerantly: ignore unknown fields and handle unknown enum values.

The red pen

Common traps: mistake → fix

  • Mistake: MSW tests prove the API works

    Fix: they prove only what the frontend assumes.

  • Mistake: Random assignment per page view is fine for an experiment

    Fix: users must stay in one variant.

  • Mistake: Types from OpenAPI guarantee runtime safety

    Fix: they are build-time only; validate at runtime.

Easy to hard

Questions interviewers ask, easy to hard

  1. How do you test a feature flag rollout?
  2. How do you test the frontend and backend agree on the API?
  3. What do you check at 5% rollout before going to 25%?
  4. How do you remove a flag safely?

Explain it out loud

Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.

Practise by voice

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview