As mobile apps become increasingly complex, it can become difficult to reason about the code. Luckily for developers, state machines can help. They are a mechanism to describe which UI components are active and how transitions between states occur. In this post, we’ll cover a brief overview of how state machines can help mobile teams, including:

  • The benefits of state machines
  • The disadvantages of state machines
  • How state machines can help mobile teams as they scale

You can also check out our eBook for a deep dive on how several design patterns from gaming can benefit your mobile team today!

The benefits of state machines

Here are three of the main benefits that state machines can provide mobile teams.

Reduce complexity

The purpose of state machines is to reduce complexity across the codebase. This focus makes state machines ideal for complex user flows like login, checkout, and cart management. You can even assign different state machines for different purposes that address varying degrees of complexity—either micro or macro-level processes. For example, one state machine could handle the active elements and valid transitions at the individual screen level (e.g. creating/editing user profiles) while another could handle behavior at the global level (e.g. navigation across screens).

Simplify repetitive app elements

State machines can also simplify repetitive app elements that would otherwise devolve into excessive spaghetti code. Instead of relying on UX patterns to dissuade incorrect behavior (e.g. applying gradients over disabled controls, loading a modal that blocks other UI elements), state machines let you control exactly which actions a user can take at each step. Moving away from hacks and towards disciplined state machines makes it much easier to onboard new team members who can immediately understand your code.

Increase debugging visibility

With state machines, you can easily log and see the transitions users have taken into and out of any given state. This makes state machines effective debugging tools for your QA team, enabling them to rapidly reproduce issues so your engineers can fix them faster. Instead of guessing and checking for every possible edge case, your team knows exactly which flows to consider when testing and debugging.

The disadvantages of state machines

Here are three of the main disadvantages to consider before implementing state machines into your mobile app.

No built-in tooling

While gaming platforms have built-in support for state machines, current mobile platforms do not. This means your mobile team will need to create their own tooling systems. This isn’t as onerous as it seems at first, however. It will prompt your team to ensure the state machine is optimized for your use case, and to add specific debugging logic, which is key for growth and scale!

State restrictions can be difficult to break later

When your needs do inevitably change as you scale your app, it can be difficult to break the state transitions you have built into your mobile app. You’ll code your current user flows into your state machine. If that flow changes later, you’ll need to unpack the flow and retest transitions. This can actually be an advantage. Because your team has to be accurate about transitions and the user paths through your app, state machines will encourage your team to make sure the initial plans are solid so they can avoid costly refactors down the line.

Dead-end states are worse than crashes

Another disadvantage is you can end up with dead-end states, which are worse than app crashes from a user experience perspective. Simply put, a dead-end state refers to when users get stuck on a screen they cannot get out of. There is no valid transition back to a functioning part of the app, so users are left to rage tap and abandon the app. In order to prevent these from happening, work with your team to ensure there is always a path out of every state.

How state machines can help mobile teams as they scale

Using shared design patterns like state machines makes it easier for your entire team to be more productive:

  • Team members can more easily talk about the codebase.
  • New hires can onboard faster.
  • Developers can reduce the surface area for bugs.
  • QA teams can be more efficient when building and executing test plans.
  • The codebase becomes more extensible by removing one-off spaghetti code solutions.
  • Tracking down the cause of poor user experiences can be easily done by following states and transitions.

State machines free up valuable time that can be used to grow your mobile app. Mobile is an incredibly competitive space, and teams need to innovate rapidly while delivering stellar user experiences to achieve continued success. By streamlining communication, testing, debugging, and coding, your team can become more efficient at building rock-solid features that boost engagement, retention, and revenue. To learn more about how state machines and other design patterns from gaming can benefit your mobile team, download our eBook. It’s filled with best practices that will help your team overcome the challenges of scaling your mobile app.

How Embrace helps mobile teams

Embrace is a data driven toolset to help mobile engineers build better experiences. We are a comprehensive solution that fully reproduces every user experience from every single session. Your team gets the data it needs to proactively identify, prioritize, and solve any issue that’s costing you users or revenue.


Request a demo and see how we help teams set and exceed the KPIs that matter for their business!