Data Storage in Mobile Development: What It Is, Methods, and How It Works

Author: IT Sectr Published: 2026-03-08 Reading time: 9 min

Data storage is one of the key tasks of a mobile application, affecting performance, security, and user experience. In this article, we will cover SQLite, Room, Core Data, Realm, Firebase Firestore, SharedPreferences, DataStore, Keystore and Keychain, as well as serialization formats (JSON, Protobuf) and libraries (Gson, Moshi, kotlinx.serialization). This guide will help beginner developers choose the right data storage solution. Learn more in the official Android data storage guide.

Key Takeaways

  • Room (Android) and Core Data (iOS) are the official ORMs for working with relational databases on each platform
  • SharedPreferences (Android) is being replaced by DataStore — an asynchronous and type-safe key-value storage
  • For secure token storage, use Keystore (Android) and Keychain (iOS) with hardware-backed protection
  • Firebase Firestore is a NoSQL database with real-time synchronization and offline mode
  • Serialization — converting objects to JSON/Protobuf using Gson, Moshi, kotlinx.serialization

Local Databases: SQLite, Room, Core Data, Realm

Relational databases are used for storing structured data with relationships between entities.

SQLite

SQLite is an embedded relational database that works on any mobile platform. It requires no separate server, and data is stored in a single file. SQLite is the foundation for Room (Android) and optionally for Core Data (iOS). Libraries: android.database.sqlite (Android), FMDB/Core Data (iOS), sqflite (Flutter).

Room (Android)

Room is the official Android Architecture Components library for working with SQLite. It provides an ORM layer: Entity (table), DAO (queries), Database (entry point). Room checks SQL queries at compile time, supports coroutines and Flow, and automatically migrates schemas.

kotlin
@Entity
data class User(
    @PrimaryKey val id: Int,
    val name: String,
    val email: String
)

@Dao
interface UserDao {
    @Query("SELECT * FROM user WHERE id = :id")
    suspend fun getUser(id: Int): User?
}

Core Data (iOS)

Core Data is Apple's framework for managing an object graph. It is not a pure database — it is a persistence layer on top of SQLite, XML, or binary storage. Core Data manages objects (NSManagedObject), relationships, schema versioning, undo/redo, and multithreading via NSManagedObjectContext.

Realm

Realm is an alternative to SQLite, designed as a high-performance mobile database. Realm is faster than SQLite for reads and writes, supports reactive notifications (Live Objects), on-the-fly encryption, and cross-platform use (Android, iOS, Flutter, React Native). Disadvantages: increased APK/IPA size and higher memory usage.

Key-Value Storage and Settings

For storing small amounts of data (settings, tokens, cache), simple key-value stores are used.

SharedPreferences (Android)

SharedPreferences is a legacy key-value store in Android. Cons: synchronous access (blocks UI on read), lack of typing, ANR risk when loading large files. NOT recommended for new projects.

DataStore (Jetpack Android)

DataStore is a modern replacement for SharedPreferences from Google. It works asynchronously via Kotlin Coroutines and Flow, supports Preferences DataStore (key-value) and Proto DataStore (typed data via Protobuf). DataStore is safe for the UI thread and supports transactions.

NSUserDefaults (iOS)

UserDefaults is the standard storage for small settings in iOS. It supports primitive types, strings, dates, Data. UserDefaults is synchronous, so it is not suitable for large data volumes. Register default values via register(defaults:).

Cloud Databases: Firebase Firestore and Realtime DB

For data storage in applications requiring synchronization across devices, Firebase cloud databases are used.

Cloud Firestore

Firebase Firestore is a NoSQL document database with real-time subscriptions, automatic scaling, powerful queries, and built-in offline mode. Data is organized into collections and documents (JSON-like structures). Firestore supports transactions and batch operations. Ideal for chats, feeds, and social apps.

Firebase Realtime Database

Firebase Realtime Database is an older Firebase NoSQL database that stores data as a single JSON tree. Simpler than Firestore but less flexible in queries and scaling. Recommended for simple real-time applications (online status, simple chats).

Feature Cloud Firestore Firebase Realtime DB
Data ModelCollections → DocumentsJSON tree
QueriesComplex (filtering, sorting, limits)Simple (by key)
ScalingAutomaticManual sharding
Offline ModeYes (persistent cache)Yes
PricingPer read/write operationsPer traffic + storage

Secure Storage: Keystore, Keychain and EncryptedSharedPreferences

Storing tokens, passwords, and encryption keys requires special protected storage.

Android Keystore

Android Keystore is a system storage for cryptographic keys. Keys are stored in a hardware environment (TEE — Trusted Execution Environment), inaccessible to apps and the OS. It supports key generation, encryption, and signing. Android 9+ includes StrongBox Keymaster (dedicated chip).

iOS Keychain

Keychain Services is a secure iOS storage for passwords, keys, and certificates. Data is encrypted using the hardware Secure Enclave. Keychain supports accessibility levels: Always, WhenUnlocked, WhenUnlockedThisDeviceOnly, AfterFirstUnlock.

EncryptedSharedPreferences (Android)

EncryptedSharedPreferences is a wrapper around SharedPreferences with key and value encryption using AES256-GCM and HKDF. Implemented in the AndroidX Security library. Recommended for storing tokens and sensitive settings.

At IT Sectr, we use Android Keystore + EncryptedSharedPreferences for storing refresh tokens and biometric-based keys. On iOS, we use Keychain with the kSecAttrAccessibleWhenUnlockedThisDeviceOnly level for maximum security.

File Storage: Internal, External, Cache Directory

For file storage (images, videos, documents), mobile platforms provide several storage types.

Android Storage

Android distinguishes between Internal Storage (/data/data/package/ — private storage) and External Storage (SD card or emulated partition). Cache Directory is temporary storage that the system can clear. Scoped Storage (Android 10+) restricts access to External Storage — apps see only their own files or files via MediaStore/SAF.

iOS Storage

iOS provides Documents Directory (iCloud backup, persistent data), Library/Caches (temporary files, not backed up), and Tmp Directory (temporary, can be cleared). Use NSFileManager to work with the file system. iOS 11+ supports File Provider for cloud files.

Data Serialization: JSON, Protobuf and Libraries

Serialization converts objects into a format for transmission or storage. Deserialization is the reverse process.

Formats

JSON (JavaScript Object Notation) is the most popular format: readable, flexible, supported by all platforms. XML is stricter, used in legacy systems. Protobuf (Protocol Buffers) is a binary format from Google: 3-10x more compact than JSON, faster to parse, with a strict schema. Used for high-load systems and microservices.

Android Libraries

  • Gson (Google) — simple, flexible, but slow. Works automatically with Java/Kotlin objects
  • Moshi (Square) — faster than Gson, better Kotlin support (non-null properties, default values, sealed classes)
  • kotlinx.serialization — native Kotlin serialization from JetBrains, works at compile time, supports JSON, Protobuf, CBOR

iOS Libraries

JSONSerialization is the built-in API for working with JSON. Codable (Encodable/Decodable) is a modern Swift protocol for automatic serialization to JSON, Property List, and other formats.

swift
struct User: Codable {
    let id: Int
    let name: String
    let email: String
}
let user = User(id: 1, name: "Alice", email: "alice@example.com")
let encoder = JSONEncoder()
let jsonData = try encoder.encode(user)

Cross-Platform Solutions: Hive, ObjectBox, Drift

For Flutter and React Native, there are efficient storage libraries of their own.

Hive (Flutter)

Hive is a lightweight, fast key-value store for Flutter. It requires no native code (pure Dart), supports typing via TypeAdapter, and works in isolates. Ideal for cache, settings, and small data volumes.

ObjectBox

ObjectBox is a high-performance embedded database for Flutter, Android, and iOS. It is 10x faster than SQLite, uses a flat file structure for minimal overhead. Supports relationships, queries, and reactive subscriptions (ObjectBox Dart).

Drift (formerly Moor)

Drift is a reactive SQLite library for Flutter and Dart. It provides type-safe queries, migrations, DAO functions, and Stream support (reactive updates). Drift is the primary choice for Flutter projects requiring SQLite.

Frequently Asked Questions

Which is better for local data storage: Room or Core Data?

The choice depends on the platform: Room (Android) is the official library based on SQLite with compile-time query checking. Core Data (iOS) is Apple's framework with an object graph. For cross-platform projects, Realm or SQLite via ORM works well.

How is SharedPreferences different from DataStore?

SharedPreferences is an old implementation with synchronous access and ANR risk. DataStore (Jetpack) is a modern replacement based on Kotlin Coroutines and Flow, supporting asynchronicity, typing, and error protection.

How to securely store tokens and passwords in a mobile app?

Android: EncryptedSharedPreferences or Android Keystore. iOS: Keychain Services with WhenUnlockedThisDeviceOnly accessibility. For critical data, use Secure Enclave (iOS) and hardware Keystore (Android) with biometrics.

What is Firebase Firestore and when should it be used?

Cloud Firestore is a NoSQL database from Firebase with real-time synchronization, offline mode, and automatic scaling. Suitable for chats, news feeds, and projects that need synchronization between devices.

What ORMs exist for Flutter and React Native?

Flutter: Hive (fast key-value), Floor (SQLite ORM), Drift (Moor, reactive SQLite), ObjectBox (high-performance embedded DB). React Native: Realm, WatermelonDB (lazy loading) and AsyncStorage (analog of SharedPreferences).

Summary

  • Room (Android) and Core Data (iOS) are the official solutions for relational databases on each platform
  • DataStore replaces SharedPreferences for async settings storage
  • Keystore / Keychain are mandatory for secure token and key storage
  • Firebase Firestore is the best choice for real-time synchronization between devices
  • Kotlinx.serialization (Android) and Codable (iOS) are modern serialization approaches
  • For Flutter: Drift (SQLite), Hive (key-value), ObjectBox (high performance)
  • Realm is a cross-platform alternative to SQLite with reactive notifications

We will develop a mobile application turnkey

IT Sectr creates iOS and Android applications for startups and businesses since 2017. We will advise you and propose the best solution.

Discuss the project