KatInterview

Build a Regression Test Suite for a REST API

System DesignModel answer
EasyModel answerSystem DesigntestingREST APICI/CD

Last updated

Design an automated testing strategy for a three-endpoint user service that survives frequent deployments without breaking existing behavior.

Scenario

You maintain a user profile service with three endpoints:

  • GET /users/{id} — fetch a user's profile
  • POST /users — create a new user
  • PATCH /users/{id} — partially update a user's fields

The team ships changes several times a week. Your job is to design an automated regression suite so that a broken deployment is caught before it reaches production.

What you need to cover

  1. Test layers. Describe the types of tests you would write (unit, integration, end-to-end, etc.), what each layer covers, and roughly how many tests belong at each level.

  2. Schema and version safety. Explain how you would detect a change in the API's request or response shape before it reaches users, across current and future API versions.

  3. Test data isolation. Describe how you would provision and clean up test data so that every CI run starts from a known state and parallel runs don't interfere with each other.

  4. Deployment gate. List the explicit pass/fail criteria a build must meet before it is allowed to deploy.

Constraints

  • The suite must run inside a CI/CD pipeline without manual setup.
  • You must handle external dependencies (database, third-party auth service) without relying on shared infrastructure.
  • Include a concrete code example showing how you would test that a POST /users request succeeds and that the newly created user can then be retrieved with GET /users/{id}.

Hints

Hint 1

Start from the testing pyramid: most tests should be fast and cheap (unit), fewer should be slow and broad (end-to-end). Explain the trade-off rather than just listing names.

Hint 2

Think about what 'schema safety' means at two levels: does your code match your OpenAPI spec, and does your spec match what consumers actually depend on? Those are different problems with different tools.

Hint 3

Test data isolation is mostly about who owns the database. Ask yourself: should the test talk to a real database, a container, or a mock? Each choice has consequences for what bugs you can actually catch.