0

I have one microservice named UserRegistration for user creation, another microservice named Billing where able to show the billing details for users.

After a new user is being created, it will send userId from UserRegistration to Billing through message queue like Apache Kafka or RabbitMq. Since these 2 microservices has different database, Billing microservice only has userId, how Billing able to retrieve the user details like name, age, address? Through REST API in UserRegistration?

2

To avoid duplication of data (with the associated risk of working with stale data) using a UserRegistration service makes most sense indeed. Since both services are apparently under your control you could define an endpoint in UserRegistration that delivers exactly the data needed by Billing, unless such an endpoint already exists, of course.

2
  • what is the endpoint you mean? (REST call?, messaging queue?) sorry i can't really imagine how's the flow for the endpoint in UserRegistration
    – hades
    Mar 26 '20 at 14:55
  • 1
    REST call, sorry that my wording was vague. Billing will need name and address essentially only when bills are being sent, so getting these fields just when needed using a REST endpoint will ensure that only up-to-date data will be used. Mar 26 '20 at 15:28
2

If the billing service needs other data than it actually holds itself, what is the value of using a microservice here? If billing cannot run when UserRegistration is down, you have a tightly coupled big ball of mud.

So, ask yourself: which business value does the billing service supply, under which circumstances, and when? After you have answered the question, you basically have the following possibilities:

  • scratch the billing service alltogeher, as it is part of a more general UserService
  • depend on the UserRegistration service and do live queries by whatever method strikes your fancy
  • transfer all necessary data to the billing service, and deal with the risk of stale data
2
  • thanks, but how those companies like Amazon, or Google do microservices, i mean, i don't think it is possible to eliminate the dependencies between 2 services(even the slightest) regardless of how well you design it right?
    – hades
    Mar 27 '20 at 7:43
  • 1
    @hades It is possible. The big question is: why do you use microservices? Microservices may well be used to utilize computing power dynamically (i.e. have a fat common database and dynamically add images which do CPU number crunching) OR to cut your application into vertical slices. For the second approach, a microservice should (ideally, seldom achieved) always be able to run standalone without the other serivces being present.
    – mtj
    Mar 27 '20 at 8:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.