exactly *one* persistence actor with the same persistenceId active ?

118 views
Skip to first unread message

Olger Warnier

unread,
Sep 5, 2014, 11:26:46 AM9/5/14
to akka...@googlegroups.com
Hi guys, 

simple question: is it expected that exactly 1 PersistentActor that makes use of a specific persistenceId is active ?

In order to get all changes of my AggregateRoot, I've build a publisher that tells that this aggregate has changed. By using a single persistenceId, it's possible to read for all instances of the aggregate and thereafter fire up a specific view for the specific AggregateRoot. (nothing new here, all discussed in other threads)

My idea was to build an extension for that as that is a nice and usable way to publish these changes. 
Side effect is that every actor system that actually does the domain for this aggregate (and with cluster sharding, it is expected to be more than 1) will run such a publisher actor (that is actually a PersistentActor). 
This gives 'strange' behaviour around the persistence sequence numbers (actually counting per live actor system) that made me wondering if this approach appropriate. 

I've got the feeling that the answer is 'yes', still handy to have it here for the record. 

Kind regards, 

Olger

Martynas Mickevičius

unread,
Sep 6, 2014, 4:40:09 AM9/6/14
to akka...@googlegroups.com
Hi Olger,

yes, a unique PersistenceId per PersistentActor. However there can be as many PersistentViews having the same PersistenceId.


--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.



--
Martynas Mickevičius
TypesafeReactive Apps on the JVM

Ashley Aitken

unread,
Sep 8, 2014, 12:33:22 AM9/8/14
to akka...@googlegroups.com

Thanks Martynas.

I am also interested in this.

Besides ordering, is there any other problem with having multiple PersistentActors with the same persistenceId?  

E.g. could events be lost or corrupted?

Cheers,
Ashley. 

Olger Warnier

unread,
Sep 8, 2014, 2:11:14 AM9/8/14
to akka...@googlegroups.com, akka...@googlegroups.com
Hi Ashley,

Events are assigned the same number as each instance starts counting in the same way. It appears that the last one written with a specific sequence number is eventually kept.

In my situation, I've solved this by using a cluster singleton for this persistent actor. 

Kind regards,

Olger 


--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to a topic in the Google Groups "Akka User List" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/akka-user/9E65YaKI2BE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to akka-user+...@googlegroups.com.

Ashley Aitken

unread,
Sep 8, 2014, 2:18:47 AM9/8/14
to akka...@googlegroups.com

Thanks for your post Olger.


On Monday, 8 September 2014 14:11:14 UTC+8, Olger Warnier wrote:

Events are assigned the same number as each instance starts counting in the same way. It appears that the last one written with a specific sequence number is eventually kept.

That's unfortunate (I think).  I wonder if there would be some way for Akka Persistence to keep events with the same sequence number and for PAs and PVs to effectively handle that situation.  I realise it may not be that sensible from a persistent state perspective but more generally it could be useful.  

In my situation, I've solved this by using a cluster singleton for this persistent actor. 

Thanks for that tip.  

Cheers,
Ashley.

Konrad Malawski

unread,
Sep 8, 2014, 2:48:29 AM9/8/14
to Akka User List
Hello guys,
wherever you need strict order in a distributed system there must be one source of sequence-truth, in akka-persistence's case this means having one persistent actor,
otherwise they'd compete with each other and "behaviour is undefined" yet surely undesired they could overwrite events or cause duplicate stores with the same sequence id – that's all journal dependent though.

I'd strongly advertise against working against this limitation – if you do it's perhaps a sign you're not doing event sourcing but forcing some other way of thinking onto akka-persistence for which it was not designed for.


--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+...@googlegroups.com.

To post to this group, send email to akka...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.



--
Cheers,
Konrad 'ktoso' Malawski
hAkker @ Typesafe


Konrad Malawski

unread,
Sep 8, 2014, 2:57:07 AM9/8/14
to Akka User List
Small follow up on useful tools for preserving 1-writer:
Cluster Sharding is a very good way to spread your persistent actors in a cluster while guaranteeing "one instance per persistence id".
There's also a video from the Akka Persistence ScalaDays 2014 talk we did, in which Patrik explains why Cluster Sharding is so useful with Persistent Actors.

Hope this helps!

Olger Warnier

unread,
Sep 8, 2014, 3:48:33 AM9/8/14
to akka...@googlegroups.com, akka...@googlegroups.com
Hi Konrad, 

Thanks for your additions. The Cluster Sharding setup works very well indeed. 
In order to keep track of changes within *all* sharded actors, the single writer is required. 
The moment Views can handle listening to more than 1 aggregate (that another conversation on the list), I’ll remove this as it will become a bottleneck in the cluster sharded setup. 

Kind regards, 

Olger



On Mon, Sep 8, 2014 at 8:18 AM, Ashley Aitken <amai...@gmail.com> wrote:

--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to a topic in the Google Groups "Akka User List" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/akka-user/9E65YaKI2BE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to akka-user+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages