rathoud96
I am working with commanded by @slashdotdash. Recently I encountered an issue where my aggregate’s state was different than my projection.
For example the aggregate state is %Aggregate.Example{is_valid: false} and my projection is %Projection.Example{is_valid: true}
Now I am stuck on how to sync them or is there a way the state can be updated?
Thanks
Trending in Questions
Hello!
Suppose you are building workflow (order / task / payment) processing system with the following requirements:
Each workflow con...
New
I’m aware of 2 such projects, are there others?
git: GitHub - team-alembic/realworld: A fullstack Phoenix LiveView application with back...
New
Hi all,
I’m working on a Phoenix project where I need to make external HTTP requests and I’m trying to choose between Req and HTTPoison....
New
Hi everyone.
My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
Hi,
we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New
Hi all, I’m new here and would like to hear peoples views on my Elixir/Phoenix based game-engine! :smiley:
Mutonex gamedesign was finish...
New
Hello
I’ve been coding in Elixir for almost two years now because of my current job where we implemented Elixir in our application. But ...
New
Other Trending Topics
Hey there,
I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first.
...
New
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself.
My main conc...
New
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly)
AI dream has many faces, but general...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #ai
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #blog-post
- #ecto-query
- #elixirconf-us
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #elixirconf-eu
- #api
- #forms
- #security
- #hex











Showing Posts 1 to 7- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
tcoopman
I’m lacking a bit of context to give a good response.
Do you mean your projection in production has a bug so that it’s state is wrong? Did you forget to handle an event? Or something else?
If it’s a bug in your projection, the default way to solve this would be to fix the bug, deploy it and then replay the eventstream.
rathoud96
Hello, @tcoopman thanks for the quick response.
My projection is correct but my aggregate state is incorrect.
tcoopman
Do you know why they have a different internal state? Did you find the bug?
In event sourced systems your aggragate is the thing that makes decisions.
Syncing is not something we want to do manually. We always look at the stream of events. They are the source of truth.
Depending on the kind of bug you made, you can either rebuild the aggregate state:
https://github.com/commanded/commanded/blob/master/guides/Aggregates.md#rebuilding-an-aggregate-snapshot
Or send in a compensating command to the aggregate. That means you need to implement that on the aggregate, and then make sure that it uses the command to fix it’s internal state.
rathoud96
I could not find the bug. In the event stream as well i just have error logs but those aren’t helpful.
I tried to delete the event stream but now if i run the same command again it says
command_uuidnot found.I am pretty new with commanded that’s why having difficulty figuring out the issue.
tcoopman
Do you have some code that you can share so we can take a look at it?
rathoud96
It would be difficult to share the sample code, but I will try to explain in a more detail.
I have a table ‘books’. It looks something like this
And my aggregate looks looking like this
Now before the recent change, the
is_publishedwas true for aggregate as well but now after I put a validation for the author_id it’s giving me the wrong state in aggregate.What the validation is
if author_id is in DB then the 'is_published: true' else 'is_published: false'And the above validation would work only when we insert or update the operation.
Now I am not getting why this validation would change the
aggregatestate.After adding the validation I didn’t do any insert or update.
tcoopman
On my phone, so I’ll do my best to respond.
I’m going to take a step back from commanded and talk about event sourcing in general for a moment.
In event sourcing an aggregate takes a list of events (it’s own history) and a command and it makes a decision. That decision is communicated by returning one or more events.
The aggregate should be pure. Meaning it should make the decision only based on the information in the history of the events and the command. It should do no queries or other side effects to make a decision.
I write should. I mean I strongly suggest doing it that way. It will give you easier to understand code. Easier to test code,…
Looking at your code it looks like you’re doing a query in the aggregate. From a design perspective I would try to extract that.
It’s not clear though where you’re doing the query in the aggregate. Is it when making the decision? So where you handle the command? Or is it in the apply function?
If it’s in the apply function it is definitely wrong. Your apply function MUST be pure.
If it’s in the code making a decision. The only thing I can imply is that at the time of the command the author was not in the DB. I would expect a different event though depending on if the author is in or not, so the projection should follow and have the same information.
Hopefully this makes sense. If not let me know.