LESSON 01 · Access pattern

Define the key-value contract

A small API still needs precise durability, size, and consistency promises.

SYSTEM VIEW

The storage path

Diagram view
Data—
Copies—
Nodes—

Watch a store answer by key, refuse to look inside values, then outgrow one machine.

  1. The Client knows the order ID, so it calls put(order:42, …) and the Key-value store answers ok. A later get(order:42) returns the same 1 KB. The store keeps the value as opaque bytes and never reads inside.

    Core API
    put(key, value), get(key)
    Decided apart
    delete, expiry, listing

    What changed

    • put(order:42, …) acknowledged
    • get(order:42) returns the bytes
  2. A team asks for all late orders in the EU. The Key-value store has no key for that: region and lateness sit inside opaque values, so it would scan every value. If ad hoc queries are common, a relational database is likely the better start.

    What changed

    • Query: late orders in the EU
    • No key to look up
  3. A Secondary index, updated by the store on every put, answers the question instead: asked for late orders in the EU, it returns their order IDs. It costs extra storage and write work, as DynamoDB’s secondary indexes do.

    Answers
    late orders by region
    Costs
    storage + write work

    What changed

    • Secondary index
    • Every put also updates it
  4. The contract must say whether an acknowledged write survives a crash. Here the Key-value store acknowledged put(order:42), crashes, restarts, and get(order:42) still returns it. The contract must also say whether every read reflects the latest acknowledged write.

    Durability
    an ok survives a crash
    Fresh reads
    get sees the latest ok
    Also agree
    sizes, volume, latency

    What changed

    • Secondary index (set aside)
    • Store crashes and restarts
    • Acknowledged put survives
  5. A one-machine store is a useful first model, and for many products it is enough. A Standby copies every write and takes over if the store fails: a single Redis server with a standby can carry plenty of cache and session traffic.

    What changed

    • Standby
    • One machine carries the traffic
  6. Numbers turn the contract into decisions: 2 billion keys at 1 KB each is 2 TB before copies, twice the 1 TB one node comfortably holds. The Standby holds the same 2 TB, so a copy adds no room: the data set forces distribution.

    Data
    2 billion × 1 KB = 2 TB
    One node holds
    1 TB comfortably

    What changed

    • 2 billion keys: 2 TB
    • Twice one node’s 1 TB
  7. With three copies, the 2 TB becomes 6 TB stored. At 1 TB a node, that is at least six nodes for storage alone, so the Cluster spreads the data across six nodes, each key on three of them.

    Stored
    2 TB × 3 = 6 TB
    Per node
    1 TB

    What changed

    • Cluster of six nodes
    • One machine and its standby
    • 3 copies: 6 TB stored
  8. A promise to survive machine failure forces recovery into the contract. When one of the six nodes fails, its slice is gone: up to 1 TB that must be rebuilt from the other copies before every key has three again.

    Lost
    1 node · up to 1 TB
    Rebuilt from
    the other copies

    What changed

    • One node
    • Some keys down to 2 copies
    • Up to 1 TB to rebuild

Space plays · ← → step · Home resets

THE IDEA

How it works

A key-value store associates a unique key with an opaque value, meaning the store keeps the bytes without interpreting them. Its core operations are put(key, value) and get(key). Deletion, conditional writes, expiration, and listing are separate product decisions. Direct lookup by known key is its strength; joins or filtering across values need another index or data model.

Agree on key and value sizes, volume, read/write mix, latency, availability, durability (whether an acknowledged write survives a crash), and whether a read must reflect the latest acknowledged write. Numbers turn that list into decisions. As an example, 2 billion keys at 1 KB each is 2 TB before copies, or 6 TB with three copies. If one node comfortably holds 1 TB, that is at least six nodes for storage alone, and each lost node leaves up to 1 TB to rebuild.

A one-machine hash table is a useful first model, and for many products it is enough: a single Redis server with a standby can carry plenty of cache and session traffic. A data set larger than one machine, or a promise to survive machine failure, forces distribution and recovery into the contract. If you expect ad hoc queries across values, a relational database is likely the better start. DynamoDB shows the usual compromise: fast access by key, with secondary indexes as extra structures that cost storage and write work.

DECISION POINT

Orders are stored by order ID, but a team also needs all late orders in a region. What would you clarify?

Write a sentence or two to unlock the guidance. Committing first is what makes it stick.

Keep in mind

  • A key identifies an opaque value; the access pattern drives the design.
  • Specify durability, failure, and read-after-write expectations before choosing machinery.
CHECK YOUR UNDERSTANDING

Put it into practice.

1 OF 2
RecallQUESTION 01

Which operation is native to a simple key-value API?

Choose an answer. You’ll see the explanation once you get it right.

Next lesson

0 of 2 checkpoints answered correctly to complete this lesson.