Order fulfilment with Akka FSM, storing state of FSM

46 views
Skip to first unread message

Srinivas Ch

unread,
Jul 1, 2015, 1:04:43 AM7/1/15
to akka...@googlegroups.com

Hello,

I am trying to build order fulfilment component with AKKA FSM. I have few basic doubts on how the state is been stored and taken further upon event from user.

Consider states

ORDER_CLEAN, ORDER_INIT, ORDER_PAYMENT_WAITING, ORDER_PAYMENT_SUCCESS, ORDER_DELIVERY, ORDER_COMPLETE

Events as

EV_CART_CHECKOUT, EV_PROCEED_PAYMENT, EV_PAYMENT_SUCCESSFUL, EV_ITEMS_PACKED, EV_DELIVERED

State changes as

(EV_CART_CHECKOUT, ORDER_CLEAN) -> ORDER_INIT
(EV_PROCEED_PAYMENT, ORDER_INIT) -> ORDER_PAYMENT_WAITING
(EV_PAYMENT_SUCCESSFUL, ORDER_PAYMENT_WAITING) -> ORDER_PAYMENT_SUCCESS
(EV_ITEMS_PACKED, ORDER_PAYMENT_SUCCESS) -> ORDER_DELIVERY 
(EV_DELIVERED, ORDER_DELIVERY) -> ORDER_COMPLETE

Questions

  1. When we create FSM actors starting at ORDER_CLEAN with event EV_CART_CHECKOUT, would this actor is alive till we bring it to ORDER_COMPLETE(assuming we stop actor at this state) state?

  2. If yes to above point, in that case as we store order status on database how do we trigger new event on that actor? Is that do we need to maintain order_id to actor mapping and trigger event? What if there are 10K unique orders are currently being processed then we maintain mapping for all 10K actors is it? If so what is best data structure for maintaining these mappings for larger number of orders?

  3. In continuation to 2nd point, what if actors go down how to bring back actors to same state? Is supervisor actor only way to solve this? Or do we need to check actor status and then send event?

  4. At any point of state, user might not trigger next event may be for days, then is it good to keep actor live for such longer time or is it good to create new actor with updated state?

What are the better approaches to address these problems with akka FSM

Leonid Bakaleynik

unread,
Jul 1, 2015, 6:15:43 PM7/1/15
to akka...@googlegroups.com
Hi Srinivas,

You can consider using Persistent FSM, this way the state of the FSM can be recovered upon restart. 
This will let you take down the inactive actors - they can later be started again on demand, in the  state they were in before the stop.

Warning: Persistent FSM is marked as an experimental feature, it was just added to Akka 2.4-M2.

In case you do try it, it would be interesting to get your feedback.

Thanks,
Leonid

Srinivas

unread,
Jul 2, 2015, 1:48:39 PM7/2/15
to akka...@googlegroups.com
Hi Leonid,

   Thanks for the suggestion. I will update once after I finish coding in this direction.

--
Thanks,
Srinivas
Reply all
Reply to author
Forward
0 new messages