liveBook · Manning

Singleton database process

As explained in Elixir in Action, Third Edition

A singleton database process is one central process through which all operations on a database resource are serialized.

A singleton database process centralizes operations on a shared resource, serializing access through one server. This prevents races and limits unbounded concurrent I/O, but the server can become a bottleneck. section 7.3.4

Choose among these designs according to the resource and workload:

  • Bypass the process when no long-lived state, reusable resource, or synchronization requirement exists; a plain module can improve parallelism. section 7.3.4
  • Keep the central process but spawn one-off workers when requests share state yet can execute independently. section 7.3.4
  • Keep handlers short and fast so serialized coordination does not prevent many workers from running concurrently. section 7.3.4
Figure 7.3 Handling requests concurrently
CH07_F03_Juric3

Visualizes requests passing through the central server while worker processes perform database operations concurrently. section 7.3.4

How Elixir in Action, Third Edition covers it

How deep it goes
Explains process justification, bypassing, worker spawning, and asynchronous replies without covering broader pooling designs.
Examples
Uses file-backed storage with spawned workers for store casts and get calls replied through GenServer.reply.
What it assumes
Assumes familiarity with processes and shared resources while identifying long-lived state and synchronization requirements.
What you can do after
Apply it via GenServer, spawn, and GenServer.reply to separate serialized coordination from concurrent file operations.
How it connects
Connects GenServer handlers with shared state, critical sections, race conditions, parallelism, and scalability.

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.