Search code examples
restarchitecturemicroservicesmessaging

Microservices communication model


Consider microservices architecture, where you need to expose functionality to manage simple configuration shared with different microservices. Configuration is not changing often, but still, I would like to see changes whenever I ask for any value. Using REST microservice seems easy, but it is adding latency. Alternative could be RPC over messaging (i.e. RabbitMQ), but interface becomes more complicated.

What communication are you using for internal, simple services and what are pros and cons? Any examples?

I tried with REST API, but it means a lot of "slow" requests, which add a latency to overall requests.


Solution

  • I've found that using RESTful APIs with some judicious implementation of cache-control headers actually works fairly well for this use case. The biggest challenge is ensuring that the HTTP client underneath your REST client actually respects the things.

    It's fairly easy to implement, fits nicely into HTTP, and generally scales really well. It gives control to the client to decide if they want to respect the caching suggestions, allows server to optimize if it "knows" the configs haven't change (304 Not modified) to optimize if the client wants to ask for new versions.

    You don't have to get into anything too complicated from a cache-invalidation, and you can leverage things like edge caching to further accelerate things in interesting ways.