O'Reilly logo

Domain Modeling Made Functional by Scott Wlaschin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Pushing Persistence to the Edges

As we discussed earlier, we would ideally like all our functions to be “pure,” which makes them easier to reason about and test. Functions that read from or write to the outside world cannot be pure, so when designing our workflows, we want to avoid any kind of I/O or persistence-related logic inside the workflow. This generally means separating workflows into two parts:

  • A domain-centric part that contains the business logic
  • An “edge” part that contains the I/O-related code

For example, let’s say we have a workflow that implements the logic for paying an invoice. In a model that mixes up domain logic and I/O, the implementation might be designed like this:

  • Load the invoice from the database.

  • Apply the payment. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required