Phillipp

Phillipp

Hey,

I am actually interested in Event Sourcing for literally years but haven’t used it yet. Last night, I read through the guides in the Commanded documentation and watched the linked 20 minutes talk on Youtube.
The provided examples start to make sense and the overall picture becomes more clear.

Now, I have a project idea in mind for a very long time, which involves a rating system. I knew right from the start that this rating system would be a good opportunity to use Event Sourcing. However, this rating system will be a little bit more complicated in terms of aggregation and business rules.

Let me show you the concept:

The following will be my logical structure:

- parent
--- child
------category_a
------category_b
------category_c
--- category_1
--- category_2
--- category_3
  • parent and child are the actual things I want to be rated.
  • a child has a dynamic list of categories to be rated on, that can change over time, so they have just an identifier, e.g. usability (%RateCategory{subject: "id-of-child", name: "usability", score: 8})
  • a parent also has a dynamic list of categories to be rated, same as child
  • some parents are not ratable, depending on their type
  • the overall rating of a child is a combination of all category ratings for it
  • if a parent is ratable, it has two overall ratings
    • one overall rating as a result of combining its category ratings
    • another rating that combines the overall rating of its children

Here comes the tricky part:

I want to have the concept of rating periods. I am not sure yet how long a period should be, but as soon as one period ends, another starts immediately. This is to track “progress” over time.
In each rating period, a user can rate only once.
Let’s say, there is a rating period every month. In January, a user can rate all categories of a parent and child. Then, in February, the ratings will be “reset” and the user can rate for everything again.

The goal is to track the ratings of a parent and child over time to see if things got better or worse.


So, that was my overall idea for the rating system. Everything else in the system will be done the “usual” way.

What I would like to get from you are some strategies to achieve this. Since I am just starting to get into the ES mindset, I am a bit lost as to how to implement this right now.

Showing Posts 1 to 4

factoryd

factoryd

I’m a bit drunk right now. And I’m probably not reading this right. lol

And since I’m drunk and bored, I threw up a start app for you. I had all aspirations of understanding what you’re after. But nope.

I hope this sets you off onto the right path.

https://drive.google.com/file/d/1iiY6A1uHfCeoZiCxLVGm2wo_lJF9jwaQ/view?usp=sharing

slashdotdash

slashdotdash

It sounds like you want to implement your entities’ lifecycle to be within a time period. You can take inspiration from accounting where a ledger is for a given period (e.g. one year) and at the end of each year the ledger is closed. When this occurs the ending balances from the ledger are copied across into a new ledger as the starting balances.

You could design your entities’ event streams to be monthly and at the end of each month have a scheduled command end the rating period and raise a corresponding domain event. This can be used to start the next period:

  1. Whenever a rating period is started, it schedules an EndRatingPeriod command to be executed at the end of the month.
  2. The scheduled EndRatingPeriod command gets automatically dispatched at the end of the month.
  3. This produces a RatingPeriodEnded event.
  4. Which triggers a StartRatingPeriod command to begin the next month’s ratings

Include whatever data you need from the rating period in the period ended event so that it can be included in the command to be copied into the new period. For example you might just copy the average rating per category, not each individual rating.

Commanded scheduler can be used to do the above command scheduling (either using an event handler or process manager).

By splitting the entities into time-delimited event streams (e.g. monthly) you can use read model projections to build aggregated views of the ratings over time. The benefit of this approach is you won’t have unbounded event streams for your entities and limit the number of events within each stream.

slashdotdash

slashdotdash

Yves Reynhout gave a good talk at Explore DDD in 2017 which covers splitting aggregate event streams by time (appointment scheduling product for healthcare).

Phillipp

Phillipp OP

Using an extra RatingPeriod aggregrate was also one thing I had in my mind, I just wasn’t sure if this was the correct thing to do, but it gives me the most flexibility I think, because I can end a rating period whenever I want and seamlessly move from 1 month to 1 week if I want and still retain the old 1 month cycles for history.

So, let me dump my thoughts in here:

  1. I have a RatingPeriod aggregate with a minimum of id, start_date, end_date, is_active fields.
  2. I have Parent and Child aggregates whose identity is a compound value consisting of the parent/child id and the RatingPeriod id. Probably using a custom struct like in the documentation example for custom identities.
  3. When I want to commit a new rating, I first fetch the current active rating period from my read model and include its id in the rating command and event.

That should give me all I need to properly structure a read model. I aim at having one table row per parent/child entity and rating period with a json column for the categories and its rating counts.

I will also watch the talk you linked. Maybe I missed something but right now it starts to make sense and takes shape in my head.

— All posts loaded —

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
psy-q
I’m trying to set up Emacs with elixir-ls via lsp-mode and credo via Flycheck. This should mostly be preconfigured as Flycheck picks up c...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews