Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Microservice internal communication

I've been reading up on Microservice Architecture But I still can't understand the inter-microservices communication mechanism.
In many articles they said that microservices are usually exposed over a RESTful API. But when you search the internet you always see implementations based on messaging and events for the backend communications.

So I'm confused, Is REST API a standard for all the microservices or we can see microservices without a REST endpoints.

like image 467
Zeina Avatar asked Jan 21 '18 19:01

Zeina


People also ask

How do microservices communicate internally?

If you're communicating between services internally (within your Docker host or microservices cluster), you might also want to use binary format communication mechanisms (like WCF using TCP and binary format). Alternatively, you can use asynchronous, message-based communication mechanisms such as AMQP.

How do microservices communicate between services?

Because microservices are distributed and microservices communicate with each other by inter-service communication on network level. Each microservice has its own instance and process. Therefore, services must interact using an inter-service communication protocols like HTTP, gRPC or message brokers AMQP protocol.

What are the types of microservice communication?

There are two basic forms of microservice communication: synchronous and asynchronous.


1 Answers

For your problem , first lets understand the ways in which one service interacts with each other , lets create two service order service and customer service :

  1. One service need some data from other service to process its requests, eg: lets say you want to place an order , so from ui you must hit http request to order service (which can be rest , or have a api gateway in between n that use some other protocol like protobu ) to call order service for placing an order , now assume order service needs to check the validity of the customer , so order service needs to call customer service in sync — most probably you will hit rest or create a protobuf or have a persistent websocket between the service and then after response from customer service , order service move ahead.

In this case sync communication needs to be imitated , one direct approach is rest or protobuff , or imitate it through messaging

  1. Based on one service events , you want to update other service : in this generally the preferred style is messaging bus , where one service emits out event and multiple other services have a listener on the messaging bus and react accordingly . Eg : lets say on update of customer name in customer service , you want to update the cached name of the customer in order service , in this when name is updated in customer service , it emits customer name updated event , order service subscribe to it , then react to it

Your third question is , is it possible to have service with no rest endpoint ::: yes its possible , but every service needs to be reachable . So use rest or other form is needed

Above mentioned link : microservices.io is very good , go through it once again

like image 83
techagrammer Avatar answered Sep 21 '22 13:09

techagrammer