byu

byu

PaperTrail vs Carbonite vs Others?

So, I wanted to share my decision making experience on how I chose carbonite vs papertrail – for my own specific needs, others may have different requirements.

And maybe get insight from others in the community about other possible metrics, alternatives, or things to think about-- or even their own use cases when having chosen one solution or another…

Caveat that what I did was an amount of “playing around” and superficial analysis… nothing so technical or deeply exhaustive-- i can’t really know if I decided correctly until i actually build out the thing.

Problem Statement

A new Ash project is core to a new subdomain of our business, and of course, EventDriven notifications are a go to choice for signaling between different bounded contexts (outside of this project). And also, because of the writings/speakings of Pat Helland, Joe Armstrong and Rich Hickey, I definitely wanted to embrace the benefits – though not without challenges – of the ideas of immutability (where we can with data and identity), messaging/coordinations, etc. especially across bounded contexts, autonomous computing fiefdoms (per Helland).

I chose Ash for its Resource oriented declarative philosophy, and I’m lazy and don’t want to write GraphQL or migrations.

So I was looking for:

  1. Compatibility with Ash
  2. Emit events to messaging fabric – Primary Goal
    • Domain Events vs persistence CDC?
    • Transactional Outbox Pattern, w/ understood sender ordering guarantees?
  3. Have audit trail of changes – Major Goal
    • some resources we want stronger auditing on changes for debugging and customer support.
  4. Can we model immutability for general non-functional benefits?
    • And where we need mutability of resources, can we preseve past knowledge/fact?
  5. Revert Versions – not a goal
  6. Access past Versions – A mixed bag where it “depends” based on the problem domain… to balance append-only data (e.g. just log events) vs tracking mutating versions (e.g. changing of a webhook connection target – active, inactive, url changes).

Options

So for auditing and versioning in Ash, I found two immediate options:

Carbonite

Pros

  • transactional consistency – the change is persisted w/ resource all or none, unlike post-action notifications in elixir.
  • multiple ash resources changed in same transaction are explicitly tracked
    • “changes” table FK to “transactions” table, also includes postgres transaction ids.
  • we can set custom metadata on the transaction itself
    • specify actor of change
    • we can write the initiating ash-resource action… translate this to a “domain event”?
  • has transactional outbox processing

Cons, Gotchas, Coinflips

  • persistence level CDC, not domain level events
  • Implemented using DB Triggers – mixed bag here for me.
  • Outbox processing and ordering has subtle guarantees in ordering and processing.

PaperTrail

Pros

  • transactional consistency – the change is persisted w/ resource all or none, unlike post-action notifications in elixir.
  • strict mode foreign keys constraints for relating a resource to its versions
  • modeled as saved versions, and with the ability to look up old versions
  • straight forward wrapper around ecto
  • integration as Ash extension – still experimental though
  • has specialized originator and (of change) metadata to signify the actor of the change and the source processor of the change
  • open ended metadata for the change

Cons, Gotchas, Coinflips

  • different ash resources changed in the same transaction each get their own event row, but there is no strong correlation between the two rows.
  • I’ll have to write something completely custom to try for outbox processing.

Conclusion

I ended up using Carbonite because of my own use-case needs…

Related: I didn’t find anything in Ash to support event-sourcing itself … Though, maybe commanded has some sort of future integration with Ash… haven’t started any exploration in how commanded works-- and I don’t personally see the need for event-sourcing complexity in my own needs.

Mainly, the key deciding factor was the outbox processing and that different changing resources would all be strongly correlated by a transaction-- i.e. an action on an “Aggregate Root” would also manage other subresources such as changing “tags” (a different as resource, not actually embedded resource)… while for papertrail, I didn’t see the extra transactional outbox handling/sending, or the same correlation capability.

For “immutability” vs “versioning” … I think I can get away with, for my problem domain at least, modeling relevant resources as INSERT-only to provide immutability as needed… and that I only needed audit logging for the other mutatable entities/resource, and I would not need to revert or show the user past revisions.

As for compatibility concerns for Ash, while AshPaperTrail extension existed, I saw a past PR to get carbonite to work with ash… so just fine there.

Though, I’m still fleshing out how to best design “Domain-Level Events” out of this persistence level trigger-based CDC

  • Maybe that each transaction is annotated (metadata) with the AshResource action used, and translate that to some single Domain Event.
  • or maybe create additional domain events ash resources–persisted to also be captured by the carbonite CDC.
    • outbox processor handles the transaction, sees a domain event row inserted… and sends that out instead of the raw resource data change.
    • that are explicitly created as a result of a related ash resource action, which would give me possibility of many events to one action and better conformity to the domain.

And that is me mostly completely emotional-gut decision making, with a rationalization of arbitrary picked metrics.

I hope that eventually I’ll have enough experience working with it that I can have a more rational, experience/fact based, retrospective.

And I’d like to hear from others about if they had similar/different evaluations, share anything else in this field, or if there were other alternatives?

thanks!

Marked As Solved

user20230119

user20230119

Also Liked

zachdaniel

zachdaniel

Creator of Ash

News coming soon on that front :slight_smile:

zachdaniel

zachdaniel

Creator of Ash

Nice! Looks like a great write up. We’re also actively working on ash_paper_trail right now, working to make it better. We should include in that a way to pass down identifiers so that you can track the initiating event for any given version. With that said, the carbonite solution should be great as well. As for event sourcing strategies with Ash, I’ve played with a few ideas that have some interesting takes, but are not fully fledged. I’ve pushed them up to a non-production ready experimental package that may interest you: GitHub - ash-project/ash_events: An event-architecture extension for Ash. · GitHub

byu

byu

As discovered in the thread, I wasn’t quite looking at Ash PaperTrail itself … rather it was a different paper trail.

But since I went with carbonite, I didn’t have a need to immediately re-evaluate Ash PaperTrail.

I would definitely look at Ash Paper Trail again if I had a need in a new project. But also, at that future time, I would also take a look at Ash Events – per zach.

Longer answer

And it would depend on the problem statement to solve. I could see different needs depending on the situation.

  • Is “versioning the resource” a first class concept for the feature, and exposed to the user? For example, a user may want to rollback/forward different draft versions of an Article?
    • Ash Paper Trail w/ version may look promising here
  • Or is it a non-functional issue like auditing?
    • I’ll want to re-evaluate the experience with carbonite at that time, see what worked or didn’t work.
  • Or how much we may need, or not need, “Event Driven Architecture”…
    • “Event Driven Notification” and/or “Event-State Carried Transfer” needed?
    • Do we want to keep resource state using “Event Sourcing” (Ash Events or Commanded)?
    • Would there be a path to use Event Sourcing, translate that State Event to a Domain (or Integration) Event for publication to Domain or other “Bounded Contexts”?
    • Would the problem even be complicated enough to need all the extra work/complexity for DDD and these kinds of Tactical Patterns?

Summary

But sorry :frowning: , @terris , I don’t have any thoughts on Ash PaperTrail for you at this moment-- maybe in the future.

Where Next?

Popular in Questions Top

9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New

Other popular topics Top

malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
RisingFromAshes
I’ve read in another post that it may be possible with a router helper - but I couldn’t find an appropriate one, and tbh, I’m still just ...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement