Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 1

Symptoms of Poor State Management

Recommended resources

Welcome to the first lesson of your course on designing state engines. Your goal is to build robust systems that can manage the lifecycle of real-world entities, like an eCommerce shipment. Before we dive into designing solutions, it's crucial to understand the problems we're trying to solve. As you requested, we'll start by exploring the "real-world pain" that motivates a more disciplined approach.

In this lesson, we will focus on identifying the common symptoms of poorly managed state in complex systems. You'll learn to spot the tell-tale signs of trouble, such as orders that get stuck in limbo or different parts of a system having conflicting information about the same entity. Understanding these symptoms is the first step toward designing systems that are reliable, predictable, and easier to manage.

The Challenge of Distributed Systems

In a simple application with a single database, managing state is relatively straightforward. If you need to update an order and its corresponding inventory in one go, you can wrap both operations in a database transaction. This ensures that either both actions succeed or both fail, keeping your data consistent.

However, modern applications, especially in eCommerce, are rarely that simple. They are often built as a collection of specialized, independent services—a pattern known as a microservice architecture.

This diagram shows a common microservice architecture. A user request comes through a load balancer and an API gateway, which then routes it to different services (A, B, C). Each service often has its own dedicated database and can communicate with others through an event bus.

While this architecture has many benefits, it introduces a significant challenge: a single business process, like "placing an order," now involves communication across multiple services and multiple databases. For instance, the Order Service, Inventory Service, and Payment Service all need to coordinate. When the state of an entity (like our order) is scattered across these services, things can go wrong in subtle and painful ways.


Symptom 1: Conflicting Statuses

One of the most common and damaging symptoms of unmanaged state is when different services hold conflicting information about the same entity.

Imagine a naive implementation of an order process. A customer clicks "Place Order":

  1. The Order Service creates the order and marks its status as Awaiting Payment.
  2. The Order Service then makes a direct call to the Payment Service to charge the customer's credit card.
  3. If the payment is successful, the Order Service updates the order's status to Paid.

What happens if the call to the Payment Service times out? The Payment Service might have successfully charged the card, but because the network connection was lost before it could send a success response, the Order Service assumes it failed.

The result is a data inconsistency:

  • The Payment Service database shows the customer has been charged.
  • The Order Service database shows the order status is still Awaiting Payment or even Payment Failed.

This situation is often called an indeterminate state. The system as a whole doesn't have a clear, single truth. This leads to very unhappy customers who have been charged for an order that the system believes has failed.

The following article provides an excellent analysis of this exact problem.

Distributed transactions in microservices: failure design

This article from Zühlke Engineering explains why directly chaining service calls is fragile and leads to serious data consistency problems. It uses an Ordering and Payment system as its core example.

Please read the introduction and the first two main sections. Start from the beginning and read down to the subheading "A Robust Strategy". Focus on these parts: The example of the Ordering and Payment system to understand the components. The description of the "naive implementation" and its three major flaws. Pay close attention to the paragraph that explains what happens when a timeout occurs, leading to a transaction being in an indeterminate state.

To see another clear breakdown of this problem, the following video explains a similar scenario involving a subscription service.

Do you need a Distributed Transaction? Working through a Design Problem

In this video, "Do you need a Distributed Transaction?", Derek Comartin from CodeOpinion walks through a design problem where an Order service and a Payment service need to stay consistent.

Watch the first four and a half minutes, from the beginning of the video. Pay attention to the specific failure point he describes, where the Payment service's database is updated, but the Order service's isn't. This results in orders that look like they're unpaid even though the customer's balance has been reduced.


Symptom 2: Cascading Failures and "Stuck" Orders

When one service fails or slows down, it can trigger a chain reaction, causing other services that depend on it to fail as well. This is known as a cascading failure.

In this illustration, Service Y has failed. Because services T and U depend on it, they can no longer function correctly. Furthermore, Service Y's failure might have been caused by its own dependency, Service A, failing, creating a widespread outage.

In our eCommerce example, if the Payment Service is slow, the Order Service might be stuck waiting for a response. While it's waiting, it could be holding onto resources (like database connections or memory). If enough order requests get stuck, the Order Service itself could become overwhelmed and stop responding, affecting every customer trying to place an order.

An order that ends up in an indeterminate state is often called a "stuck" order. The automated system doesn't know how to move it forward or backward, so it just sits there until a human intervenes.


Symptom 3: The Pain of Manual Workarounds

When automated processes fail due to inconsistent state, the burden falls on people. This creates hidden operational costs that can cripple a business even if the website technically "still works."

  • Customer Support: Your support team is flooded with calls from confused customers. "I was charged, but my order was cancelled!"
  • Engineering: Developers have to spend hours digging through logs and manually inspecting databases to figure out what happened and patch the data. This is time they aren't spending on building new features.
  • Operations: Teams create complex manual processes to fix stuck orders, which are slow, expensive, and prone to human error.

Over time, teams can become accustomed to this pain and start to see it as normal. This normalization of workarounds is a strong signal that the underlying system architecture is flawed.

The following article does a fantastic job of translating these technical issues into the language of business operations.

12 Signs Your B2B eCommerce Platform Slowing Your Growth!

This article from Reveation.io is geared toward business leaders, but it provides a sharp diagnosis of the symptoms of poor system design from an operational perspective.

Please read the first half of the article, from the start down to the section "Score Your B2B eCommerce Platform Assessment". As you read, focus on: The table that connects what teams get used to with the deeper platform problems it signals. Question 4 under "Data, ERP, and Integration Reality," which directly addresses the symptom of disagreeing statuses across systems. Question 11, which highlights the disconnect between internal workarounds and the customer experience.

These symptoms—conflicting statuses, stuck entities, and reliance on manual intervention—all point to the same root cause: the lack of a central, authoritative process for managing an entity's state across a distributed system.


Conclusion

In this lesson, we explored the painful and costly symptoms that arise from poorly managed state. You learned to identify three key signs of trouble:

  • Conflicting Statuses: Different services have different versions of the truth, leading to inconsistencies like an order being both "Paid" and "Cancelled."
  • Stuck Orders and Cascading Failures: Entities get stuck in an indeterminate state, requiring manual intervention, and failures in one service can bring down others.
  • Manual Workarounds: Teams develop costly and inefficient manual processes to compensate for the system's shortcomings, hiding the true cost of the problem.

These issues are not just abstract technical challenges; they cause real business damage in the form of lost revenue, frustrated customers, and wasted operational effort. Recognizing these symptoms is the critical first step.

In our next lesson, we will begin our journey toward the solution. Now that we understand the chaos of unmanaged state, we will introduce the core concepts of a much more orderly world: the finite state machine. We will define what makes a good "state" and begin modeling the lifecycle of our eCommerce shipment.