Skip to content

Question regarding the example #28

Open
@amrutprabhu

Description

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 
    LocalDateTime baselineDate = LocalDateTime.now().minusDays(10);

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?

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions