-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Actor Persistence #112
Comments
@softinio Hi, I've started thinking about an API design for this ticket. Have you started working on this? After some time of thinking about it on my own and then looking at Akka, I came to a conclusion that Akka's API design is suitable. Do you think that is the correct approach? Or is there a better one? DesignSo, as we already have trait EventSourcedStateful[S, +E <: Throwable, -F[_], Ev]
def receive[A](state: S, msg: F[A], context: Context) :IO[E, (Event[Ev], A)]
def sourceEvent(state: S, event: Ev): S
} Same as in Akka, the API should provide two separate steps of processing a message:
For representing events there's sealed trait Event[+Ev]
case class Persist[Ev](event: Ev) extends Event[Ev]
case object Ignore extends Event[Nothing]
object Event {
def persist[Ev](event: Ev) = Persist(event)
def ignore = Ignore
} Such design is pretty much the same as in Akka, because we need a separation for impure message processing and pure state update that we persist. Reading persisted events for given Examplesealed trait Msg[+A]
case object Increase extends Msg[Unit]
sealed trait MyEvent
case object SomeEvent extends MyEvent
new EventSourcedStateful[Int, Nothing, Msg, MyEvent] {
override def receive[A](state: Int,
msg: Msg[A],
context: Context)
: IO[Nothing, (Event[MyEvent], A)] =
msg match {
case Increase =>
state match {
case i if i > 10 =>
IO.effectTotal((Event.ignore, ()))
case _ =>
IO.effectTotal((Event.persist(SomeEvent), ()))
}
}
override def sourceEvent(state: Int, event: MyEvent): Int =
event match {
case SomeEvent =>
state + 1
}
} Thanks to using ZIO we can be sure that user won't make any side effects in Also when spawning an actor with a What do you think about such design? |
@mtsokol Nice work Sir! Overall I am fine with your design but would be good to do more to distinguish our implementation from Akka. I haven't started work on this myself yet, I assigned myself to it as I wanted to break it up into smaller issues as I feel this is a big topic to have as a single github issue. Lets use this issue to finalize design and approach and create new related issues for doing the work so we can split the work. We need to design a common Trait that gets extended for each datastore that we will support. Will provide more feedback later this weekend once I have chance to think your design through more. @mijicd Look forward to your feedback also on this approach? |
I agree with both about taking the approach from Akka as the API design foundation. It is battle-tested, and anyone interested in this feature is more or less familiar with it. That being said, what's called I don't agree with the statement about @softinio you can "merge" ScyllaDB and Cassandra, the same client can be used for both. |
@mijicd Thanks for your remarks, I've started working on this. My clarification regarding the statement about |
Well, that's what's not true :). Akka's signature is exactly the same as the one presented above: |
Sure, I think I overinterpreted it then.
So what I meant was that the lack of But as I said I overinterpreted it 😛 |
Anyhow, let's draft it out, and see how it evolves. It might show us further polishing opportunities. |
Requirements
Data Stores to support as a minimum
It would be ideal to have ZIO implementations as an optional dependency on maven for these datastores
Notes
The text was updated successfully, but these errors were encountered: