The API CPU is low but booking latency is rising. Why might adding tasks make it worse?
After this you can answer: The API CPU is low but booking latency is rising. Why might adding tasks make it worse?
Say it in 30 seconds
Section titled “Say it in 30 seconds”The deeper answer
Section titled “The deeper answer”The pool reuses connections instead of reconnecting for each query. Its maximum is per process, not per deployment. A deployment with overlapping old and new tasks can therefore have more connections than the steady task count suggests, alongside migrations and operator sessions.
A booking waiting on the event lock already holds a database connection. The outbox relay also holds a transaction while publishing to SNS. Those waits can consume a pool even when Node is doing little CPU work. The current pool uses a two-second connection timeout and a five-second statement timeout, including SQL lock waits; these are not a single end-to-end request deadline.
I would correlate increased latency with active sessions, lock waits, query plans and outbox publishing delays. Reduce unnecessary work, protect admission and keep transactions short before enlarging the pool. A larger database or more connections can help only after identifying the constrained resource; it cannot parallelize conflicting updates to one event row.
Counter-questions
Section titled “Counter-questions”Why not set the pool to the database maximum?
Does a statement timeout guarantee a fast request?
What evidence would justify more API tasks?
Where in MiniTickets
Section titled “Where in MiniTickets”Read Rds postgres, then inspect the rds-postgres piece →.
apps/api/src/db/client.ts → poolRead this book online: https://book.theversehub.in/