mikeysee
mikeysee•16mo ago

Convex and State Machines

Hi, has anyone done anything specifically with state machines on convex? Im thinking it might be quite powerful tro leverage XState (or something similar) plus the jobs system plus the natural atomicity of Convex to have a system follow a fixed state chart?
12 Replies
jamwt
jamwt•16mo ago
@mikeysee hey! yes, so I know David K and think xstate is pretty cool. he and I have explored the idea of convex <-> xstate a few times over the last year or so. in the past, convex hasn't quite had everything necessary to the best of my understanding to support what xstate needs, but convex post-1.0 is close. it's probably something we should revisit soon. if you dig into it at all, let us know how it goes
mikeysee
mikeyseeOP•16mo ago
Yes we are looking at building a tournament system on convex currently and think it is a great usecase for state machines. Will let you know if anything interesting comes out of it or if we run into any issues.
jamwt
jamwt•16mo ago
great! I'm going to try to dig out some work someone did recently where they did use convex and a kind of state machine DSL framework and they bound them together and it worked pretty well. it was just a POC, and maybe it was actually xstate? I feel like I can't quite recall right now, though this was within the last 6-10 weeks, so should be possible to dig it up
mikeysee
mikeyseeOP•16mo ago
cool thanks!
DiamondDragon
DiamondDragon•5w ago
Hi @jamwt I have been reading more about xstate and trying to get more familiar with it so i can start using it more. it seems like XState and Convex together on the backend would be really powerful, but i'm not big brained enough to really understand the "when should i reach for this?" or "this is how i should think about the best practices?" kind of questions. I think where I'm at is understanding that XState is really powerful for complex client side apps (like dashboards) and separately can be used server side. But when thinking about which state remains on client or backend alongside XState is where I am not sure. I am new to learning convex and playing around with it, and my current mental framing of Convex is that it's really powerful to lean into Convex's backend as a single source of truth , so that's where I am wondering "Should i try working with XState on the backend with convex and just manage the complexity for clients on the backend?" Not sure if my comments make sense
mikeysee
mikeyseeOP•5w ago
Ye this is something I would like to dig into a bit futher too. I think your mental model of Convex as "the single source of truth" is the right one (until you introduce local state). An ex-colleague of mine experimented with xstate and Convex, I need to look through that a bit more carefully but I agree it seems like it could be a powerful combination. If I was just starting out on Convex I probably wouldnt dive right into using Convex and XState together, it would probably be wiser to get a project (even if its small) under your belt that uses just convex first so you can get a better intuitive understanding of how all the bits fit together. Having said that however, if you do play with xstate on the backend I would be very interested to hear how you get on, what your experiences are with it, what lessons you learnt etc 🙂
adam
adam•5w ago
I would also be interested in knowing when I should reach for using XState? From what I understand, it's useful for restricting state transitions so that states can only be transitioned in a certain order. I see some overlap with multi step workflows, and I'm curious how XState would be related to multi-step workflows such as Temporal, n8n/Zapier?
ampp
ampp•5w ago
sounds like you never got a chance to make that tournament system?
DiamondDragon
DiamondDragon•5w ago
AI agent/workflow uses cases are interesting as well. Langgraph is the big dog for ai workflows, but mastra appears to be an alternative and they use xstate it seems for workflows
mikeysee
mikeyseeOP•5w ago
Sorry I have a terrible memory, remind me? 😛
ampp
ampp•4w ago
this^
mikeysee
mikeyseeOP•4w ago
ahhh hahha, yes we did indeed build a tournaments product: https://tournaments.battletabs.io/ Im not 100% sure if the developer that led that did end up using xstate in the end, I think he ran into some issues. Its on my list to dive in deeper very soon.