kenchilada
kenchilada

Reputation: 7559

How do you develop a microservice in isolation when it depends on other microservices?

We are evaluating a move to microservices. Each microservice would be its own project developed in isolation. During planning, we have determined that some of the microservices will communicate with other via REST calls, pub/sub, messaging (ie. a order service needs product information from product service).

If a microservice depends on retrieving data from another microservice, how can it be run in isolation during development? For example, what happens when your order service requests product details, but there is nothing to answer that request?

Upvotes: 3

Views: 703

Answers (2)

IlliakaillI
IlliakaillI

Reputation: 1558

If a microservice depends on retrieving data from another microservice, how can it be run in isolation during development?

It should be always temporally isolated from other services during development and production as well.

For example, what happens when your order service requests product details, but there is nothing to answer that request?

This is a place where design flaw reveals itself: order service should not request product details from another service. Product details should be stored in the message (event) that order service will be subscribed to. Order service should be getting this message in an asynchronous manner using publish-subscribe pattern and saving it in its own database. Data about the product will be stored in 2 places as the result of that.

Please consider reading this series of articles about microservices for more details. But in a nutshell: your services should be temporally decoupled, so when your product service is down - order service can continue its operations without interruptions. This is the key thing to understand about good distributed systems design in general.

Upvotes: 1

bichito
bichito

Reputation: 1426

What you probably need is an stub rest service. Create a webapp that takes the expected output using a path that is not part of the public api. When you invoke the public api it sends what it just received

Upvotes: 3

Related Questions