liveBook · Manning

Key-value store

As explained in Rust in Action: Systems programming concepts and techniques

A key-value store is a data-storage system that associates keys with values and supports storing and retrieving those values.

A key-value store associates each key with one value and retrieves that value through the key. The model handles direct lookups, such as finding Fiji’s capital, but not broad queries over many records. section 7.5.1

A practical store can represent keys and values as byte sequences of arbitrary length. The actionkv project begins with an in-memory command-line store and grows toward persistent storage that survives hardware failure. section 7.0 section 7.5.2

A Rust implementation demonstrates several core operations:

  • Store and retrieve arbitrary byte sequences as key-value pairs. section 7.5.1
  • Use HashMap indexing for fast direct access, or BTreeMap when ordered traversal and subsets are needed. section 7.7.9
  • Handle missing keys with get(), which returns an Option, instead of indexing and risking a panic. section 7.7.9
  • Persist records in files while coordinating library code, executable binaries, metadata, and storage dependencies through Cargo. section 7.5.2 section 7.7.6

Country capitals

A table can map "Fiji" to "Suva" and "Kiribati" to "South Tarawa". Looking up capitals["Tonga"] returns a read-only reference when the key exists; capitals.get("Tonga") allows the program to handle an absent key explicitly. section 7.5.1 section 7.7.9

Table 7.5 Illustrating keys and values by matching countries with their capital cities (view table figure)

Key

Value

"Cook Islands"

"Avarua"

"Fiji"

"Suva"

"Kiribati"

"South Tarawa"

"Niue"

"Alofi"

Use the country-and-capital table to see direct lookup relationships between keys and values. section 7.5.1

How Rust in Action: Systems programming concepts and techniques covers it

How deep it goes
Descends from the key-value model through in-memory APIs to file-backed persistence, checksums, indexing, and hardware-failure durability.
Examples
Uses country-capital mappings, an in-memory command-line application, and a complete Rust file-backed implementation.
What you can do after
Build it from scratch as a Rust key-value store that stores, retrieves, indexes, and persists arbitrary byte sequences.
How it connects
Connects key-value stores with files, persistent storage, HashMap, BTreeMap, checksums, and Rust library crates.

Also explained in

Compare how 8 books explain key-value store →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Rust in Action: Systems programming concepts and techniques. The section links point to the parts of the book it draws on.