1

How can I manage eventual consistency when getting stock balance (or like bank account balance) from read database when implementing CQRS? I dont want to playback events as I believe it will be a bottleneck.

Trying to Implement CQRS for inventory management. Getting wrong stock balance due to eventual consistency.

AKBK
  • 11
  • 2

1 Answers1

1

The trick here is to realise that perhaps it is not actually a business problem if the data on the read side is eventually consistent (ie old data)?

For the bank, the bank can actually make money on overdraft fees when the balance is negative.

But, as a developer it may feel weird to not always use the 100% up-to-date value.

secondly, the inventory value in your database is an approximation of the actual value in the warehouse shelf. Things might have been damaged, lost, misplaced or stolen. So the actual value in the warehouse and in your database will never be 100% accurate.

So, I would ask the business if this is really a requirement?

Tore Nestenius
  • 16,431
  • 5
  • 30
  • 40
  • Thank you. That is indeed a realistic way to go about it. But its another thing to convince the stake holders especially when coming from a legacy ERP system. Still I would like to know if there exists any optimized solution for such cases using CQRS. – AKBK Mar 09 '23 at 12:32
  • There are a few ready many solutions for starting building CQRS-based systems, some are https://www.axoniq.io/ (java) https://liquidprojections.net (.NET) https://martendb.io/ (.NET) – Tore Nestenius Mar 09 '23 at 13:56