Search code examples
resthateoasmicroserviceshypermedia

HATEOAS and Microservices


I'm having some serious trouble seeing how HATEOAS and Microservices can co-exist.

Let's take an example:

Let's say we have a shopping cart resource. And we need to put snapshots of products into it, e.g. product Id, product price; snapshot of current price when item was added to cart, and possibly some other values. The actual use-case is not relevant, but just to get some idea on the problem at hand.

When I have been doing HATEOAS earlier, I would have put a link in the shopping cart resource that links to products or a template url that links to a specific product.

This way, the client can still be ignorant of resource URL's.

But in the microservice world, a service should have no knowledge of other services. AFAIK.

So how could they both work together?

My interpretation of microservices is that they can never link to anything else than themselves, which would pretty much be a Self link.

I've found the same question asked on ther places, e.g. https://groups.google.com/forum/#!topic/api-craft/YRkLFVY_zFc

Where solutions like "macro services" that weave all this together is used. Which doesn't seem like a clean way to solve things.

[Edit]

I've found some more nice info on the topic: https://github.com/Netflix/eureka https://github.com/RestExpress/HyperExpress

This seems nice to have some tool augument the resources with links, but this makes me think, where does the logic to decide what links a resource should have belongs? In the service that exposes the resource? In the central service registry?


Solution

  • But in the microservice world, a service should have no knowledge of other services. AFAIK.

    I think this is the root of your confusion. My understanding is that a service should not rely on out-of-band information to communicate with other services, for the purpose of software development. This means a service should not know anything about the internals of its peers, but it doesn't make any sense to say it should have no knowledge of other services. This does not conflict with HATEOAS, in fact, they complement each other.

    There's no problem with linking to other services. How else would you build a macroservice from microservices? There's a problem with relying on out-of-band information for that.