PRO

Effect Fair Connection Pool

A bounded pool with FIFO waiting and a fast-fail timeout instead of a hang. Opening a connection per request lets a spike exhaust the database's connection limit so even cheap queries fail; a bounded pool caps concurrency at what the database can serve and makes surplus demand wait. An unbounded wait turns backpressure into a hang, so waiting is FIFO (no waiter starves) and bounded by an acquire timeout that fails with a typed AcquireTimeout under saturation. Acquire and release are single Ref.modify hand-offs, so a connection is issued to exactly one waiter and never double-issued. The demo caps 12 concurrent requests at 3 and fails fast when saturated. Pinned to effect 4.0.0-beta.98.

Install
npx shadcn@latest add https://ui.aryank.space/r/effect-connection-pool-fair.json

Installs from ui.aryank.space. To add it by hand, copy the files in Files below, or register the @compronents namespace via the docs.

Visualization
12 requests
readonly Request[]
FINALIZERS
inFlight >= limit ? enqueue(waiter) : take(idle)

The pool caps concurrency at what the database can serve: 12 concurrent requests against 3 connections never run more than 3 at once. Surplus waits FIFO, and a saturated wait fails fast with AcquireTimeout instead of hanging.

Files

Dependencies