DEV Community

Andrzej Krzywda
Andrzej Krzywda

Posted on

Querying data from process managers or sagas

Today I received such a question:

Hello! Is there ever a time where it’s appropriate to query the read model/projections from inside a saga/process manager? For example:
I have an application/inquiry form that can be submitted by leads, and sometimes they submit it more than once. I don’t want to create multiple records for a lead if I know I already have them (say by normalized email address). My initial thought was to create a saga around the application submitted event and optionally create the lead if they don’t already exist.

This is a question I often receive recently. Here is my answer:

In general, the answer is yes, sometimes it’s hard to avoid such “queries”.
However, there are some things I’d be careful with:

  • Try to avoid querying an exisitng read model that is also used for a UI purpose. This comes with a risk that a small change on the UI can result on breaking the process manager (in the worst case have a test which covers such integrations)
  • Watch out for too big projections/read-models - certain data (a list of all leads?) can be huge one day.
  • Choose the peristence method wisely - for bigger sets of data, projecting from events on the fly can be slow. In that case having a read model backed by a db table is OK
  • Sometimes having this need points to a potential design problem (the process manager being too big, similarly as with aggregates) - I don’t think this is your case, but just a word of warning

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay