From 620230a0f108a0fb54424dc24830c0b5bc10afd8 Mon Sep 17 00:00:00 2001 From: Shubham Goyal Date: Thu, 23 Apr 2026 12:19:37 +0530 Subject: [PATCH 1/4] Add mobile storage standards documentation Document guidelines for using SQLite DB versus Shared Preferences in mobile storage. --- docs/mobile_storage_standards.md | 68 ++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 docs/mobile_storage_standards.md diff --git a/docs/mobile_storage_standards.md b/docs/mobile_storage_standards.md new file mode 100644 index 0000000..3618e38 --- /dev/null +++ b/docs/mobile_storage_standards.md @@ -0,0 +1,68 @@ +# SQLite DB vs Shared Preferences + +## Use Shared Preferences for: + +Small, simple key-value data such as: + +* Theme / dark mode +* Feature flags +* First launch completed +* Last sync timestamp +* Selected language +* User settings +* Small primitive user state + +**Best when:** + +* Few values +* Simple reads/writes +* No querying needed +* UI State + +--- + +## Use SQLite DB for: + +Structured, growing, or queryable data such as: + +* Lists of records +* Forms / submissions +* Messages / history +* Downloaded content +* Offline business data +* Queues / retries +* Parent-child relationships + +**Best when:** + +* Many records +* Need search / sort / filter +* Need transactions +* Data evolves over time + +--- + +## Quick Decision Rule + +| If data is... | Use | +| ----------------------- | ------------------ | +| App settings / flags | Shared Preferences | +| Single values | Shared Preferences | +| Records / lists | SQLite | +| Searchable / filterable | SQLite | +| Growing over time | SQLite | + +--- + +## Avoid + +* Large JSON blobs in Shared Preferences +* Using SQLite for isolated flags or intermediate properties +* Complex structured data in Shared Preferences + +--- + +## Team Principle + +**If data is state → Shared Preferences** +**If data is records → SQLite** From e8c18d2174b5332338e5294d76342525ce8b1c17 Mon Sep 17 00:00:00 2001 From: Shubham Goyal Date: Thu, 23 Apr 2026 12:29:54 +0530 Subject: [PATCH 2/4] Update title of mobile storage standards document --- docs/mobile_storage_standards.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/mobile_storage_standards.md b/docs/mobile_storage_standards.md index 3618e38..388cf08 100644 --- a/docs/mobile_storage_standards.md +++ b/docs/mobile_storage_standards.md @@ -1,4 +1,4 @@ -# SQLite DB vs Shared Preferences +# Mobile Storage: SQLite DB vs Shared Preferences ## Use Shared Preferences for: From ce5956f73c2d5811aaa780f5d946dd8fcfc20337 Mon Sep 17 00:00:00 2001 From: Shubham Goyal Date: Thu, 23 Apr 2026 12:34:15 +0530 Subject: [PATCH 3/4] Cross link storage guidelines from mobile standards --- docs/mobile_standards.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/mobile_standards.md b/docs/mobile_standards.md index ab5dc69..39697f0 100644 --- a/docs/mobile_standards.md +++ b/docs/mobile_standards.md @@ -61,7 +61,11 @@ In short: “Crash early, fix quickly, and handle gracefully where it matters. - Nullable types are handled appropriately with safe calls and nullability checks. - Use of Kotlin's built-in null safety features where necessary. -- Change Java files to Kotlin when Java-Kotlin intercompatibility introduces unnecessary and significant boilerplate code. +- Change Java files to Kotlin when Java-Kotlin intercompatibility introduces unnecessary and significant boilerplate code. + +### Mobile Data Storage + +- [Sqlite vs Shared Preferences](https://github.com/dimagi/open-source/blob/master/docs/mobile_storage_standards.md) ### Async Processing From e2fb57a3f244083000021af96ea6114427473c4f Mon Sep 17 00:00:00 2001 From: Shubham Goyal Date: Fri, 24 Apr 2026 14:42:11 +0530 Subject: [PATCH 4/4] Update mobile storage standards documentation Clarified definitions and best practices for mobile storage standards, including specific examples of user state and data types. --- docs/mobile_storage_standards.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/mobile_storage_standards.md b/docs/mobile_storage_standards.md index 388cf08..bbb37c3 100644 --- a/docs/mobile_storage_standards.md +++ b/docs/mobile_storage_standards.md @@ -10,7 +10,7 @@ Small, simple key-value data such as: * Last sync timestamp * Selected language * User settings -* Small primitive user state +* Small primitive user state like number of times a user has been shown a specific prompt or reminder **Best when:** @@ -32,6 +32,7 @@ Structured, growing, or queryable data such as: * Offline business data * Queues / retries * Parent-child relationships +* Data from Server APIs (generally structured persistent data) **Best when:** @@ -56,13 +57,12 @@ Structured, growing, or queryable data such as: ## Avoid -* Large JSON blobs in Shared Preferences +* Using Shared Preferences for non-volatile data that might need backward compatibility or migrations across app versions * Using SQLite for isolated flags or intermediate properties -* Complex structured data in Shared Preferences --- ## Team Principle -**If data is state → Shared Preferences** -**If data is records → SQLite** +* If data is state → Shared Preferences +* If data is records → SQLite**