← All posts
databasesstatetransactionscomputer science

Burritos, Rollbacks, and State

What a bad burrito taught me about state, transactions, and rollbacks.

You know you’ve made a terrible decision when you start to wish life had a big undo button you could hit to reset everything back to the moment right before you messed up.

That was me on April 17th when I bought a burrito for $15 and got a sad piece of rolled up diced chicken and queso, a cup of diluted Dr Pepper, and a mistake from the cashier that meant I had to wait an extra five minutes to get it fixed. And afterwards, I was still hungry.

State, Stateless and Stateful

Before I walked to that burrito station, I was hungry and $15 richer. After the purchase, I was disappointed and $15 poorer. Systems call this state. It’s just the “memory” of a system at a specific moment.

My first option was to get a pizza. The other was to go to the dining hall for a regular school lunch. But I chose the burrito instead.

What if that situation worked like a stateless system? I could start every decision fresh, forgetting any prior choices I made or how they turned out. I wanted that. I wanted to walk back to the food court like nothing happened and maybe get a pizza instead.

But real life is painfully stateful. My bank account remembered. My stomach remembered. I couldn’t just “refresh the page” and reset my hunger or my balance.

Transactions and Rollbacks

I could treat the whole situation like a transaction: pay the cashier, get my food, and then enjoy it. If I didn’t like what I got or wasn’t full afterwards, I’d want to roll back to the last 60 seconds before I chose the burrito.

In databases, transactions are supposed to either fully succeed or not happen at all. When something goes wrong, you can roll everything back like it never happened. You also roll back when a system ends up in a bad state.

In this case, I needed to be satisfied. I wasn’t. This was a failed transaction, and I really could’ve used a rollback.

Fix Forward

When rollback isn’t an option, systems fix forward. They accept the bad state and move on by building something better from it. In my case, that meant accepting the loss and figuring out what comes next. That could’ve been going back to get a pizza. At the very least, I learned not to commit too early next time.

At least if life had a save point, not even a full reset, I could go back to the moment I was standing in the food court with all my options still available.

Further Reading

← Back to all posts