Pinned Tweet
Your backend should probably be a state machine!
docs.statebacked.dev/blog/20…
State Backed is a great AI orchestrator (we've been building a *ton* of AI-focused apps with it ourselves). Now, it's even better: we're increasing the timeout for each state machine step to 90 seconds.
4
297
It was great chatting with @leeatchison on the @software_daily podcast about State Backed and the backend state machine architecture we're so excited about. Thanks so much for having me!
📻 Listen to our conversation here: softwareengineeringdaily.com…
2 days to build, test, and deploy a major new feature affecting DB, untrusted code-running, and API layers.
Also 2 days: upgrading dependencies in a 1 year old rust library (ts-bindgen).
Pretty convinced @unisonweb function-level versioning is the right way out of this mess.
4
247
If you have code that runs on clients and servers, the world doesn't care if you put your code in one file or 30: you have a distributed system and the rules of distributed systems apply.
Rules:
1. Things fail
2. Components upgrade independently (compatibility matters)
2
364
This React stuff is *really bad* but not because of the SQL in the presentation layer.
Let's talk about interfaces.
Software changes. We learn & improve & want to update the stuff we built.
We break software into components. Some of these components are logically separated and some are physically separated.
If the innards of one component depends on the innards of another component, it can be really hard to change one without changing the other.
If we don't bother to define how one component depends on another component, we can't really tell whether it's safe to change one without atomically changing the other. Atomicity is somewhere between hard and impossible.
If a component communicates with itself *in the future* (e.g. by storing state in a client or server that will call it later, scheduling a request, etc), then everything we said about two components applies to our single component, just in a less-obvious, more insidious way.
If, instead of an "easy" mess of interdependencies between components, we define explicit and narrow interfaces that make clear exactly the nature of the interdependence, it is very easy to tell whether we have changed something in one component that will break another.
Let's examine this React blunder in light of these basic truths about software engineering that we've known about for the past ~50 years.
We are giving up on *explicit* interfaces in favor of *implicit* interfaces. What data exactly is exchanged from client to server when a "server action" is fired? What data from the running server code is expected to match the data from the server code that produced the client code that produced the callback?
Because React has opted not to define an actual protocol (as far as I can tell), we don't actually know. But we can surmise a few things:
1. We need some way to identify the component that defines our callback.
2. We need some way to identify our callback within the component.
3. We need some way to communicate the closed-over values of variables.
That is an interface you could drive a bus through.
During an upgrade, can you guarantee that no client is running code generated (magically) by the previous version of your server code, just waiting to send an un-processable request to your new server code? What if, god forbid, you need to rollback your server code? Can you actually guarantee across every commit to every component that none of the items that compose the interface you never explicitly thought about changed in a way that won't break your system?
Software that wasn't built for change (i.e. with hard interfaces) is, by definition, fragile.
Taking 11 seconds to write out an interface for something as important as how two machines communicate across the globe to enable your customers to do whatever it is that they're trying to do is a small price to pay for a stable business.
Define your interfaces. Keep them small. Change them carefully. If you want to mess around, mess around *within* the confines of a single component. That's the beauty of a good interface: it buys you the ability to move quickly up until an interface boundary.
Unsurprisingly, we thought about interfaces, upgrades & change *a LOT* in building State Backed.
Upgrading individual machine instances independently unlocks a huge amount of safety.
Machine interfaces consist of events (inbound) and state, tag, and public context (outbound).
We intend to build a layer on top of machines to run pure code to even further narrow the interface you expose from a machine.
Discipline = Freedom in software.
This React stuff is *really bad* but not because of the SQL in the presentation layer.
Let's talk about interfaces.
Software changes. We learn & improve & want to update the stuff we built.
We break software into components. Some of these components are logically separated and some are physically separated.
If the innards of one component depends on the innards of another component, it can be really hard to change one without changing the other.
If we don't bother to define how one component depends on another component, we can't really tell whether it's safe to change one without atomically changing the other. Atomicity is somewhere between hard and impossible.
If a component communicates with itself *in the future* (e.g. by storing state in a client or server that will call it later, scheduling a request, etc), then everything we said about two components applies to our single component, just in a less-obvious, more insidious way.
If, instead of an "easy" mess of interdependencies between components, we define explicit and narrow interfaces that make clear exactly the nature of the interdependence, it is very easy to tell whether we have changed something in one component that will break another.
Let's examine this React blunder in light of these basic truths about software engineering that we've known about for the past ~50 years.
We are giving up on *explicit* interfaces in favor of *implicit* interfaces. What data exactly is exchanged from client to server when a "server action" is fired? What data from the running server code is expected to match the data from the server code that produced the client code that produced the callback?
Because React has opted not to define an actual protocol (as far as I can tell), we don't actually know. But we can surmise a few things:
1. We need some way to identify the component that defines our callback.
2. We need some way to identify our callback within the component.
3. We need some way to communicate the closed-over values of variables.
That is an interface you could drive a bus through.
During an upgrade, can you guarantee that no client is running code generated (magically) by the previous version of your server code, just waiting to send an un-processable request to your new server code? What if, god forbid, you need to rollback your server code? Can you actually guarantee across every commit to every component that none of the items that compose the interface you never explicitly thought about changed in a way that won't break your system?
Software that wasn't built for change (i.e. with hard interfaces) is, by definition, fragile.
Taking 11 seconds to write out an interface for something as important as how two machines communicate across the globe to enable your customers to do whatever it is that they're trying to do is a small price to pay for a stable business.
Define your interfaces. Keep them small. Change them carefully. If you want to mess around, mess around *within* the confines of a single component. That's the beauty of a good interface: it buys you the ability to move quickly up until an interface boundary.
2
450
Serverless is so passé.
Data store-less is so hot right now.
Access persistent data like it was in-process. Let the platform handle the rest.
1
195
🎉 Indexing by any property in a machine instance's context and queries for matching instances just dropped in State Backed!
With this, State Backed can support any backend use case I can think of.
What example apps should we build???
1
164
One of the best things about the Clojure community: sometimes they decide that a library is complete, having achieved the purpose it was designed for.
For React, that point came some time around 2018.
From then on, we should have been building on top of it but not within it.
Server Actions are now in React Canary, ready for frameworks and libraries to adopt! Server Actions are functions created alongside your components that run on the server for tasks like data mutations
4
335
The plan for machine instance indexes (going with indexes over indices, after much deliberation😃):
1. Specify index names at machine creation time or as an update to an existing machine
2. Machine versions specify a map from index name to JSON path pointing into machine context
3. Every state update updates indices (synchronously & atomically for now but thinking of only guaranteeing eventual consistency)
4. Expose a /machines/{machine}/indexes/{index}/query endpoint to get a page of instances with an index value >, <, or = the query value
If the index points to an array of values, index each value in the array separately.
WDYT?
149
Adam Berger retweeted
Replying to @sayestheorem
Exactly! I'm really excited about this. It unlocks all of the remaining use cases I can think of.
DBs today so a great job at helping you understand your data at rest.
Our goal is a "DB" that makes it really easy to understand how your data *evolves*.
Adam Berger retweeted
Replying to @abrgrBuilds
This is awesome! No need to duplicate in a DB if you need searchability :)
Working on today: indexing machine instances by any values from the machine's context.
This is the crucial step needed for State Backed to be a great store for any online data.
After this: if it's suitable for DynamoDB, it will work (we think better) in State Backed.
Save user settings safely without wasting time on undifferentiated backend work.
Simple, open source React hook from State Backed Headless.
2
234
Calling all community notes writers...
👀
Calling all #developers!
Build with our real-time and historical data on the X API.
Get started with our Pro API in minutes.
153
Just open-sourced our GitHub bot for visualizing XState state machines (hint: it runs on State Backed).
Check it out at github (dot) com/statebacked/github-visualizer-bot
🙃
20
1,238

















