MVVM & Unidirectional Data Flow Interview Questions

ARCHITECTURE › Patterns

What is MVVM, and what does each part do in an Android app?

What a strong answer covers: Model is the data and business logic (repositories, use cases); View is the Activity, Fragment or composable that renders state and forwards user events; ViewModel holds UI state for a screen, exposes it as observable state (StateFlow), handles events by calling the model, and survives configuration changes. The View observes the ViewModel; the ViewModel never references the View.

What is unidirectional data flow, and why is it preferred?

What a strong answer covers: State flows down from the ViewModel to the UI, and events flow up from the UI to the ViewModel, which updates state. There's one source of truth for each piece of state, changes happen in one place, and the UI is a function of state. That makes bugs easier to trace, state easy to test, and avoids the UI and ViewModel disagreeing.

Why did you choose your current architecture? MVVM vs MVI vs MVP: which would you pick and why?

What a strong answer covers: MVP has a presenter that calls back into a view interface, tightly coupled and lifecycle-fragile. MVVM exposes observable state that the view subscribes to, fits Jetpack and Compose well, and is Google's recommended baseline. MVI adds a single immutable state and explicit intents reduced into new state, giving predictability at the cost of boilerplate. A strong answer picks based on team size and screen complexity, and justifies with trade-offs rather than preference.

Should a ViewModel expose one UiState object or several separate flows? What are the trade-offs?

What a strong answer covers: A single data class state is consistent (no impossible combinations, one place to render and test) and easy to restore, but every change emits a whole new object and can recompose more. Several flows are fine when the values are unrelated and update at very different rates. A common approach is one UiState built with combine from separate sources, with fields grouped sensibly and sealed types for loading, content and error.

Walk me through how a button tap becomes a database write and an updated screen in a well-structured MVVM app, including where threading, errors and loading state are handled.

What a strong answer covers: The composable calls onSaveClicked(), passed down from the screen. The ViewModel launches in viewModelScope, sets a saving state, and calls a use case or repository suspend function. The repository is main-safe, switches to IO, and writes to Room. Room's Flow re-emits the new data, which the ViewModel maps into UiState with stateIn, and the UI recomposes. Errors are caught in the ViewModel (or returned as a Result) and turned into an error message in state; CancellationException is never swallowed.

Back to MVVM & Unidirectional Data Flow