There must be something shared between actor systems ,How do they avoid lock?

Assuming that I am selling books with Actor Sytem cluster, each system are the same as others,How do they avoid oversolding ?All my systems shared the inventory.

Before I learning akka I think they may use some distribution lock or message queue,I am wondering do akka have some better way ?

I’m an Akka newbie but my understanding of how it should work with Actors (and without locks on shared data) is one would create an Actor to represent the state of the inventory of each specific book title.

Other actors that want to tell this Actor to reduce its inventory would send a message to ask it to do so. The Actor would only be running in one physical node, and it would process the incoming messages received in its mailbox, one by one (no race conditions like in traditional multi-threaded coding). For each incoming message, the Actor could consider whether it wants to comply with the incoming message (and decrease the inventory say), or whether to reject it *(because it has no inventory left for example). This Actor could reply back to the sending Actor accordingly.

How about cluster? What if the one hold the state state inventory is multiple?

Akka has “cluster sharding”, which distributes actors around the nodes of the cluster - so rather than replicating the state of an Actor in each node, rather each Actor is only run on a single node in the cluster. The toolkit takes care of routing the messages for each Actor to the node on which it is active or should be active.

The official docs cover that, and this is a nice introduction too:

Thanks,It seems resolved my problem, still hard to understand.