LightMySky

Key-Value and Document Stores

Some workloads want a single key lookup and nothing else, and pay for the freedom by giving up joins and schema checks. A document store keeps whole nested objects together, which suits reading one thing at a time and makes any cross-cutting question harder.

No account needed. Progress saves in this browser.

What a learner can do afterwards

  • Model a small domain as documents and as normalised tables, and compare the queries
  • Say what duplication buys in a document design and what it costs on update
  • Name a workload that suits a key-value store and one that does not

1 · Read

Some workloads want a single key lookup and nothing else. You hand the database one key and it hands you back the whole value. It does not check the shape of your data, and it does not join things together for you. That freedom suits reading one thing at a time, and fails any question that cuts across many records.

Try it together

Think of var cat = { name: "Whiskers", age: 5, color: "gray" }. Each property has a key like name and a value like Whiskers, and cat.name reaches it, the way a key reaches its value. A cat can even hold an owner object with its own keys, and nesting values inside one object is exactly how a document store works: the whole nested thing sits together, so one lookup returns everything.

Document designs often repeat the same fact in many places. Storing the owner city inside every cat record makes reads fast, since one lookup returns everything. But if the owner moves, every copy must be updated, and a missed copy leaves the data disagreeing with itself. Duplication buys speed and simplicity on reads, and charges work and risk on every update.

Good to know

To model a blog, keep each post with its comments as one document when readers open one post at a time. Ask which questions each design answers badly: documents struggle with cross-cutting questions like the average age of all cats in every city, since there is no join and no schema to lean on. Pick documents for single-thing reads, tables for cross-cutting questions.

Key lookups return whole values fast, documents keep nested things together, and duplication trades update pain for read speed.

2 · Watch

Take it off screen

Print a worksheetA4 with an answer key page for grown-ups. No screen, no internet.

Where it sits

Then practise

8 questions wait behind this lesson, each with its answer explained. Every answer feeds the sky: stars light as they are learned, and dim when it is time to come back.

Spotted a problem on this page? Tell us
Key-Value and Document Stores · Computing, ages 20 to 21 · LightMySky