Why Distributed Systems Are Really Search Problems in Disguise
Hatched by Kai Nguyen
Jun 30, 2026
11 min read
2 views
86%
The hidden question behind every broken transaction
What if the hardest problem in microservices is not consistency, but decision making under uncertainty?
At first glance, distributed systems look like an engineering problem about databases, APIs, and retries. But the deeper challenge is stranger and more interesting: every multi step business process is really a journey through a landscape of possible states. Some states are good, some are terminal, some can be recovered from, and some force you to backtrack. In that sense, building a reliable service architecture is closer to solving a search problem than to executing a single transaction.
That framing changes everything. Instead of asking, “How do I make all services behave like one database?” the better question becomes, “How do I guide a system through a space of possible outcomes so it reaches a valid end state, even when parts of the journey fail?”
This is where the Saga pattern and state space search unexpectedly meet. One is a software architecture for coordinating local transactions. The other is a classic way of reasoning about problems by exploring successive states. Together, they reveal a powerful idea: distributed consistency is not about eliminating branching, but about managing it intelligently.
From one big transaction to a landscape of possibilities
Traditional ACID thinking encourages a comforting illusion: if the transaction is atomic, then reality is simple. Either everything succeeds or everything rolls back. But microservices break that illusion because each service owns its own data and its own database. The system is no longer one machine with one perfect point of control. It is a network of independent actors, each making local decisions.
That means a business process like placing an order is not a single operation. It is a chain of states: inventory reserved, payment authorized, shipment prepared, notification sent. At every step, the system can move forward, fail, pause, or compensate. The process is not linear in the intuitive sense. It is a state machine with branches.
State space search gives a useful lens here. In search problems, you do not assume the solution is directly reachable from the start. You define the possible states, the operations that move between them, and the goal state you want to reach. Then you search through the space of possibilities until you find a valid path. A distributed business workflow works the same way, except the “search” is partly embodied in runtime behavior, failures, retries, and compensating actions.
Consider an online purchase:
- Reserve inventory.
- Charge payment.
- Create shipment.
- Send confirmation.
If shipment creation fails after payment succeeds, the system has entered an undesirable state. The question is not whether failure exists, because it does. The question is what the system does next. A Saga answers by defining a compensation path: refund the payment, release inventory, and return the process to a stable state.
That is not just error handling. It is controlled traversal of a state space.
A Saga is less like a transaction and more like a guided expedition through possible outcomes, where every step forward also defines what it means to step back.
The real unit of design is not the service, but the state transition
Most teams think in terms of services: payment service, inventory service, shipping service. That is useful for ownership, but dangerous for system design if you stop there. The deeper unit is not the service itself. It is the transition between system states.
In a Saga, each local transaction produces a new state. The important question becomes: what invariants hold after that state change, and what compensations are available if the next transition fails? This is precisely the kind of reasoning used in state space search, where every action must be understood in terms of the states it can reach.
A useful mental model is to picture a board game. Every move changes the board. Some moves are irreversible, some are reversible, and some create traps that are expensive to escape. Good players do not just ask, “Can I make this move?” They ask, “What positions does this move make available, and which ones become impossible afterward?” Distributed systems demand the same discipline.
This leads to an important insight: local success is not the same as global success.
A payment service may succeed perfectly while the overall order process becomes invalid because shipping cannot proceed. A shipment service may succeed while the customer has been charged for an item that can no longer be delivered. The system is healthy only if the chain of states as a whole remains manageable.
That is why the Saga pattern uses two essential ideas:
- Local transactions: each service commits only its own state.
- Compensation transactions: if the path becomes invalid, earlier steps are reversed through domain specific undo actions.
In search terms, local transactions are forward operators. Compensations are not magic rollback. They are reverse operators that exist only because the system designer has explicitly modeled them.
This is a major conceptual shift. Many engineering failures happen because teams treat compensation as a cleanup detail rather than as part of the core state model. But if your architecture is really a search through possible states, then reversibility is part of the problem definition, not an afterthought.
Orchestration and choreography are two ways of exploring the same search space
There are two common ways to implement a Saga: orchestration and choreography. On the surface, they look like coordination styles. At a deeper level, they represent two philosophies of search.
In orchestration, a central controller directs each step. It knows the desired path, asks services to perform their actions, and decides when to compensate. This resembles a search algorithm with an explicit evaluator or planner. The orchestrator maintains a map of the process and chooses the next move based on the current state.
In choreography, services emit events after completing local work, and other services react. There is no single conductor. Instead, the system explores the state space through distributed reactions. This resembles a decentralized search process, where the next possible state emerges from local rules rather than a global plan.
Neither approach is inherently superior. The real difference is about where knowledge lives.
Orchestration works well when the business process is complex, exception handling matters, and you want a clear place to reason about the workflow. Choreography works well when you want loose coupling, evolving behavior, and simple local rules. But both approaches still face the same truth: the system is navigating a graph of states, not executing a perfect script.
Here is a concrete analogy. Imagine airport baggage handling.
- In an orchestrated version, a central operations desk tracks each bag and assigns tasks to scanning, routing, and loading teams.
- In a choreographed version, each station publishes events like “bag received” or “bag routed,” and the next station responds automatically.
In both cases, the bag can be delayed, misrouted, or lost. The important question is how the system detects failure, how it recovers, and whether it can still reach the goal state of “bag delivered to the correct plane.”
The search lens helps explain why hidden complexity emerges in choreography. Because no single component sees the whole path, the state space becomes distributed across services. That can be elegant, but it also makes reasoning harder. If nobody owns the full picture, then debugging becomes an exercise in reconstructing the path after the fact.
Orchestration reduces ambiguity by making the search path explicit. Choreography reduces central control by letting the path emerge. The tradeoff is not just technical. It is epistemic. It asks: who knows enough to make the next decision?
Compensation is not rollback, it is path repair
One of the most important mistakes in distributed systems is to imagine compensation as a weaker version of rollback. That is misleading. Rollback assumes the world can be returned to a prior state as if nothing happened. Compensation is more realistic and more creative. It acknowledges that the system has already changed, external side effects may exist, and the only way forward is to repair the path.
This is exactly where the search analogy becomes valuable. In many search problems, if a branch leads to a dead end, you do not erase history. You backtrack, prune, and continue from a different point. But in real systems, backtracking often requires semantic repair rather than literal reversal.
For example:
- If a warehouse has packed an item and payment fails, you may not “unpack” it. You restock it or mark it for redistribution.
- If a promotional email has already been sent and the order later fails, you cannot unsend it. You may need a follow up apology or a customer support workflow.
- If a taxi dispatch has been triggered, a cancellation may require a separate cancellation notice, not a perfect undo.
Compensation, then, is domain aware state repair. It is the design of meaningful reverse moves in a world where perfect reversal is impossible.
This is why the best Saga implementations are not just technically correct. They are semantically honest. They ask, “What does it mean to reverse this step in the real business domain?” That question is much harder than writing a database transaction, but it is also much more powerful. It forces teams to define the business meaning of failure.
If a state transition cannot be cleanly reversed, the real design question is not how to hide that fact, but how to model it.
That may sound abstract, but it has direct practical consequences. Many incidents happen because teams build forward paths without designing reverse paths. They assume success is the default and failure is rare. In a distributed system, failure is not rare. Failure is a first class state. So is partial completion.
Once you accept that, compensation stops being a cleanup task and becomes part of the architecture of truth.
A practical framework: design your business flow as a search graph
If distributed workflows are state space problems, then they should be designed like state space problems. That does not mean pulling in formal AI methods everywhere. It means adopting a sharper way of thinking.
Here is a simple framework that teams can use.
1. Define the valid states
Start by listing the meaningful states of the business process, not just the technical events. For an order flow, those might include:
- Draft order
- Inventory reserved
- Payment authorized
- Shipment created
- Order completed
- Order canceled
- Order partially completed and compensating
This helps reveal what the system is actually trying to reach.
2. Define the transitions
For each step, ask what action moves the system from one state to the next. Also ask what can block that transition. This makes the dependencies visible.
3. Define the reverse moves
For every forward step that has side effects, define the compensating action. If no compensation exists, be honest about it. Not every action is reversible, and pretending otherwise creates brittle systems.
4. Choose the coordination style based on observability
If the business process has many branches, exceptions, or regulatory constraints, orchestration may be the safer choice because it makes the state path easier to inspect. If the process is simple, highly decoupled, and event driven by nature, choreography may be enough.
5. Treat uncertainty as expected behavior
Do not design the happy path and hope everything else is edge cases. In distributed systems, the unhappy path is part of the design space. Your job is to make it navigable.
This framework is valuable because it shifts the conversation from infrastructure to semantics. It asks not just what technology to use, but what kinds of state changes your business can survive.
Key Takeaways
- Think in states, not steps. A microservice workflow is a graph of possible states, not a straight line of commands.
- Model compensation as domain repair. Undoing a distributed action usually means creating a meaningful corrective action, not erasing history.
- Choose orchestration or choreography based on visibility. Use orchestration when you need a clear global view, choreography when local autonomy matters more.
- Design reversibility up front. If a step cannot be compensated, that constraint should shape the architecture before implementation begins.
- Treat failure as part of the path. In distributed systems, reliability comes from navigating uncertainty well, not pretending uncertainty is absent.
The deeper lesson: systems do not fail in the abstract, they fail in a state
The most useful way to unify these ideas is to stop thinking of distributed systems as machines that either work or break. They are better understood as systems that move through a space of states, each with its own obligations, opportunities, and escape routes.
That reframing changes the role of architecture. Architecture is not merely the arrangement of services. It is the design of a navigable reality. A good Saga does not eliminate complexity. It makes complexity intelligible. A good state space model does not guarantee success. It reveals the shape of failure so success becomes achievable.
This is the surprising connection between distributed transactions and search: both are about reaching a goal without assuming the route will be clean. Both require knowing what counts as progress, what counts as a dead end, and what actions restore viability. Both reward systems that are designed to reason, not merely react.
The next time you look at a workflow across services, do not ask only, “How do I make it atomic?” Ask something deeper: What is the state space this system must survive, and how will it find its way home when the path branches?
That question is bigger than microservices. It is a philosophy of building systems that can live in reality.
Sources
Hatch New Ideas with Glasp AI 🐣
Glasp AI allows you to hatch new ideas based on your curated content. Let's curate and create with Glasp AI :)
Start Hatching 🐣