liveBook · Manning

Database process

As explained in Elixir in Action, Third Edition

A database process is a concurrent process that handles requests to store and retrieve application data.

A database process isolates persistence behind a concurrent server. Clients store values by key and retrieve them later, while the process serializes file access and hides its PID through local registration. section 7.3.1

The simple implementation stores each key in a same-named file, encoding arbitrary Erlang terms as binaries. It favors clarity over production robustness so concurrency behavior remains visible. section 7.3.1

The request interface makes an explicit availability–consistency trade-off:

  • Use a cast for store when callers need no response; they continue immediately, improving responsiveness and scalability. section 7.3.1
  • Use a call for get when callers require the retrieved value. section 7.3.1
  • Accept that casts provide no confirmation that a request arrived or succeeded, weakening consistency guarantees. section 7.3.1

The surrounding system starts the database from the cache, persists a to-do list after each modification, and loads it on first initialization. Long disk reads should not block GenServer.start, so two-phase initialization defers loading to handle_continue/2. section 7.3.2

Persisting a named list

Todo.Server.add_entry updates its in-memory list and calls Todo.Database.store(name, new_list). On restart, the server retrieves that name and restores the saved list, or creates an empty list when no file exists.

How Elixir in Action, Third Edition covers it

How deep it goes
Explains request callbacks, file encoding, registration, trade-offs, integration, and deferred initialization, but uses deliberately simple file storage.
Examples
Uses Todo.Database, named to-do lists, persist files, and interactive retrieval after restarting the server.
What it assumes
Assumes familiarity with Elixir processes, GenServer callbacks, message casts, calls, and basic file and term serialization.
What you can do after
Build it from scratch as a GenServer that exposes cast-based writes, call-based reads, and persisted process state.
How it connects
Links GenServer processes with casts, calls, process state, persistence, and two-phase initialization.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Elixir in Action, Third Edition. The section links point to the parts of the book it draws on.