MVI Pattern Interview Questions
ARCHITECTURE › Patterns
What is MVI, and how is it different from MVVM?
What a strong answer covers: Model-View-Intent: the user's actions are modelled as intents (events), a reducer takes the current state and an intent and produces a new immutable state, and the view renders that single state. MVVM is looser: the ViewModel can expose several state streams and has arbitrary methods. MVI enforces one state object and one entry point, which makes state transitions explicit.
What is a reducer, and why should it be a pure function?
What a strong answer covers: A reducer is (State, Intent or Result) -> State. Pure means no side effects and the same inputs always give the same output, so state transitions are predictable, easy to unit test without mocks, and can be logged or replayed. Side effects like network calls happen elsewhere and feed results back in as new events.
How are side effects handled in MVI, like network calls, navigation and showing a toast?
What a strong answer covers: Async work runs outside the reducer (in a middleware, processor or the ViewModel), and its results are dispatched back as events that the reducer turns into state. One-off UI effects like navigation or a snackbar are either part of state and cleared after handling, or sent through a separate effect channel. Frameworks like Orbit or MVIKotlin formalise this.
What are the downsides of MVI, and when is it overkill?
What a strong answer covers: Boilerplate (intent, state, effect and reducer types per screen), a learning curve, a big state object that can cause extra recomposition, and awkward handling of one-off events. It's overkill for simple screens like a static settings page. It pays off on complex screens with many interacting inputs, or where reproducibility and debugging state transitions matter a lot.
How would you handle a race in MVI where two async results arrive out of order, for example search results for an old query arriving after the new one?
What a strong answer covers: Cancel the previous work when a new query comes in (flatMapLatest or keeping a Job and cancelling it), tag each request with the query or a request id and have the reducer ignore results that don't match the current state's query, and model loading per request. A strong answer notes that MVI makes this explicit because the reducer can compare the incoming result with the current state.