liveBook · Manning

In-memory database

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

An in-memory store is a storage implementation that keeps its data in volatile memory rather than persistent storage.

An in-memory database stores task and event state in process memory. In a task orchestrator, it provides a concrete Store implementation behind the same interface used by the manager and worker, so callers can save and retrieve state without depending on map internals. section 11.2 section 11.5

Figure 11.1 The mental model of our store interface
11-01

The store sits between orchestration components and concrete storage choices: both the manager and worker use one Store interface, while in-memory and persistent stores supply the implementation. section 11.2

The interface defines four operations: Put stores a value under a string key, Get retrieves one value, List returns stored values, and Count reports their number. A deletion operation is omitted because task history is treated as a record, though removal could support datastore maintenance. section 11.2

Typed task-event store

A task-event store wraps a map from strings to pointers to task events. Its Put method checks that the supplied value is a task-event pointer before inserting it; Get returns an error for a missing key; List builds a slice by iterating over the map. A task store follows the same pattern for task values. section 11.4

Use an in-memory store through the abstraction rather than direct map access:

  • Choose the memory datastore type during manager construction, then create separate task and event stores. section 11.5
  • Retrieve a task with Get, handle a missing-key error, and type-assert the returned interface value before updating it. section 11.5
  • Write changed task state back with Put, and obtain task collections with List rather than ranging over the backing map. section 11.5

This design decouples orchestration logic from the storage mechanism. The same manager and worker code can select memory for development or a persistent implementation for production by passing a datastore type to construction. The tradeoff is durability: map-backed state disappears when the manager or worker restarts, while a persistent store can retain tasks and events on disk for recovery. section 11.12 section 11.5

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

How deep it goes
Implements typed map-backed event storage and traces manager refactoring to Get, Put, and List calls.
Examples
Demonstrates task-event map storage, manager datastore selection, typed Get results, Put updates, and List-based task retrieval.
What it assumes
Assumes familiarity with Go structs, maps, interfaces, pointers, type assertions, and error handling.
What you can do after
Build it from scratch as typed map-backed task and event stores selected through a Store interface.
How it connects
Connects Store interfaces, Go maps, task orchestration, persistent storage, BoltDB, and failure recovery.

Also explained in

Compare how 5 books explain in-memory database →

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.