1

I would like to implement a complex state machine on some serverless infrastructure like AWS Lambda. I know there is already AWS StepFunction for such purpose but pricing model is not that good for my use case as there will be many state transitions on prod.

I found XState as a very interesting candidate but as far as I understand it was developed for frontend, possibility to use it in backend ist not documented but mentioned in the documentation.

Now the question: if it is possible to use it with AWS Lambda and how the state could be stored and restored after Lambda instance goes down?

  • The question really is: how complex / long running is your state machine? Why are you worried about lambda instances "going down"? What kind of functionality do you need in terms of actions at each state? Step Function is there to do minute to hour long work at each step and then transition based on the results of that - you *can* replicate that with a lambda but it will be A LOT of work. – luk2302 Mar 31 '23 at 14:55
  • State machine is very complex, it has aprox. up to 50 states and some state transitions can run for a couple of days. Because of long running transitions is my worry that lambda will lose the state if it will be not stored somewhere( DB, Cache etc.). – Dmytro Kosiachenko Apr 03 '23 at 07:24
  • This might be helpful https://graph-docs.vercel.app/examples/node/lambda – z_lander Apr 05 '23 at 07:27
  • xstate is serializable, so in theory it should be possible. I am looking at implementing something similar by creating a proxy of the activities to serialize the current state and trigger other lambdas. Serialization and storage is also useful in case you want to query the state or send events. Another thing I am thinking is using eventbridge scheduler to account for the time based events, specially when it comes to ones that span over very long time. – Felipe Sabino Jun 13 '23 at 10:53
  • 1
    Overall this activity proxy and timer override approach is very similar to what temporal.io has to support xstate, ex: https://github.com/Devessier/temporal-electronic-signature – Felipe Sabino Jun 13 '23 at 10:53
  • Found temporal.io also very interesting and possibly fitting my needs. The big drawback is that temporal.io is not supporting AWS Lambda workers. – Dmytro Kosiachenko Jun 22 '23 at 06:30

0 Answers0