[25] Systems Design - Chapter 3 Flashcards

(48 cards)

1
Q

What are the 3 principles of Mobile architecture

A
  1. DRY principle
  2. Separation of concerns principle
  3. SOLID Principle
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is DRY?

A

Don’t Repeat Yourself

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Explain Separation of concerns

A

It improves readability, facilitates testing, and enables teams to evolve features independently.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the SOLID principles?

A

Five core ideas that guide design of flexible and maintainable object-oriented systems.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the five SOLID principles?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How is a layered architecture in mobile?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What characteristics has the Domain Layer?

A

This layer is the most isolated and platform-independent part of the architecture.

Not includes:
- Doesn’t know where the data comes from (local database or remote server)
The responsibilities include:
- Encapsulating business logic in use cases or interactors.
- Defining domain models.
- Coordinating flows and outcomes between UI and data layers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the benefits of layered design? (5 benefits)

A

Testability: Each layer is testable in isolation without deep mocks or side effects.

Modularity: Features evolve independently with well-defined ownership.

Scalability: Teams work in parallel on layers without stepping on each other’s code.

Maintainability: UI and logic changes remain isolated, reducing regression risks.

Flexibility: Logic written in the domain layer can be reused across iOS, Android, and desktop.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What techniques can your team use to enforce boundaries across teams?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What mobile architecture patterns do?

A

Mobile architectural patterns are structured design approaches that help manage the complexity of building scalable and maintainable mobile apps.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Most commonly used patterns include:

A

MVC (Model-View-Controller)
MVP (Model-View-Presenter)
MVVM (Model-View-ViewModel)
MVI (Model-View-Intent)
VIPER (View, Interactor, Presenter, Entity, Router)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Who fetches data on the MVC architecture?

A

The model.
This is all about our app’s data and business logic. It knows how to fetch data from the server, for example, a list of restaurants from an API.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does the controller in MVC?

A

This is the middleman that coordinates everything. It triggers the data fetch, listens for results, and passes data to the View.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

When MVC shines?

A
  • Very simple screens with low interaction.
  • Prototypes where speed matters more than maintainability.
  • Developers are working solo or in small teams.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does MVP (Model - View - Presenter) does differently?

A

The Presenter takes over most of the logic. It talks to the Model to get data, transforms it into a format the View can use, and keeps the View as simple as possible. The View no longer thinks (how to display); it just displays.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is the difference between the presenter in MVP and the controller in MVC?

A

The presenter is platform independent and we can reuse presenters across Views or platforms.

example:

class RestaurantPresenter(val view: RestaurantView, val service: RestaurantService) {
    fun onSearchQuery(query: String) {
        view.showLoading()
        service.searchRestaurants(query) { result ->
            when (result) {
                is Success -> view.showRestaurants(result.data)
                is Error -> view.showError("Could not load results")
            }
        }
    }
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

Pros and Cons of MVP

A

Pros: Great choice for medium-complexity screens with much interaction, like our search-enabled restaurant list. We can even reuse Presenters across Views or platforms.

Cons: One downside of MVP is that the Presenter can get big

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What are the responsibilities of MVVM?

A

MVVM is different because the View and ViewModel are connected through reactive bindings. The ViewModel changes the data, and the View just watches and reacts. No back-and-forth or manual syncing is needed.

Model: Manages data and business logic (same as before).
View: Displays the UI and observes state changes.
ViewModel: A middle layer that holds the UI data and exposes it in a form that the View can easily use, often using observable data streams like LiveData or StateFlow.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

MVVM advantages?

A

Reactive by design: Great for live data like order tracking or real-time updates.

Cleaner separation: ViewModel contains all presentation logic, View only shows data.

Testable: ViewModels are easy to test without dependency on Android or iOS UI classes.

Resilient: Survives configuration changes like rotation, because the ViewModel is life cycle-aware.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

MVVM Cons?

A

The ViewModel can become bloated if overloaded with multiple responsibilities: UI logic, state mapping, user interactions, and API coordination.

While it’s better than the MVP, it still doesn’t give us clear state machine-like control over the app.

21
Q

What is MVI?

A

Model View Intent.

MVI is centered around one big state object that holds everything our screen needs. Instead of updating different parts independently, the entire UI reflects this immutable state. When something changes, a new state version is created and sent back through the system.

22
Q

Key Roles

A

Intent: These are user actions, like tapping a button, typing text, or pulling to refresh.

Model: Holds the logic for taking an Intent and producing a new state. It knows how to respond to an Intent; it fetches data, handles errors, and returns results.

View: Displays the current state, and nothing else.

State: A snapshot of everything the View needs now (e.g., loading = true, list = empty, error = null).

23
Q

Benefits of MVI?

A

Predictability: Every change is intentional and traceable, with no hidden side effects.

Debugging: We can replay a history of states to see what happened.

Testability: The reducer is a pure function, super easy to write unit tests for.

Fit for reactive UIs: Works brilliantly with Jetpack Compose, Flutter, React Native, etc.

24
Q

Cons of MVI?

A

writing a lot of sealed classes, reducers, and state definitions, even for a simple screen. The immutable objects are more memory-heavy, and MVI feels abstract to a team new to data flow or patterns.

25
What are the five layers of VIPER?
View: Displays information to the user and sends input to the Presenter. Interactor: Contains the business logic (e.g., fetching, caching, validating). Presenter: Prepares data for the View; knows when to trigger the Interactor. Entity: Raw data structures like Restaurant, Order, User. Router: Handles navigation between screens (and deep links).
26
How will the following use case work in VIPER? "place order" on Uber Eats app?
The View shows a summary of the cart and a “place order” button. The Presenter listens for the tap and informs the Interactor. The Interactor uses Entities and checks if the cart is valid, applies promotions, and calls the API. On success or failure, the Interactor tells the Presenter what happened. The Presenter formats the result and updates the View. If the order is successful, the Presenter asks the Router to navigate to the order tracking screen.
27
Pros and cons of using VIPER?
VIPER introduces a lot of files. Even a simple screen might require tens of files for each independent module. For small teams, this can feel like overengineering. But for long-term, large-scale apps, VIPER pays off with consistent structure and rock-solid boundaries.
28
Time to observe key differences of mobile architectures
29
What does it means UDF? (Unidirectional data flow)
Unidirectional data flow (UDF) means the application state changes in a single, predictable direction. Instead of components reading and writing state freely, the flow is structured: user actions trigger events (or Intents), which are processed to update a central state, which then updates the UI. This makes the logic more transparent and significantly easier to test or debug. We trigger an action (like clicking a button) that creates a signal (an Intent), which flows into a central system that updates the application’s state. Then the UI re-renders based on that new state. It’s a loop, but a controlled one. The data only moves forward in one direction through that loop, as illustrated below:
30
What is an Intent?
An Intent represents a user’s action or a system-triggered event. It’s a declarative way to say, something happened that should lead to a state change, for example, AddItemClicked(itemId), CheckoutPressed, etc.
31
What is dependency injection?
At its core, DI is about providing an object with the resources it needs (its dependencies) from the outside, rather than having the object construct them itself.
32
What are the three common forms of DI?
Constructor injection: Dependencies are passed in through the class constructor. Field injection: Dependencies are injected directly into class fields. Method injection: Dependencies are passed in through specific methods.
33
How a dependency injector should work?
Here, a centralized dependency injector manages the creation and provisioning of objects, adhering to the inversion of control principle. Each layer, application, activity, and ViewModel is injected with its dependencies based on well-defined scopes: - Application scope for app-wide singletons. - Activity scope for UI logic tied to the activity life cycle. - ViewModel scope for business logic that survives configuration changes.
34
What kind of injector is preferred in mobile apps? and why?
constructor injection is often preferred for its immutability and easier testability.
35
What are the modules that a good app typically falls into?
- App module: This is the entry point of the application, such as, aap/. - Feature module: This module encapsulates functional areas, such as, feature/chat/, feature/feed/, etc. - Core or shared module: These consist of common utilities, network, storage, and design system, such as, core/network/, core/ui/, etc. - Libraries or tools: They contain optional tools or libraries for internal reuse, such as, lib/logger/, lib/analytics/, etc.
36
Notable advantages of a well modulated project?
- Testability via targeted test scopes for isolated modules. - Developer productivity through better isolation and cleaner version control diffs.
37
If you modularize your project but skip dependency injection, what happens?
The app looks modular in structure, but behaves monolithically in practice. Modules declare what they need without dictating how or where those dependencies come from. Instances are reused where appropriate and cleaned up when no longer needed.
38
Three benefits of modularization + dependency Injection.
- Developed and tested independently. - Updated without impacting other parts of the app. - Temporarily disabled or replaced without breaking the system.
39
What is BFF?
Backend For Frontend (BFF)
40
Problems BFF trys to solve?
- Over fetching and under-fetching - Payload inefficiency - Leaked client logic in shared layers. (some platforms may now details of other platforms) - Performance and security (shared APIs become a central point of freagitility)
41
Diff between API Gateway & GraphQL
API gateways serve everyone equally, but understand no one specifically. GraphQL allows clients to specify exactly what data they want, nothing more, nothing less. Is like a buffet.
42
API vs GraphQL vs BFF
43
How can BFF be deployed?
44
Benefits and trade-offs of BFF
Benefit: Improved performance: A BFF can aggregate data from multiple back-end services into a single, optimized response Trade-off: Over-optimization can lead to code duplication across multiple BFFs for different platforms, and performance tuning adds complexity to versioning and payload maintenance. Benefit: Encapsulated back-end complexity: With a BFF, mobile clients interact with a simplified and consistent API that hides the details of back-end systems. Trade-off: This abstraction can create visibility gaps and duplicated logic if multiple BFFs evolve in parallel without coordination. Benefit: Product-centric and autonomous development: BFFs empower frontend teams to define and own APIs that are closely aligned with the mobile product experience. Trade-off: This autonomy increases responsibility; teams must manage back-end-like concerns (auth, validation, error handling), which, without care, can cause service sprawl or fragile implementations. Benefit: Experience-driven APIs: With a BFF, APIs can be crafted around the user experience. For example, a mobile screen for the home feed can be powered by a single endpoint like /api/mobile/home-screen, encapsulating everything the screen needs for better performance and user experience. Trade-off: Designing APIs around UX flows can introduce tight coupling between the frontend and backend. Benefit: Operational separation and focus: BFFs promote a clear separation of concerns by isolating frontend-specific logic into its own service. This leads to cleaner back-end services and allows focused API evolution tailored to mobile UI needs. Trade-off: If the BFF is not designed for high availability and scalability, it can become a single point of failure.
45
What's navigation vs screen flow?
Navigation refers to the way a user moves through an app, from screen to screen, feature to feature, and context to context. Screen flow architecture is the underlying structure that governs these movements. I
46
What are the most common navigation re-entry points?
Notifications. Deep links (e.g., URLs or universal links). Saved app state (e.g., “resume where I left off”). A/B tested flows that branch dynamically.
47
If every screen in your app can be an entry point, should navigation logic be centralized for control or decentralized for flexibility? What architecture allows us to have both?
Navigation logic should be centralized in structure but decentralized in execution. That means maintaining a single source of truth, such as a navigation graph, flow controller, or coordinator registry, defines how screens relate and how transitions are orchestrated. However, the actual triggering and ownership of flows can be scoped to features or modules. For example, each feature may expose a “flow entry point” API, while a centralized router determines how and when to call it. This achieves both control and composability, which is essential in apps where any screen might be the start of the user journey.
48
What technique iOS uses for navigation and screen flow architecture?
However, large-scale apps increasingly adopt the coordinator pattern because, unlike storyboards, coordinators scale better with feature teams and support nested flows more predictably: Coordinators encapsulate navigation logic outside view controllers. Enable reusable, testable flows and clean separation of concerns. Works well with dependency injection and modular design.