liveBook · Manning

Connection pooling

As explained in Elixir in Action, Third Edition

A database connection pool is a bounded collection of reusable database connections managed to constrain simultaneous database operations.

Connection pooling bounds concurrency when an underlying resource, such as database or disk I/O, cannot handle unbounded simultaneous operations. Requests reach one coordinating process and are quickly delegated to a fixed set of workers. section 7.3.4

A practical pool design:

  • Create several worker processes and retain their PIDs in coordinator state. section 7.3.4
  • Select a worker for each request using round-robin distribution or a key-based strategy. section 7.3.4 section 7.3.5
  • Route identical keys to the same worker when per-key synchronization is required. section 7.3.5
  • Keep the public database interface unchanged while forwarding get and store operations internally. section 7.3.5
Figure 7.4 Pooling database operations
CH07_F04_Juric3

Visualizes how a coordinating database process distributes operations across pooled workers. section 7.3.4

How Elixir in Action, Third Edition covers it

How deep it goes
Explains coordinator state, worker delegation, distribution strategies, stable key routing, and interface preservation.
Examples
Uses three workers, PID maps, stable key selection, and Todo.Database forwarding get and store requests.
What it assumes
Assumes familiarity with Elixir processes, GenServer callbacks, PIDs, and request forwarding.
What you can do after
Build a three-worker database pool while preserving the existing public interface and per-key synchronization.
How it connects
Connects processes, GenServer, concurrency, load distribution, and synchronization.

Also explained in

Compare how 9 books explain connection pooling →

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.