skip to content

In an offline language-learning app, which store kind would you choose for flashcards, progress, settings and lesson audio, and why?

level: middleimportance: must knowfreq 58%

answer

  1. queries and sizes, not product names
  2. range plus sort wants an index
  3. a dozen named values
  4. megabytes belong on the file system
  5. one event, one store, one commit

basics

~10 s

Choose by each data's queries and size: cards and progress in an embedded relational database indexed by due date, settings in a key-value store, and audio as files that a database row points to.

solid answer

~50 s

I pick a store per kind of data from how it is read and how big it is. Flashcards are queried as "due today for this deck, oldest first" across thousands of rows, so they go in an **embedded relational database** with an index on deck and due time. Lesson progress and the streak change in the same moment as the cards, so they share that database and one transaction. A dozen settings read by name at launch fit a **key-value store**. Lesson audio is megabytes per pack, so it lives in **files**, with a row recording where each file is and whether it is complete. Lesson text that is only read and replaced whole can be one stored document. Every extra store is one more thing to migrate and wipe, so I add one only where the queries differ.

go deeper

for a junior

Recall the four store kinds and one example each suits: a few settings in a key-value store, many searchable records in a relational database, large media in files.

for a middle

Argue each choice from a query and a size: a range filter with a sort needs an index, a dozen settings do not, and megabytes of audio go in files with a row pointing at them.

for a senior

Draw store boundaries around transactions so one event's updates commit together, and say what every additional store costs in migrations, wiping on logout and testing.

for a principal

Weigh one relational store for nearly everything against specialised stores per data type, considering team skills, tooling shared across platforms and the migration burden over years.

A design interviewer who hears "we'll use a database" asks the obvious follow-up: which kind, for which data, and why. On a phone the answer is rarely a single store. An installed app keeps several kinds of data with very different shapes, and the right store for each follows from two facts about it: **how it is read** (by name, by range, sorted, joined, or whole) and **how big it is** (a few bytes, thousands of rows, or megabytes per item). Product names come after that argument, never before it. ## The four store kinds An **embedded relational database** is a full SQL engine running inside the app's process, keeping its tables in a file in the app's private storage; there is no server. A **key-value store** maps names to values, often keeping the whole set in one small file. A **document store** keeps nested records (documents) and can query fields inside them. **Plain files** are bytes on disk addressed by a path. | Store kind | Good at | Weak at | Typical fit | |---|---|---|---| | Embedded relational database | Filtering and sorting many rows through **indexes**, joins, multi-row **transactions**, observable queries | Large binary content; needs a schema and migrations | Thousands of records queried by range or sort | | Key-value store | Reading and writing a handful of small values by name | Queries across values, relationships, large data sets | Settings, flags, the last-opened tab | | Document store | Loading and saving nested objects whole, flexible shape | Queries and updates that cut across documents | Aggregates read and replaced as a unit | | Plain files | Large blobs streamed from disk | Any query; consistency with other data without extra work | Audio, images, downloaded packs | ## Mapping the language-learning app's data Assume, as this scenario's own numbers rather than any standard, 20,000 flashcards per learner, about 30 lessons in progress, a dozen settings and lesson packs carrying 40 to 80 MB of audio each. - **Flashcards** are the deciding case. The home screen asks for the cards due today in this deck, oldest first, and a badge asks how many. That is a range filter plus a sort over thousands of rows; a relational database with an index on deck and due time answers it by reading only the due rows. - **Per-lesson progress and the streak** are small, but they change in the same moment as the cards when a lesson is finished. They belong in the same relational database so that one transaction covers all of them. - **Settings** such as the interface language, daily goal, reminder time and sound on or off are a dozen values read by name at launch. A key-value store is the honest fit. - **Lesson audio** is megabytes per pack. It goes into **files** in the app's private, persistent storage, and a database row records which pack it is, where the file is, its size and whether the download finished. Screens query the row; only the player opens the file. - **Lesson text** that is always read whole and replaced whole when a pack updates can be stored as one document or one JSON value per lesson. Splitting it into tables buys nothing until something queries inside it. ## Things that change together live together The most common mistake in this question is splitting data that one event updates across two stores. Finishing a lesson: 1. writes new due dates for the cards just reviewed, 2. marks the lesson's progress, 3. extends the streak. If the streak sits in a key-value store and the cards in the database, no single commit covers both, and a process ended between the two writes leaves the streak and the cards disagreeing. The rule is to **draw store boundaries so that every multi-record update lands inside one store's transaction**. That is also why a setting that must change together with rows, such as a per-course daily goal the due query joins against, can move into a database table. ## What the screens need from the store Platform guidance for offline-first apps recommends that the local store be what the screens read, with the network only filling it, because one place to read survives a relaunch and works without a connection. That puts two requirements on the store's API, and both argue for the relational choice for the core data: - **Observable reads**: a query the screen subscribes to that emits again when its rows change, so a graded card leaves the due list without a manual refresh. - **Off-UI-thread access**: reads and writes that run on a background thread and report back, so a query over 20,000 rows never blocks a frame. ## Answering it in the room - Name the **kind** first, then justify it with a query or a size. - Add a store only where the queries genuinely differ; each extra store is another schema to migrate, another thing to wipe on logout and another failure mode to test. - Say what you would **not** do: audio inside database rows, due-date filtering in a key-value store, or 20,000 cards serialised as a single value.

  • When would you put a setting in the relational database instead of the key-value store?
    When it must change in the same transaction as other rows, or when queries join against it, such as a daily goal per course that the due-cards query uses. One small settings table then beats a second store, because one commit covers the setting and the rows it affects.
  • When does a document store beat the relational database for an app's core data?
    When the data is an aggregate read and written whole, its shape varies, and nothing queries across documents. Once screens filter or sort across many documents, like due cards across every lesson, or one event updates several documents together, the relational store's indexes and transactions win.
  • Why not keep all 20,000 cards as one JSON value in the key-value store?
    Every read loads and parses all of them, every grade rewrites all of them, and the due filter runs in app code over the whole list on each change. Rows with an index read only what the screen needs and update one card at a time.

  • Picking one store by product name before naming a single query it must serve.
  • A key-value store answers 'cards due today, sorted by date' as well as an index does.
  • Data updated by one event can be split across two stores without risking disagreement.
  • Multi-megabyte audio is best kept as blobs inside the database rows.
  • More stores are always safer, because each one isolates its data from the others.