Essential Guide to Technology Trade-offs for Android System Design:

Vishvnath Pratap Singh
7 min readApr 13, 2024

--

1. Introduction

In the ever-evolving landscape of software development, particularly within the mobile ecosystem, Android system design stands out as a critical area of focus for developers and architects alike.

Understanding the trade-offs between various technological choices is not just an academic exercise — it’s a fundamental aspect of designing solutions that are both effective and efficient.

This document delves into some of the most significant trade-offs that developers encounter when working on Android applications, including database selection, server architecture, communication protocols, and network considerations.

The primary aim of this guide is to equip Android developers, system designers, and architects with a deeper understanding of these trade-offs to make informed decisions during the system design phase.

By exploring the advantages and disadvantages of each technology option, such as choosing between NoSQL and SQL databases or deciding on the appropriate communication protocol, this document will help clarify how each decision impacts application performance, scalability, and maintainability.

Data Storage on Android:

In the context of Android app development, here are the trade-offs and considerations for NoSQL vs. SQL vs. Blob Storage:

  1. NoSQL vs. SQL:
  • NoSQL databases (e.g., Firebase Realtime Database, Realm) are well-suited for Android apps that require real-time synchronization, offline capabilities, and flexible data modeling. They allow for seamless data synchronization across multiple devices and provide automatic conflict resolution.
  • NoSQL databases are particularly useful for apps with rapidly changing data structures or when you need to store and retrieve complex hierarchical data.
  • SQL databases (e.g., SQLite, Room) are commonly used in Android apps for structured data storage and retrieval. They provide a well-defined schema, strong data consistency, and powerful querying capabilities. SQL databases are suitable for apps with complex relationships between entities, strict data integrity requirements, and when you need to perform complex queries or transactions.

When to choose:

  • Use NoSQL databases when you prioritize real-time synchronization, offline capabilities, and flexible data modeling.
  • Use SQL databases when you have structured data, complex querying needs, and require strong data consistency and integrity.

When it comes to local data storage options in Android app development, here one more equation arises which one we should choose from Sqlite, Shared Preferences, and File storage?

Each option has its own trade-offs and is suitable for different use cases. Let’s explore these options and their trade-offs:

  1. SQLite:
  • SQLite is a lightweight, file-based relational database that is built into the Android framework.

Advantages:

  • Structured data: SQLite is ideal for storing structured data with well-defined schemas and relationships between tables.
  • Complex queries: It supports complex queries, indexing, and transactions, making it suitable for handling large datasets and performing advanced data operations.
  • Data integrity: SQLite ensures data integrity through ACID (Atomicity, Consistency, Isolation, Durability) properties.

Disadvantages:

  • Complexity: Working with SQLite requires understanding SQL and database concepts, which can add complexity to the app development process.
  • Performance overhead: For simple data storage needs, using SQLite may introduce unnecessary overhead compared to other options.

When to choose:

  • Use SQLite when you have structured data with complex relationships and need to perform advanced queries or transactions.
  • Suitable for scenarios like local caching of server data, offline data storage, or when you need to store and retrieve large datasets efficiently.

2. SharedPreferences:

SharedPreferences is a key-value pair-based storage mechanism provided by the Android framework for storing small amounts of primitive data.

Advantages:

  • Simplicity: SharedPreferences provides a simple API for storing and retrieving key-value pairs, making it easy to use for basic data storage needs.
  • Lightweight: It is lightweight and efficient for storing small amounts of data, such as user preferences or app settings.

Disadvantages:

  • Limited data types: SharedPreferences only supports storing primitive data types (boolean, float, int, long, string) and sets of strings.
  • No query support: It does not provide querying capabilities, so retrieving specific data requires iterating through all the stored key-value pairs.

When to choose:

  • Use SharedPreferences when you need to store small amounts of simple, key-value based data, such as user preferences, app settings, or simple app states.
  • Suitable for scenarios where you don’t require complex querying or structured data storage.

3. File Storage:

  • File Storage refers to storing data in files on the device’s internal storage or external storage (e.g., SD card).

Advantages:

  • Flexibility: File Storage allows storing any type of data, including binary data, text files, or custom file formats.
  • Large data storage: It is suitable for storing large files or datasets that exceed the capacity limitations of other storage options.

Disadvantages:

  • Manual file management: Working with File Storage requires manual file management, including creating, reading, writing, and deleting files.
  • No structure or querying: File Storage does not provide any built-in structure or querying capabilities, so you need to implement your own data organization and retrieval mechanisms.

When to choose:

  • Use File Storage when you need to store large files, such as images, videos, or documents, that don’t fit well in other storage options.
  • Suitable for scenarios where you have custom file formats or need to store data that doesn’t require structured querying.

When deciding between SQLite, SharedPreferences, and File Storage, consider the following factors:

  • Data structure and complexity: If you have structured data with relationships and need to perform complex queries, choose SQLite. For simple key-value pairs, use SharedPreferences. For unstructured or large data, consider File Storage.
  • Data size: SharedPreferences is suitable for small amounts of data, while SQLite and File Storage can handle larger datasets.
  • Performance: SharedPreferences is lightweight and fast for simple data storage, while SQLite provides better performance for complex queries and large datasets. File Storage performance depends on the storage medium and file I/O operations.

Real-time communication and data retrieval in Android app:

When it comes to real-time communication and data retrieval in Android app development, there are several approaches to consider, each with its own trade-offs and suitable use cases. Let’s explore the trade-offs and when to choose each approach:

  1. Polling:
  • Polling involves periodically sending requests from the Android app to the server to check for updates or retrieve new data.

Trade-offs:

  • Inefficient resource usage: Polling can result in unnecessary network traffic and battery consumption, as the app continuously sends requests even when there are no updates available.
  • Increased latency: The app may experience delays in receiving updates since it relies on periodic requests rather than instant notifications.

When to choose:

  • Use polling when real-time updates are not critical, and the data changes infrequently.
  • Suitable for simple scenarios where the app can tolerate some latency and resource overhead.

2. WebSocket:

  • WebSocket is a protocol that enables full-duplex, bidirectional communication between the Android app and the server over a single, persistent connection.

Trade-offs:

  • Persistent connection: WebSocket maintains a continuous connection, which can consume server resources and may not be suitable for high-scale architectures.
  • Compatibility: Some older servers or network infrastructure may not fully support WebSocket, requiring fallback mechanisms.

When to choose:

  • Use WebSocket when you need real-time, bidirectional communication between the app and the server.
  • Ideal for applications like chat systems, collaborative tools, or live updates that require instant data propagation.

3. Long Polling:

  • Long polling involves sending a request to the server and keeping the connection open until new data is available or a timeout occurs.

Trade-offs:

  • Server resources: Long polling can consume server resources by keeping connections open for extended periods.
  • Latency: There may be some latency in receiving updates since the server waits until new data is available before responding.

When to choose:

  • Use long polling when you need near-real-time updates but can tolerate some latency.
  • Suitable for scenarios where the frequency of updates is relatively low, and the server can handle multiple open connections.

4. Server-Sent Events (SSE):

  • Server-Sent Events is a unidirectional communication protocol where the server pushes updates to the Android app using a persistent connection.

Trade-offs:

  • Unidirectional: SSE only allows the server to send updates to the app, not vice versa.
  • Limited browser support: Some older Android versions or WebView implementations may not fully support SSE.

When to choose:

  • Use SSE when you need real-time updates from the server to the app, but don’t require bidirectional communication.
  • Suitable for scenarios like live feeds, stock tickers, or real-time notifications.

5. GraphQL:

  • GraphQL is a query language and runtime for APIs that allows the Android app to request specific data from the server.

Trade-offs:

  • Learning curve: GraphQL has its own syntax and concepts, which may require some learning for both app and server developers.
  • Caching complexity: Implementing caching for GraphQL queries can be more complex compared to traditional REST APIs.

When to choose:

  • Use GraphQL when you need flexibility in querying and retrieving only the required data from the server.
  • Suitable for scenarios where the app needs to efficiently retrieve complex, nested data structures.

6. gRPC:

  • gRPC is a high-performance, open-source framework that enables efficient binary communication between the Android app and the server using Protocol Buffers.

Trade-offs:

  • Learning curve: gRPC uses Protocol Buffers and has its own concepts and syntax, requiring some learning for app and server developers.
  • Compatibility: gRPC may not be suitable for communication with browsers or other platforms that don’t have gRPC support.

When to choose:

  • Use gRPC when you need high-performance, low-latency communication between the app and the server.
  • Suitable for scenarios like microservices communication, real-time streaming, or when you have control over both the app and server implementations.

When selecting an approach, consider factors such as the app’s real-time requirements, scalability needs, compatibility with existing infrastructure, and the complexity of implementation. It’s also common to use a combination of these approaches based on the specific requirements of different features within the app.

Remember to evaluate the trade-offs and choose the approach that aligns with your app’s performance, user experience, and development constraints.

Thank you for reading.

For comprehensive preparation for Mobile System Design Interviews, explore our detailed course covering design templates, trade-offs, decision-making strategies, and techniques to master both breadth and depth in your interviews. Check it out here or connect with me on topmate.io.

--

--