The Real Fullstack

The Exhausted Connection Pool

PostgreSQL CPU sits at 22%. Why are requests timing out waiting for a database connection?

Engenheiro sênior10 minLaboratório de performanceSimulador de fluxo
javaspring-boothikaricppostgresqlkubernetes

Este desafio ainda não foi traduzido para Português (Brasil). Você está lendo a versão em inglês.

Missão:Serve 500 req/s with ≤ 0.5% errors and the pool at most half utilised, without exceeding the database's 100 connections.Contexto · Objetivos de aprendizagem ▾

Brightcart's order service runs 6 pods with a HikariCP pool of 10 each, against a PostgreSQL server allowing 100 connections. At 500 orders per second, requests fail with “Connection is not available”. The team's first idea: bigger pools, more pods.

Missão: Serve 500 req/s with ≤ 0.5% errors and the pool at most half utilised, without exceeding the database's 100 connections.

Objetivos de aprendizagem

  • Read pool metrics and pg_stat_activity to find hold time.
  • Keep transactions short: no remote calls while holding a connection.
  • Understand how replicas × pool size meets max_connections.
Simulação
Simulado
Load balancerOrder service podsConnection poolsPostgreSQLFraud check API
Executar simulação
@Transactional                               // connection borrowed here …public Order place(OrderRequest r) {  Order o = orders.save(Order.pending(r));  FraudVerdict v = fraudClient.check(r);     // … held during a 120 ms HTTP call  o.apply(v);  return o;                                  // … and returned only at commit}

Simplificação

Steady-state queueing. Connection hold time is fixed per request; the database is modelled as 16 cores. Modelo educacional — os números ilustram comportamento, não são benchmarks.

Conceitos

Útil antes deste

Desafios relacionados

Referências