Local Storage: Key-value, SQLite & Files

Choose the right on-device storage for settings, structured data, files and secrets, and handle schema migrations.

Intermediate · about 7 hours · difficulty 3/5

Learn first: Networking Clients & Server-state Caching

Apps store data locally for speed, offline use and continuity. Picking the wrong store is a common source of bugs and security issues.

Options

  • Key-value stores for small settings and flags: AsyncStorage or MMKV (React Native), shared_preferences (Flutter), DataStore (Android), UserDefaults/@AppStorage (iOS). Not for large or relational data.
  • SQLite for structured, queryable data: expo-sqlite, Drizzle or WatermelonDB (React Native), drift or sqflite (Flutter), Room (Android), SwiftData/Core Data (iOS, built on SQLite).
  • File system for images, downloads and exports: expo-file-system, path_provider, app-specific directories.
  • Secure storage for tokens and secrets: Keychain on iOS and Keystore-backed storage on Android, via expo-secure-store or flutter_secure_storage. Never put tokens in plain key-value storage.

Migrations

When your schema changes in version 2, users still have version 1 data. Write versioned migrations and test upgrading from an old build.

Pitfalls

  • Storing large JSON blobs in AsyncStorage and parsing them on startup slows launch.
  • Assuming storage survives forever; the OS or user can clear it. The server should remain the source of truth for important data.

Good enough to move on: your app keeps settings in key-value storage, records in SQLite with one migration, and the auth token in secure storage.

Key concepts

  • Key-value storage
  • MMKV: Fast synchronous KV for React Native
  • SQLite and ORMs
  • Schema migrations
  • File system storage
  • Secure storage for secrets
  • Choosing the right store

Mini project

Build an expense tracker storing entries in SQLite with a category filter, preferences in key-value storage, and add a migration that introduces a notes column.

Check yourself

Where should an access token live on the device, and why not in AsyncStorage or SharedPreferences?

Free resources