liveBook · Manning

Key-value store

As explained in Build and Orchestrator in Go (From Scratch)

A key/value store is a datastore that associates unique keys with values for direct lookup.

A key-value store associates unique keys with values for direct lookup. Its interface is deliberately small: put data into the store and get it back by key. In a task datastore, a UUID can identify the task stored as its value. section 11.8

For an orchestrator, the store holds data needed by the manager and workers. An embedded key-value store places the datastore library inside the application, avoiding a separately managed database server and network calls for reads and writes. This provides fast, simple access while keeping the system focused on Docker containers. section 1.7 section 11.8

The model becomes concrete through these implementation choices:

  • Use an in-memory Go map as the simplest form of key-value storage. section 11.8
  • Replace transient storage with BoltDB when task and event data must persist. section 11.8
  • Choose the key-value model instead of a relational datastore when strict tables, columns, and SQL are unnecessary. section 11.8

Persisting an orchestrator task

A task enters the store under its UUID. The manager or worker later retrieves that task using the same key. The in-memory map demonstrates the interaction first; BoltDB preserves the same key/value paradigm in an embedded persistent datastore. section 11.8

$ go get github.com/boltdb/bolt/...

Install the BoltDB library before implementing persistent task and event stores. section 11.8

How Build and Orchestrator in Go (From Scratch) covers it

How deep it goes
Develops the key/value model from an in-memory map to persistent BoltDB, while stopping short of detailed storage internals.
Examples
Uses a Go map, UUID-keyed tasks, task and event stores, and BoltDB installation as concrete examples.
What it assumes
Assumes familiarity with Go maps and teaches the transition from in-memory key/value access to embedded persistence.
What you can do after
Operate/configure BoltDB as an embedded persistent store after modeling task data through simple key-based access.
How it connects
Connects key-value storage with embedded datastores, persistence, UUIDs, relational databases, SQL, Cassandra, Redis, and BoltDB.

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 Build and Orchestrator in Go (From Scratch). The section links point to the parts of the book it draws on.