I didn't study computer science as a degree, so whilst having studied computer science, there are still gaps in my knowledge. Everything I read about 'state' sounds like some form of 'data' but kept in memory as opposed to a database. This keeps leading me to the question: is a state machine not just a way of storing data, like a database.

There is probably a very obvious answer to this, but I can't seem to find anything about it when searching Google, which leads me to think I'm way off in my understanding somewhere. Any pointers (not the memory type) into some good reading would be super helpful. Thanks!

  • $\begingroup$ State machine = algorithm. Its called like that since in the formal sense, we represent turing machines and regular automatons using graphs, where we call the nodes "states", since at each point of time the "algorithm" will be only in one such state, and can move between them. Database is a totally different thing as you can guess. $\endgroup$
    – nir shahar
    Mar 3, 2021 at 10:03

1 Answer 1


State machines and databases are quite different entities, and their usage (or functionality) is very different. In this answer, I'll just try to separate them with respect to the similarity you mention. This is by no means a comprehensive description of neither state machines nor databases.

The states of a state machine can indeed be thought of as representing data (although this is not always obvious, and sometimes state machines do not reveal what data they store in their states). However, the crucial element of a state machine is the transitions between the states, which represent the behaviour of the machine.

That is, a state machine does something. It computes. During its run (or runs, in nondeterministic models), it moves from state to state according to some predetermined set of rules, and possibly according to a given input, and this process is called a computation. At the end of the computation (if it's finite), you might receive an output, from which you can derive some information.

For example, a Turing machine receives an input and if it halts, tells you whether the input is accepted or rejected, from which you can formalize a decision problem. Similarly, an automaton does the same, but without external memory.

In contrast, a database merely stores data. How this storage is done, which operations are allowed on the data, and what their respective complexity is, are all interesting questions, and their answers depend on the type of database you use. However, databases do not compute anything by themselves, they just store the data, possibly efficiently.

  • $\begingroup$ So a state machine is literally just an event store style database? $\endgroup$
    – timhc22
    Mar 3, 2021 at 10:34
  • 2
    $\begingroup$ No. A state machine, is a formalization of computation. As you can see in its name, it is a "machine". It is more than just data. In simpler terms, a state machine is an algorithm and a database is just data. $\endgroup$
    – nir shahar
    Mar 3, 2021 at 11:17
  • 2
    $\begingroup$ @timhc22 - I don't exactly understand why you think there should be any similarity between the two things. Basically, state machines are nothing like databases. $\endgroup$
    – Shaull
    Mar 3, 2021 at 12:04
  • 1
    $\begingroup$ You're trying to force similarities that just aren't there. A state machine is a model of computation. A database is a method of storing data. They are completely different entities. Transactions in a blockchain are neither of those things: the transactions themselves are a collection of messages passed between some parties. The mechanism that models how transactions are made can be modeled by a state machine, though (as it is an algorithm). $\endgroup$
    – Shaull
    Mar 3, 2021 at 12:49
  • 2
    $\begingroup$ I suggest you post a new question, and give details about the bitcoin scenario you have in mind. I think you may have abstracted it too much, and the answers for this question may be entirely irrelevant to what you're looking for. $\endgroup$
    – Shaull
    Mar 3, 2021 at 14:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.