← Questions
Design the API layer of an Android app with MVVM
0
I was asked this
No reports yet. Sign in to say where you were asked it.
A system design interview question asked in OpenAI's technical screen (coding), last asked May 2026. It tests android, mobile and architecture.
Design the client-side architecture an Android app uses to call its backend API, following MVVM. Walk from the HTTP client up through repositories and view models to the screen, say what each layer owns, and trace one request from a tap to pixels and back, including threading, cancellation, errors and loading.
Requirements
- Functional: screens that load data from the API, show loading, content, empty and error states, refresh and retry; a navigation step from a list to a detail screen.
- Non-functional: no work on the main thread; requests cancelled when the screen goes away; state survives configuration changes such as rotation; testable layers; works for both older View/Java screens and Kotlin/Compose screens.
Clarifying questions
- Kotlin coroutines and Flow, or a Java codebase with callbacks or RxJava? Compose, Views, or both?
- Is offline support or caching required?
- How are auth tokens obtained and refreshed?
- One module or a modular app with feature modules?
What a strong answer covers
- Layers: an HTTP client (OkHttp, Retrofit) with interceptors for auth and logging; a data source; a repository that hides network versus cache and maps DTOs to domain models; optional use cases; a
ViewModelexposing state; the UI rendering it. - The request lifecycle:
viewModelScopecoroutines on an IO dispatcher, results back on the main thread, cancellation when theViewModelis cleared, timeouts and retries. -
ViewModellifetime across rotation and process death (SavedStateHandle), and how a Java/View screen and a Compose screen both observe it (LiveDataorStateFlow,collectAsStateWithLifecycle). - UI state as one sealed type (
Loading,Content,Empty,Error) plus one-off events (toasts, navigation) kept separate from state. - Errors mapped once in the repository into typed results the UI can show; caching with a single source of truth (Room) when offline matters.
- Navigation passing ids, not objects; dependency injection (Hilt) so each layer is tested with fakes.
Follow-ups
- Two screens need the same data: how do you avoid fetching it twice?
- Add paging for a long list.
- The token expires mid-request: where does refresh happen, and how do concurrent requests wait for it?
- How do you test the
ViewModeland the repository?
Where it's asked
- OpenAI · Technical screen: coding · Last asked May 202660 min · One problem in three to five growing parts filling the hour, usually in CoderPad; ML roles get a Colab notebook with autocomplete off · No AI assistants or autocomplete; documentation is fine
What it tests
android · mobile · architecture · mvvm
No official answer yet. Draw yours on the right; publish it and it shows under Community.
Nothing published yet. Publish your canvas and it shows here for others to open and remix.
Draw your answer hereBoxes, arrows and notes, saved for you to come back to.Sign in to start drawing
