---
title: "Comment by ZHE ZHANG on \"The Tri-Z Architecture: a Pattern for Layering ZIO Applications in Scala\" | Hashnode"
description: "If ZPure is used together with Event Sourcing, because Event Sourcing has an EventHandler that folds events and applies them to the state, and ZPure also descri"
url: "https://hashnode.com/posts/the-tri-z-architecture-a-pattern-for-layering-zio-applications-in-scala/66b07c222ac672d4672fe731/comment/67ada0aa241e6d265ffd7ee3"
---

[Discussion](https://hashnode.com/posts/the-tri-z-architecture-a-pattern-for-layering-zio-applications-in-scala/66b07c222ac672d4672fe731)

Comment [The Tri-Z Architecture: a Pattern for Layering ZIO Applications in Scala](https://hashnode.com/posts/the-tri-z-architecture-a-pattern-for-layering-zio-applications-in-scala/66b07c222ac672d4672fe731)

[ZHE ZHANG](https://hashnode.com/@zhangjiji)

[Feb 13, 2025](https://hashnode.com/posts/the-tri-z-architecture-a-pattern-for-layering-zio-applications-in-scala/66b07c222ac672d4672fe731/comment/67ada0aa241e6d265ffd7ee3)

If ZPure is used together with Event Sourcing, because Event Sourcing has an EventHandler that folds events and applies them to the state, and ZPure also describes the change from the oldState to the newState, does this mean that the change function is provided by the State model and is called in both ZPure and the EventHandler? But is it still necessary to coordinate the changes in ZPure and the changes in Event Sourcing to be consistent?

[Pierre Ricadat](https://hashnode.com/@ghostdogpr)

[Feb 13, 2025](https://hashnode.com/posts/the-tri-z-architecture-a-pattern-for-layering-zio-applications-in-scala/66b07c222ac672d4672fe731/comment/67ada0aa241e6d265ffd7ee3#reply-67adaaa70034f0e755a0e09d)

The way we do it is that we have a function `liftEvent` that "logs" the event but also runs a "transition" that modifies the state. We use a typeclass for `Transition[Event]`. When running the ZPure we get the new state with the list of lifted events and we can write those event to our event store. On replay, we run the same transitions for each event.

[ZHE ZHANG](https://hashnode.com/@zhangjiji)

[Feb 13, 2025](https://hashnode.com/posts/the-tri-z-architecture-a-pattern-for-layering-zio-applications-in-scala/66b07c222ac672d4672fe731/comment/67ada0aa241e6d265ffd7ee3#reply-67adb7a9b47c0c25401869c2)

Many Thanks! I feel like these tricks are worth writing a new blog post about～
