Check if an entity exists in cluster shards

489 views
Skip to first unread message

Jisoo Park

unread,
Dec 17, 2013, 1:23:22 AM12/17/13
to akka...@googlegroups.com
Hi,

I'm playing around a bit with cluster sharding and considering trying it for my new service prototype. Although it'll start with only one node and doesn't have any scalability issue yet, I found this actor-per-entity model with built-in passivation support very useful when implementing DDD with Akka.

It's very common in web applications that when a request comes in, the app checks whether requested resource exists and if not it returns 400 (Not Found) error. However, I couldn't found any way to ask for the existence of an entity to a ShardRegion.

Currently, there are two possible workarounds:
  • Start each actor in 'empty' state by default. When a check message arrives before the state is changed by an explicit creation message, reply with negative result and stop the actor immediately.
  • Maintain global or per-cluster singleton registry.
Or we might add a feature to ShardRegion checking the existence of an entity by its id. What do you think?

Regards,
Jisoo

Patrik Nordwall

unread,
Dec 17, 2013, 3:36:42 AM12/17/13
to akka...@googlegroups.com
Hi Jisoo,


On Tue, Dec 17, 2013 at 7:23 AM, Jisoo Park <xxx...@gmail.com> wrote:
Hi,

I'm playing around a bit with cluster sharding and considering trying it for my new service prototype. Although it'll start with only one node and doesn't have any scalability issue yet, I found this actor-per-entity model with built-in passivation support very useful when implementing DDD with Akka.

It's very common in web applications that when a request comes in, the app checks whether requested resource exists and if not it returns 400 (Not Found) error. However, I couldn't found any way to ask for the existence of an entity to a ShardRegion.

Currently, there are two possible workarounds:
  • Start each actor in 'empty' state by default. When a check message arrives before the state is changed by an explicit creation message, reply with negative result and stop the actor immediately.
To be able to answer if the entity exists you have to try to load it (from persistent storage) and the solution you suggest here is the way to do that. The sharding infrastructure doesn't know if an entry is non-existing or just passivated on disk, and I don't think don't think it should or even can know that.

Thanks for asking this interesting question.

Regards,
Patrik
 
  • Maintain global or per-cluster singleton registry.
Or we might add a feature to ShardRegion checking the existence of an entity by its id. What do you think?

Regards,
Jisoo

--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://akka.io/faq/
>>>>>>>>>> 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/groups/opt_out.



--

Patrik Nordwall
Typesafe Reactive apps on the JVM
Twitter: @patriknw

Jisoo Park

unread,
Dec 17, 2013, 7:54:06 AM12/17/13
to akka...@googlegroups.com
Thanks Patrik. 

I came up with the same conclusion just before, but you've already answered 4 hours ago. I should have checked it earlier :) This behavior is common among aggregates, so it shouldn't be hard to implement in DRY way.

Also appreciate for this awesome extension!

Patrik Nordwall

unread,
Dec 17, 2013, 9:14:18 AM12/17/13
to akka...@googlegroups.com
You're welcome. Thanks for trying it out.

/Patrik
Reply all
Reply to author
Forward
0 new messages