skip to content

Should a mobile app rely on the platform's bundled SQLite or ship its own SQLite build, and how would you decide?

level: principalimportance: should knowfreq 25%

answer

  1. the oldest supported phone sets the floor
  2. compile options differ by build
  3. who ships the security fixes
  4. one SQLite copy per process
  5. newer schemas do not go back

basics

~20 s

Use the bundled SQLite when the oldest supported device's version and build options cover your features; ship your own when you need newer features or uniform behaviour, accepting the app size, the patching duty and the one-copy-per-process rule.

solid answer

~50 s

The platform's SQLite costs nothing in app size and gets security fixes with OS updates, but its version is set by the oldest device you support and its compile options are someone else's, so FTS5, limits and defaults may differ. Features gate on release: RETURNING 3.35.0, STRICT 3.37.0, built-in JSON 3.38.0, JSONB 3.45.0, and 3.53.0's ALTER TABLE adding and removing NOT NULL and CHECK constraints. Shipping your own build gives one version and one set of options everywhere, at the cost of app size, owning every security update, and making sure nothing else in the process opens the same file through a second copy of SQLite, which can break POSIX locking and corrupt it. Decide from evidence: record `sqlite_version()` and `PRAGMA compile_options` from the field, list the features you need, and remember the choice is sticky, since STRICT tables and JSONB values need a library new enough to read them.

go deeper

for a junior

Recall that a phone already contains SQLite, usually older than the current release, and that an app can instead ship its own copy.

for a middle

Explain how features gate on releases such as STRICT 3.37.0 and JSONB 3.45.0, and how sqlite_version() and PRAGMA compile_options reveal what a library offers.

for a senior

Show the operational consequences: size batches and features for the oldest library, never let two SQLite copies touch one file, and plan who ships security updates for a bundled build.

for a principal

Own the trade-off and its stickiness: uniform features and reproducible behaviour against app size and patching duty, decided from field data, recorded, and revisited when the supported device range moves.

## The decision Every phone platform carries a copy of SQLite, and most apps can use it. The alternative is to compile SQLite into the app and ship it. Neither is free, and the choice is hard to reverse once data written by one library has to be read by another. It is a decision a lead should make once, write down, and revisit when the supported device range moves. ## What the bundled library gives and costs - **Zero size.** Nothing is added to the app. - **Patched by the platform.** Security fixes arrive with OS updates, on the platform's schedule rather than yours. - **An unknown, often older version.** A phone's built-in SQLite lags the current release, and your installed base spans many OS versions, so the effective version is the **oldest** one you support. Do not guess it from the OS version; measure it. - **Someone else's compile options.** Whether FTS5 is present, which limits apply and which defaults are set are the builder's choices. One build may allow a different number of host parameters or a different string length than the source defaults. - **Behaviour that changes under you.** An OS update can bring a newer SQLite with planner changes, so a query plan can shift without an app release. ## What shipping your own gives and costs - **One version everywhere**, chosen by you: current features, the same planner and the same bugs on every device, which makes field reports reproducible. - **Your compile options**: FTS5 on, limits and defaults as you want them. - **App size** grows by the library. - **You own security updates.** When SQLite ships a fix, your users get it only when you rebuild and release. That needs a named owner and a cadence. - **One copy per process.** SQLite works around POSIX advisory-lock quirks with a single global list of open files. If any other code in the same process opens the same database file through the platform's copy, the two lists cannot coordinate, and a `close()` through one can silently drop the other's locks, which can corrupt the file. Your copy must be the only one that touches your files. ## A comparison | Concern | Bundled library | Your own build | |---|---|---| | Version | whatever the oldest supported device has | the one you pin | | Features such as STRICT, JSONB, newer ALTER TABLE | only if every supported device has them | available everywhere | | FTS5 and limits | the builder's compile options | your compile options | | Security fixes | delivered by OS updates | delivered by your releases | | App size | no cost | grows | | Corruption risk from two copies | none from this choice | real if other code uses the platform copy on the same file | ## Features that set the floor The releases that most often decide the question: UPSERT 3.24.0, window functions 3.25.0, the host-parameter limit rising from 999 to 32766 in 3.32.0, `RETURNING` 3.35.0, STRICT tables 3.37.0, built-in JSON functions and the `->` and `->>` operators 3.38.0, JSON5 input 3.42.0, JSONB and a page-count default of 4294967294 in 3.45.0, and in 3.53.0 `ALTER TABLE` adding and removing NOT NULL and CHECK constraints. If the oldest supported library is below a feature you need, either avoid the feature or ship your own. ## How to decide 1. **List what you need**, such as FTS5 search, JSONB settings, STRICT tables, `RETURNING`, and the size of bulk statements. 2. **Measure the field.** On first launch, run `SELECT sqlite_version()` and `PRAGMA compile_options` and report them through your own telemetry. The `sqlite3_limit()` call with a negative value returns current limits. 3. **Compare.** If every supported device covers the list, the bundled library is the cheaper choice; guard optional features with runtime checks. 4. **If not**, ship a pinned build, assign an owner for SQLite security releases, and verify that no dependency opens your database through another copy. 5. **Write down the stickiness.** A database with STRICT tables makes a library older than 3.37.0 report an error when it reads the schema, and JSONB values need 3.45.0 to be read as JSON. Switching back to an older bundled library later needs a migration first. ## Mistakes to avoid - Assuming every phone runs the current SQLite release. - Mapping OS versions to SQLite versions from memory instead of asking the library. - Shipping your own build and forgetting to update it, which can leave users on a version older than the platform's. - Linking your build while another component in the process still opens the same file through the platform's copy.

  • How do you find out which SQLite version and options your app's installed base actually runs?
    Ask the library at run time rather than inferring it from the OS: `SELECT sqlite_version()` returns the version string, `PRAGMA compile_options` lists the build's options (look for `ENABLE_FTS5`), and `sqlite3_limit()` with a negative value returns a limit without changing it. Report these through your own telemetry and size your feature floor from the oldest values seen.
  • After shipping your own SQLite 3.53 and creating STRICT tables, can a later app release fall back to the bundled library?
    Only if every supported device's bundled library is 3.37.0 or later; an older one reports an error when it reads a schema containing STRICT. JSONB values likewise need 3.45.0 to be read as JSON. A fallback therefore needs a migration that rewrites those tables and values first, which is why the original choice deserves deliberate thought.

  • Every phone ships the current SQLite release.
  • A bundled SQLite always includes FTS5 and the JSON functions.
  • Shipping your own SQLite changes nothing about security patching.
  • Linking a second SQLite copy beside the platform's is harmless.
  • The SQLite version can be inferred reliably from the OS version.
  • Files written by a newer SQLite always work in an older one.

Assumes SQLite 3.53 as the version you would ship; the feature floor depends on releases such as 3.35.0 (RETURNING), 3.37.0 (STRICT), 3.38.0 (built-in JSON), 3.45.0 (JSONB) and 3.53.0 (ALTER TABLE constraint changes).