In a thourough article, Tripadvisor iOS principal engineer Ben Sarrazin described their journey toward adopting The Composable Architecture (TCA) for their existing iOS app, moving away from the Model-View-ViewModel-Coordinator (MVVM-C) architecture.
Sarrazin explains that the decision to move away from MVVM-C was driven by several factors, all tied to increasing app complexity and a growing team. One of the pain points was navigation:
Perhaps the most painful aspect of our MVVM-C implementation is the navigation structure — or more accurately, the lack of one. Our coordinators can launch any other coordinator, creating a web of navigation possibilities that is nearly impossible to document or reason about.
For example, this complexity became evident when an anonymous user visiting the site attempted an action requiring authentication. Even in such a common scenario, the MVVM-C navigation involved numerous coordinators, view models, and event mappers, making the codebase hard to understand and modify.
Another challenge stemmed from the coordinators’ reliance on UIViewControllers, which added complexity and required using Combine as a communication layer between SwiftUI and UIKit.
Debugging Combine-based event chains proves exceptionally difficult, especially when they traverse multiple coordinators and are composed of several layers of publishers and operators.
TCA, by contrast, promised several advantages, such as seamless integration with SwiftUI, robust testing capabilities, and improved composability. The Tripadvisor team also valued TCA’s evolution and maturity, along with its high-quality documentation and support.
To handle the migration, the Tripadvisor iOS team adopted a bottom-up approach. They began by identifying view models without children and replacing them with TCA stores, then gradually worked their way up to parent view models.
A similar “leaf-to-root” strategy was applied to navigation elements, but with a twist. In fact, since TCA requires centralized, state-driven navigation, coordinators were not replaced one-to-one. Instead, parent coordinators assumed the navigation responsibilities of their children. This ultimately resulted in a single source of truth for navigation: a global router implemented as a TCA reducer.
This navigation consolidation represents perhaps the most transformative aspect of our migration. Where we currently have dozens of coordinators with overlapping responsibilities and complex interactions, we’ll eventually have a clean, state-based navigation system that’s both more powerful and significantly easier to understand.
The migration required a complete mindset shift, explains Sarrazin, and came with some challenges. One key insight was that replicating the existing feature hierarchies in TCA wasn’t always the best approach. Instead, the team learned to take into account the implications of sending actions between parent and child components, which can lead to excessive bidirectional communication. A better pattern, they found, was to centralize shared behaviors in parent components where possible.
Another challenge arose when too many actions were dispatched in a short time span, for example, while scrolling through a list. To address this, the team found it effective to debounce high-frequency inputs and minimize the number of actions sent to the store, favoring simple state updates within reducers instead.
An area where TCA also brought many benefits was testing, helping reduce test brittleness.
We found that tests written with TCA’s TestStore provided much stronger guarantees about application behavior. A test that passes gives us high confidence that the feature works as expected, which wasn’t always true with our previous testing approach, especially with the heavy dependency on Combine and schedulers.
Additionally, the team found that TCA tests often served as a form of design feedback: when a test became hard to read or write, it was usually a sign that the underlying code could be improved.
Overall, the migration proved very effective, according to Sarrazin. His article offers many valuable insights that go beyond what can be covered here. Do not miss it if you’re interested in the full detail.