[{"data":1,"prerenderedAt":159},["ShallowReactive",2],{"term-c\u002Fconnection-pooling":3,"related-c\u002Fconnection-pooling":144},{"id":4,"title":5,"acronym":6,"body":7,"category":125,"description":126,"difficulty":127,"extension":128,"letter":129,"meta":130,"navigation":131,"path":132,"related":133,"seo":138,"sitemap":139,"stem":142,"subcategory":6,"__hash__":143},"terms\u002Fterms\u002Fc\u002Fconnection-pooling.md","Connection Pooling",null,{"type":8,"value":9,"toc":119},"minimark",[10,15,19,23,26,30,108,112,115],[11,12,14],"h2",{"id":13},"eli5-the-vibe-check","ELI5 - The Vibe Check",[16,17,18],"p",{},"Opening a new database connection is expensive, like calling a new person into a meeting room every single time you need one quick question answered. Connection pooling keeps a stack of already-open connections on standby and hands them out on demand, so your app reuses the same warm connections instead of paying the setup cost over and over.",[11,20,22],{"id":21},"real-talk","Real Talk",[16,24,25],{},"Connection pooling maintains a pool of pre-established database connections that application processes borrow and return instead of opening and closing a new connection per request. It reduces connection setup overhead and, more importantly, caps the total number of concurrent connections a database has to handle, which matters because databases like Postgres struggle past a few hundred direct connections.",[11,27,29],{"id":28},"show-me-the-code","Show Me The Code",[31,32,37],"pre",{"className":33,"code":34,"language":35,"meta":36,"style":36},"language-javascript shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","\u002F\u002F pg-pool config\nconst pool = new Pool({ max: 20, idleTimeoutMillis: 30000 });\n","javascript","",[38,39,40,49],"code",{"__ignoreMap":36},[41,42,45],"span",{"class":43,"line":44},"line",1,[41,46,48],{"class":47},"sHwdD","\u002F\u002F pg-pool config\n",[41,50,52,56,60,64,67,71,74,77,81,84,88,91,94,96,99,102,105],{"class":43,"line":51},2,[41,53,55],{"class":54},"spNyl","const",[41,57,59],{"class":58},"sTEyZ"," pool ",[41,61,63],{"class":62},"sMK4o","=",[41,65,66],{"class":62}," new",[41,68,70],{"class":69},"s2Zo4"," Pool",[41,72,73],{"class":58},"(",[41,75,76],{"class":62},"{",[41,78,80],{"class":79},"swJcz"," max",[41,82,83],{"class":62},":",[41,85,87],{"class":86},"sbssI"," 20",[41,89,90],{"class":62},",",[41,92,93],{"class":79}," idleTimeoutMillis",[41,95,83],{"class":62},[41,97,98],{"class":86}," 30000",[41,100,101],{"class":62}," }",[41,103,104],{"class":58},")",[41,106,107],{"class":62},";\n",[11,109,111],{"id":110},"when-youll-hear-this","When You'll Hear This",[16,113,114],{},"\"Serverless functions need external connection pooling or they'll exhaust Postgres.\" \u002F \"We put PgBouncer in front of the database to handle pooling at scale.\"",[116,117,118],"style",{},"html pre.shiki code .sHwdD, html code.shiki .sHwdD{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#546E7A;--shiki-default-font-style:italic;--shiki-dark:#676E95;--shiki-dark-font-style:italic}html pre.shiki code .spNyl, html code.shiki .spNyl{--shiki-light:#9C3EDA;--shiki-default:#C792EA;--shiki-dark:#C792EA}html pre.shiki code .sTEyZ, html code.shiki .sTEyZ{--shiki-light:#90A4AE;--shiki-default:#EEFFFF;--shiki-dark:#BABED8}html pre.shiki code .sMK4o, html code.shiki .sMK4o{--shiki-light:#39ADB5;--shiki-default:#89DDFF;--shiki-dark:#89DDFF}html pre.shiki code .s2Zo4, html code.shiki .s2Zo4{--shiki-light:#6182B8;--shiki-default:#82AAFF;--shiki-dark:#82AAFF}html pre.shiki code .swJcz, html code.shiki .swJcz{--shiki-light:#E53935;--shiki-default:#F07178;--shiki-dark:#F07178}html pre.shiki code .sbssI, html code.shiki .sbssI{--shiki-light:#F76D47;--shiki-default:#F78C6C;--shiki-dark:#F78C6C}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":36,"searchDepth":51,"depth":51,"links":120},[121,122,123,124],{"id":13,"depth":51,"text":14},{"id":21,"depth":51,"text":22},{"id":28,"depth":51,"text":29},{"id":110,"depth":51,"text":111},"backend","Opening a new database connection is expensive, like calling a new person into a meeting room every single time you need one quick question answered.","intermediate","md","c",{},true,"\u002Fterms\u002Fc\u002Fconnection-pooling",[134,135,136,137],"PgBouncer","PostgreSQL","Read Replica","Transaction",{"title":5,"description":126},{"changefreq":140,"priority":141},"weekly",0.7,"terms\u002Fc\u002Fconnection-pooling","DVDu_HoKL9vtAteMUPGDjJW9pfq_eyxbew41RF5RBJ4",[145,149,153,156],{"title":134,"path":146,"acronym":6,"category":147,"difficulty":127,"description":148},"\u002Fterms\u002Fp\u002Fpgbouncer","database","PgBouncer is a lightweight connection pooler that sits in front of PostgreSQL and recycles database connections like a good environmentalist.",{"title":135,"path":150,"acronym":6,"category":147,"difficulty":151,"description":152},"\u002Fterms\u002Fp\u002Fpostgresql","beginner","PostgreSQL (just say 'Postgres') is the Swiss Army knife of databases.",{"title":136,"path":154,"acronym":6,"category":147,"difficulty":127,"description":155},"\u002Fterms\u002Fr\u002Fread-replica","A read replica is a copy of your database that only handles read queries.",{"title":137,"path":157,"acronym":6,"category":147,"difficulty":127,"description":158},"\u002Fterms\u002Ft\u002Ftransaction","A transaction groups multiple database operations into one all-or-nothing bundle. Either ALL of them succeed, or NONE of them happen.",1792528073561]