banner



How To Pass Data Between Services In Microservice

Current Architecture:

enter image description here

Problem:

We have a ii-step flow between frontend and backend layers.

  • First step: The frontend validates an input I1 from the user on microservice one (MS1)
  • 2nd pace: The frontend submits I1 and more data to the microservice 2

The micro service 2 (MS2) needs to validates the integrity of I1 equally information technology is coming from the frontend. How to do avoid a new query to MS1? What's the best approach?

Flows that I'm trying to optimize removing the steps 1.iii and 2.3

Period 1:

  • ane.1 The User X requests information (MS2_Data) from MS2
  • 1.2 The User Ten persists information (MS2_Data + MS1_Data) on MS1
  • i.3 The MS1 check the integrity of MS2_Data using a B2B HTTP request
  • 1.4 The MS1 apply MS2_Data and MS1_Data to persist and Database 1 and build the HTTP response.

Flow 2:

  • two.one The User Ten already has data (MS2_Data) stored on local/session storage
  • 2.2 The User Ten persists data (MS2_Data + MS1_Data) on MS1
  • 2.3 The MS1 check the integrity of MS2_Data using a B2B HTTP request
  • two.iv The MS1 use MS2_Data and MS1_Data to persist and Database 1 and build the HTTP response.

Approach

I possible approach is to use a B2B HTTP request between MS2 and MS1 but we would be duplicating the validation in the first pace. Another arroyo will be duplicating data from MS1 to MS2. yet this is prohibitive due to the corporeality of data and it's volatility nature. Duplication does not seem to be a viable option.

A more suitable solution is my opinion will the frontend to have the responsibleness to fetch all the information required by the micro service ane on the micro service ii and delivered it to the micro service ii. This will avert all this B2B HTTP requests.

The problem is how the micro service one tin can trust the information sent past the frontend. Perhaps using JWT to somehow sign the information from the micro service 1 and the micro service ii volition be able to verify the message.

Annotation Every time the micro service ii needs information from the micro service 1 a B2B http request is performed. (The HTTP asking utilize ETAG and Cache Command: max-age). How to avoid this?

Architecture Goal

enter image description here

The micro service 1 needs the data from the micro service 2 on demand to be able to persist MS1_Data and MS2_Data on MS1 database, so the ASYNC arroyo using a broker does not apply hither.

My question is if exists a pattern pattern, best practice or a framework to enable this kind of thrust communication.

The downside of the current compages is the number of B2B HTTP requests that are performed between each micro services. Fifty-fifty if I utilise a cache-command machinery the response time of each micro service volition be affected. The response time of each micro services is critical. The goal here is to annal a better performance and some how utilise the frontend as a gateway to distribute information across several micro services but using a thrust advice.

MS2_Data is just an Entity SID similar product SID or vendor SID that the MS1 must apply to maintain information integrity.

Possible Solution

enter image description here

The idea is to use the gateway as an api gateway request processing that will cache some HTTP response from MS1 and MS2 and use them equally a response to MS2 SDK and MS1 SDK. This way no communication (SYNC OR ASYNC) is fabricated directly between MS1 and MS2 and data duplication is also avoided.

Of grade the above solution is just for shared UUID/GUID across micro services. For full data, an effect motorbus is used to distribute events and information across micro services in an asynchronous way (Event sourcing pattern).

Inspiration: https://aws.amazon.com/api-gateway/ and https://getkong.org/

Related questions and documentation:

  • How to sync the database with the microservices (and the new one)?
  • https://auth0.com/blog/introduction-to-microservices-function-four-dependencies/
  • Transactions beyond Residuum microservices?
  • https://en.wikipedia.org/wiki/Two-phase_commit_protocol
  • http://ws-rest.org/2014/sites/default/files/wsrest2014_submission_7.pdf
  • https://www.tigerteam.dk/2014/micro-services-its-not-just-the-size-that-matters-its-besides-how-yous-use-them-role-1/

Source: https://stackoverflow.com/questions/41640621/data-sharing-between-micro-services

Posted by: baumfivemplarity69.blogspot.com

0 Response to "How To Pass Data Between Services In Microservice"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel