Skip to content

Proper way of storing data with events #705

@mbajur

Description

@mbajur

Hey there! First of all, thank you for this great piece of software.

I'm not sure if that's a proper way to ask general best-practice questions but let's give it a shot. If not, please forgive me.

I'm building a system which receives a pretty complicated JSON object and needs to validate it async and, if it's valid, it needs to make a further work. Obviously that's a really simplified description of what's really going on.

As those incoming JSON objects are kind of like commands of what to do with actual models (Create/Update/Vote/etc), i decided to go for RES and test it out. Everythng goes smoothly so far but i'm unsure about one detail. Let's say steps are as follows:

  1. JSON object comes in
  2. ActivityCreated event is created in RES
  3. JSON validation is being done using RES subscribers (async)
  4. If Activity is successfull, ActivityAccepted event is created
  5. otherwise, ActivityRejected event is created

Apps using that can subscribe to ActivityAccepted event and do further work. By "further work" i mean reading data from the JSON object persisted in step 2.

Right now, i subscribe to ActivityAccepted and gets the received JSON using the following code instead of storing the same JSON with ActivityAccepted event:

class OnActivityAccepted
  def call(event)
    id = event.causation_id
    Rails.configuration.event_store.read.event(id) # to fetch the contents of parent event
  end
end

As it works pretty well, is that a proper way of dealing with data in ES world? Should i pass the original JSON to the ActivityAccepted event (and any other further event)? Are there any best practices regarding that? Right now, the only contents of ActivityAccepted event are the state changed to accepted

Thanks in advance for any tips!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions