New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about isolation of databases #1

Closed
suadev opened this Issue Jan 31, 2019 · 5 comments

Comments

Projects
None yet
3 participants
@suadev
Copy link

suadev commented Jan 31, 2019

Hi,

My question is about the line below. Discount and Customer are two seperate databases, right?

On the line below, Discount service is accessing the Customer service's db directly.

In microservices architecture, this is not right way. Discount service need to make a http call to customer service.

what do you think about it?

var customer = await _customersRepository.GetAsync(discount.CustomerId);

@GooRiOn

This comment has been minimized.

Copy link
Member

GooRiOn commented Jan 31, 2019

You're not correct. Notice that discounts service subscribes to CustomerCreted event. In its event handler it creates a local version of Customer (just with Id and Email) which is then stored inside discounts DB. The line you pasted is nothing more but a call to local DB with local copy of a customer.

Here's an event handler that synchronizes data: https://github.com/devmentors/DNC-DShop.Services.Discounts/blob/master/src/DShop.Services.Discounts/Handlers/Customers/CustomerCreatedHandler.cs

@suadev

This comment has been minimized.

Copy link
Author

suadev commented Jan 31, 2019

@GooRiOn sorry my bad.

I missed that point.

Even if i don't like the pattern that a service keeps a local copy of another service's data, it's ok with microservices architecture.

@GooRiOn GooRiOn closed this Jan 31, 2019

@spetz

This comment has been minimized.

Copy link
Member

spetz commented Jan 31, 2019

Such data duplication reduces the temporal coupling. Events are one way of achieving the asynchronous integration. Imagine the following scenario: you want to fetch the order details data (some read-model). Either, your Orders Service is being dependent on the Products Service (and each time you fetch the Order DTO from DB you have to internally call Products Service to get products, which might be temporarily offline or so), or you keep the data in your own DB, which improves the overall service resiliency. Not to mention that Product aggregate has a totally different meaning when talking about the Orders (where it's just a historical data within the Order Item).

@spetz spetz reopened this Jan 31, 2019

@spetz spetz closed this Jan 31, 2019

@suadev

This comment has been minimized.

Copy link
Author

suadev commented Jan 31, 2019

@spetz Is this pattern comes from DDD approach or it'is your own decision, i wanted to ask firstly.

Your explanation is absolutely make sense. But, i think this pattern also bring with a data syncronization challange. Let me explain.

Discount service is up and running but something went wrong while creating the customer on its own database. So, CustomerCreatedEvent message is not exist in the queue anymore right? What would we do in this scenario? I guess, rabbitmq can configure to handle this kind of situations. For example; We can say, Do not delete the message from the queue untill the consumer say i finished with it. What do you think?

@spetz

This comment has been minimized.

Copy link
Member

spetz commented Jan 31, 2019

@suadev you're correct, and the data synchronization issues might happen. At first, you should always have the message bus cluster up and running, meaning that all of the queues will be there and there's a message dump (onto disks, db etc). If anything goes wrong, the whole broker should be restarted and load all of the messages (so nothing should be missing). You can easily configure it with RabbitMQ (durable queues + persistent messages, however, this one comes affects overall performance).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment