Can POJOs be proxied in a microservices application?

I'd like to avoid duplicating my POJOs in a microservices application, so I'm wondering if there is a way to do this (like proxying)?

I mean, is there a way to Service A

be able to access POJOs (or other classes / interfaces) defined internally Service B

without physically creating those POJOs files in Service A

?

The big problem in microservice architecture is that point and I haven't found a way to solve it.

+3


source to share


1 answer


"Simple": when there are two services that need to use something common , then the answer translates that code into a library of some form and depends on both services.

Anything else is most likely a bad idea. The whole idea behind microservices is that service A does not depend in any form on B. And you don't want to get into the reflection game and somehow access the internal services of another service through some kind of backdoor.



As some comments say: Using a library helps avoid code duplication. The alternative is to intentionally copy the "shared" parts from service B to service A. This is also an option.

In this sense: you either redistribute the shared parts into the library or copy them. Both approaches have their pros and cons. You must define what is important in your environment.

+6


source







All Articles