<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Tony</title>
    <description>The latest articles on DEV Community by Tony (@tony_hp).</description>
    <link>https://dev.to/tony_hp</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3862376%2F8308e039-9c18-415f-905d-d645df7adac5.png</url>
      <title>DEV Community: Tony</title>
      <link>https://dev.to/tony_hp</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tony_hp"/>
    <language>en</language>
    <item>
      <title>The connection pool paradox: why more connections slow your database down</title>
      <dc:creator>Tony</dc:creator>
      <pubDate>Wed, 08 Apr 2026 13:39:06 +0000</pubDate>
      <link>https://dev.to/tony_hp/the-connection-pool-paradox-why-more-connections-slow-your-database-down-2kjg</link>
      <guid>https://dev.to/tony_hp/the-connection-pool-paradox-why-more-connections-slow-your-database-down-2kjg</guid>
      <description>&lt;p&gt;When you hit connection timeouts under high load, the instinct is to bump max_connections to 100 or 200. Don't do it, it'll crash your server faster — CPU hits 100%, IOPS maxes out, everything freezes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Here's why&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Think of a grocery store with 4 checkout lanes (= 4 CPU cores). If customers queue up properly, throughput is great. But if 200 people rush all 4 lanes at once, cashiers spend more time context-switching between customers than actually checking anyone out. Nobody finishes faster.&lt;/p&gt;

&lt;p&gt;Two things kill you at the OS level:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Context switching&lt;/strong&gt; — a CPU core physically handles one thread at a time. With 200 open connections on a 4-core machine, the OS constantly saves and restores connection state (registers, cache) to keep everyone "running." At extreme counts, up to 80% of CPU time goes to switching — not actual work.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Disk contention&lt;/strong&gt; — databases love sequential reads. Hundreds of concurrent connections destroy that pattern, turning it into random I/O even on SSDs. Your disk queue backs up, buffer cache stops being effective.&lt;/p&gt;

&lt;p&gt;The right number is smaller than you think&lt;br&gt;
max_connections = (cores × 2) + effective_spindle_count&lt;/p&gt;

&lt;p&gt;For an 8-core server with SSD: 8 × 2 + 1 = 17&lt;/p&gt;

&lt;p&gt;Modern stacks handle this differently&lt;/p&gt;

&lt;p&gt;In microservices and serverless, you put a smart proxy (PgBouncer, RDS Proxy) on the database side. It maintains a small pool of real DB connections and multiplexes thousands of app connections onto them. Your app-side pool then only exists to reuse TCP connections — the heavy lifting moves to the proxy.&lt;/p&gt;

&lt;p&gt;To sum up: connection pools aren't more better. They're about matching concurrency to what your hardware can actually parallelize.&lt;/p&gt;

&lt;p&gt;Curious how others handle this in production:&lt;br&gt;
Do you cap connections aggressively, or rely on proxies like PgBouncer / RDS Proxy?&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpn5leup6waztujnmjphl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpn5leup6waztujnmjphl.png" alt=" " width="800" height="356"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>backend</category>
      <category>database</category>
      <category>performance</category>
    </item>
  </channel>
</rss>
