Repository & Data Layer
ARCHITECTURE › Patterns
How repositories become the single source of truth abstracting network, cache, and database.
The data layer is a near-guaranteed interview topic because it tests whether you can keep business logic and data access out of UI and ViewModels. Interviewers probe how repositories abstract data sources, why they expose immutable Flows, where caching and conflict resolution live, and how you map DTOs to domain models. Strong answers distinguish one-shot from streaming APIs and explain main-safety and single source of truth.
What this covers
- Repository responsibilities: expose data, centralize changes, resolve conflicts, abstract sources, hold business logic
- Single source of truth and why a local database is recommended for offline-first
- Exposing one-shot operations as suspend functions vs ongoing changes as Flow
- Mapping DTOs/network models to immutable domain models and why
- Where caching lives (in-memory vs persistent) and main-safe threading with dispatchers
- Operation scope: UI-oriented, app-oriented, and business-oriented (WorkManager) lifecycles
Study this topic
- Repository & Data Layer explained: the guided lesson
- 14 practice quiz questions
- 9 revision flashcards
- Repository & Data Layer interview questions and answers