DEV Community


Posted on

How to test new microservice APIs - (Monolith to Microservice)

This article will cover on a interesting approach to test newly build microservice APIs. Assuming that we are building a new microservice breaking an old monolith application that is already in production and used by end users.


We had a very large monolith and had to break them into multiple microservices. This was easy due to the TDD practice. The problem was on deciding the release process. How will you release the microservice APIs without affecting the end users and also test then thoroughly.

  • Release and test gradually and not at once
  • Need a way to test the new microservice APIs before releasing
  • Foresee any issues early before actual release

Proposed solution

Image description

Below is the list of steps how the experiment should work:

  • Frontend calls the new monolith API.
  • In backend, the API middleware is triggered. The middle ware will as usual send pass the request to the controller.
  • The controller performs the operations and returns the response to the middleware.
  • The middleware here will return the response to frontend. Thus causing no delays to the frontend.
  • In background the middle ware will do the following.
    • A random percentage is calculated. Ex: 3
    • This random percentage is compared with the release percentage set either as an environment variable or any flags like LaunchDarkly. Hence if release percentage is set to 5 then there only 5% of chance that the process continues.
    • If the above condition matches, then call the microservice API.
    • Compare and log the API processing time and response.

We can gradually increase the release percentage whenever there are no issues with monolith and microservice API responses. Ex: start with 5 then increase to 25, then to 50, then to 75 and finally to 100.

Using this setup without even affecting existing monolith API you can test the new microservice API. This will be most effective on APIs that are very sensitive, like billing or most used, like getting main job list.


Once the test succeeds and at 100% you are not receiving any issues. Then you can disable this experiment & monolith APIs and directly enable the microservice APIs.

Top comments (0)

An Animated Guide to Node.js Event Loop

>> Check out this classic DEV post <<