0

I'm beginning with microservices but what I'm about to do seems to be a bad practice. Let's imagine I have an user microservice and an order microservice.

Now, if I want to create a report based on user and orders I would need to consume both user and order microservices through their apis. Would it make sense to have a report microservice with database connections to both user and order microservices?

While I was reading microservices.io decomposition section they say that doing joins into our queries becomes harder, so why create endpoints to handle "possible joins"(suggested by the article) for reports instead of giving read access to each database(imagining a database per microservice)?

tom redfern
  • 30,562
  • 14
  • 91
  • 126
  • 1
    Possible duplicate of [How does data denormalization work with the Microservice Pattern?](https://stackoverflow.com/questions/27007353/how-does-data-denormalization-work-with-the-microservice-pattern). In fact, this question has the same domain types (users/orders) as in your own example. – tom redfern May 20 '19 at 13:00
  • Yes it uses the same domain types, but my question is not about the denormalization, my question is about having a double connection into both microservices databases. Part of the question is answered there but only about a theoretical suggestion of a Join API. – Vinícius Pacheco Vieira May 20 '19 at 13:20
  • While the title of the question says denormalisation, the question itself is more about how to structure data spread across multiple service boundaries, which is the essence of your question. Indeed, your proposal to read from both your service databases from another service is materially the same as the first option in the highest-voted-answer. – tom redfern May 20 '19 at 15:23
  • To your question: *Would it make sense to have a report microservice with database connections to both user and order microservices?* - the answer is NO. It does not make sense. You are proposing to create a monolith service which will cause you difficulties down the road. The alternative is the third option in the highest-voted answer in the duplicated question. You should replicate the data required for reporting into a read-optimised data store. How you do this is your next question. – tom redfern May 20 '19 at 15:26
  • I'm sorry but you really did not understand my question. "While the title of the question says denormalisation, the question itself is more about how to structure data spread across multiple service boundaries, which is the essence of your question." . There is no doubt on denormalization or data spread across servers, read again Tom: "why create endpoints to handle "possible joins"(suggested by the article) for reports instead of giving read access to each database(imagining a database per microservice)" This is related about creating or not a service that would consume directly those dbs. – Vinícius Pacheco Vieira May 21 '19 at 16:27
  • Yes, I've come to this conclusion by talking to a team mate here where I work, but that answer wasn't clear to me while I was reading that answer. Glad to see that our conclusion here is also a high voted answer, seems promising. Still comes to a different question, would it be better to use a redis or to mirror the databases for read-only purposes? – Vinícius Pacheco Vieira May 21 '19 at 16:29

0 Answers0