thombergs / buckpal

An example approach for implementing a Clean/Hexagonal Architecture
https://leanpub.com/get-your-hands-dirty-on-clean-architecture/overview
2.14k stars 659 forks source link

Question regarding the example #28

Open amrutprabhu opened 3 years ago

amrutprabhu commented 3 years ago

Hi Tom, I had read your book about clean architecture a month ago. I really like it as it was straightforward to the facts and no beating around the bush. 

Now, after that, today I was going through the code sample you had shared in the book ie. the buckpal example (https://github.com/thombergs/buckpal)

Looking at the send money use case, I understood the flow as follows:

  1. Load the source account.
  2. Load the Target account.
  3. Withdraw from Source
  4. Add to target. 
  5. save the activities on the accounts. 

Now here are some of the questions I had. 

  1. On the  line  https://github.com/thombergs/buckpal/blob/f5a9be50771e77ca66a153bc83c383b32cab738e/src/main/java/io/reflectoring/buckpal/account/application/service/SendMoneyService.java#L31

I see you are loading the account with a date of only 10 days back. Then account state is created based on the activities only 10 days back. So aren't we losing the account activity prior to that day to calculate the baseline account value? isn't this like the incorrect state of the account to perform withdrawal?

  1. In case we decide to load all the activities to calculate the account's baseline value, aren't we querying a lot of data from the database? 

What I had in mind, would be to also persist the baseline account value in the account entity, which would be the aggregate value of all the withdrawals and deposits. And we can then fetch the current baseline value, which would be like a single query select * from account where accountid=1 then

  1. you make a change based on the activity to the baseline value
  2. persist the activity to the database
  3. persist the account entity with the new baseline value.

I feel every time to get all the activities for the account and calculate the baseline every time I load the account is a waste of CPU and also puts pressure on the database to return a lot of data for the account.

I may be wrong In thinking this... could you enlighten me on what advantage I am missing by the calculation of the baseline everytime I load the account?