I know how to model a state machine with a flow chart, it make sense.

But I’m designing an API to control websockets and manage a web websocket service via HTTP similar to pushpin. So I have at least 4 state machines. But then there’s the events and commands that get sent around that change state and I’m at a complete loss of how to model that.

I can muddle through in my head but, I want to prove it out somehow. Anyone have any experience modeling state in a distributed system?

I have at least 4 types of actors.
- API Gateway and it's connection state
- The lambda’s it executes when connections have activity (open, message, disconnect)
- Your application getting a http request to notify you of events and get commands
- and the commands you send to the control api anytime

The last three could have any number of them running at a time

And then I got quirks of api gateway which suck for application developers (one reason I'm not using it directly and building this service)

You have an open callback, and you can reject the connection or accept it, by the return of the callback. So you can't actually do any work (eg, sending messages) in this callback and you have to do the work after it returns. But how do you know if it's returned?

@reconbot you mean the websocket connection? better to always accept and then close with an error code when the callback returns.
@jed But it could send messages before the close hits, I'd need to track state about it and ignore or queue messages sent too soon?
@reconbot by it do you mean the client on the other side of the websocket? yeah, api gateway sucks for this. if you control the client ideally you’d wait until a “ready” event is sent or something, or close with error if messages are sent.
@jed it sure does =)
@reconbot cloudflare durable objects are a breath of fresh air here, fwiw. it's Just JavaScript™️.