简体   繁体   中英

How do I access data that my microservice does not own?

A have a microservice that needs some data it does not own . It needs a read-only cache of data that is owned by another service. I am looking for guidence on how to implement this.

I dont' want my microserivce to call another microservice. I have too much data that is used in a join for this to be successful. In addition, I don't want my service to be dependent on another service (which may be dependent on another...).

Currently, I am publishing an event to a queue. Then my service subscribes and maintains a copy of the data. I am haivng problem staying in sync with the source system. Plus, our DBAs are complaining about data duplication. I don't see a lot of informaiton on this topic.

Is there a pattern for this? What the name?

First of all, there are couple of ways to share data and two of them you mention.

  1. One service call another service to get the data when it is required. This is good as you get up to date data and also there is no extra management required on consuming service. Problem is that if you are calling this too many times then other service performance may impact.

  2. Another solution is maintained local copy of that data in consuming service using Pub/Sub mechanism.

    • Depending on your requirement and architecture you can keep this in actual db of consuming service or some type of cache ( persisted cache)
    • Here cons is consistency. When working with distributed architecture you will not get strong consistency but you have to depends on Eventual consistency.
  3. Another solution is that and depends on your required you can separate out that tables that needs to join in some separate service. It depends on your use case.

  4. If you still want consistency then at the time when first service call that update the data and then publish. Instead create some mediator component and that will call two service in sync fashion. Here things get complicated as you now try to implement transaction over distributed system.

One another point, when product build around Microservice architecture then it is not only technical move, as a organization and as a team your team needs to understand something that work in Monolith, it is not same in Microservices. DBA needs to understand that part and in Microservices Duplication of data across schema ( other aspect like code) prefer over reusability.

Last but not least, If it is always required to call another service to get data, It is worth checking service boundary as well. It may possible that sometime service needs to merge as business functionality required to stay together.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM