backenddrills

Complete free practice · 8 minutes

Java connection pool debugging: a free practice drill

Checkout latency spikes while database CPU stays low. Find what is holding the connections.

Inspect the supplied evidence, write your hypothesis, then compare your choices with the reasoning. This educational simulation is free without an account or payment. Read the exercise here, or use the interactive lab to record your decisions.

Start this interactive free drill →See the complete edition · $28 one-time

The incident brief

At 14:05, checkout p95 rises after a fraud-provider slowdown. The service keeps accepting requests. Orders eventually finish, but new requests time out waiting for a database connection.

Environment and evidence

Spring Boot 3.x · JDBC transaction manager · HikariCP · PostgreSQL

14:05:02 active=30 idle=0 pending=146
14:05:03 Connection is not available, request timed out
Trace: begin tx → SELECT order (7 ms)
       → fraudClient.check() (8,120 ms) → UPDATE (5 ms)
Database sessions: mostly idle in transaction

Decision 1: Diagnose

What best explains a saturated pool with little database work?

  1. The database needs a new index.
  2. Slow network calls are extending connection ownership inside a transaction.
  3. The pool is definitely leaking connections forever.
Reveal the reasoning after choosing

Option A: The trace spends most of its time outside SQL. Check connection hold time before tuning this query.

Option B: The transaction already executed SQL and keeps its connection while the provider call waits.

Option C: Long connection holds resemble a leak, but these requests eventually release their connections. Confirm duration and ownership first.

Decision 2: Stabilize

The fraud check is required. What is the safest immediate response?

  1. Admit fewer checkouts, set a bounded provider timeout, and return an explicit retryable outcome.
  2. Increase the pool from 30 to 300 immediately.
  3. Restart instances in a staggered way.
Reveal the reasoning after choosing

Option A: Bound the waiting work while preserving the fraud requirement. Reconcile ambiguous provider outcomes rather than silently approving them.

Option B: A larger pool can overwhelm the database and leaves the long hold time in place.

Option C: This can clear waiting requests temporarily, but new traffic will encounter the same provider delay.

Decision 3: Prevent

What change addresses the failure mechanism?

  1. Disable connection timeout so every request eventually succeeds.
  2. Cache the provider response for every customer indefinitely.
  3. Use short database transactions around durable states, and call the provider outside them.
Reveal the reasoning after choosing

Option A: Unbounded waiting can exhaust the service before the provider recovers.

Option B: This changes fraud decisions and ignores freshness and risk requirements.

Option C: Record a pending state, perform the remote check, then complete in a short transaction. Add idempotency and recovery for crashes between steps.

Read the debrief after all three decisions

The mechanism

The transaction lifetime includes slow external I/O after a connection has been acquired.

Verify the fix

Explain it in your own words

I would compare connection acquisition time with hold time and trace the slow checkout. Here the fraud request dominates while a database connection remains borrowed. I would bound admitted work, preserve the required check, and make failures explicit. Then I would separate the external call from short state transitions, handling retries and ambiguous outcomes with a durable order state.

Continue with the same skill

Read the related free guide → · Choose a structured study path →

Is this practice format useful to you?

The full edition contains 1008 exercises and 3024 decisions across 18 topics. Practice testing, SQL, APIs, Java 8, Java 21, design patterns, system design, cybersecurity and cloud. Related exercises revisit mechanisms through different decision lenses. You receive authored reviews and five study paths; this is a decision workbook, not a code execution service.

Explore everything included for $28 →

One-time payment. No subscription. Review the purchase and refund terms before buying.

Primary documentation

Original educational examples, prepared with AI assistance. No employer question, customer incident or hiring outcome is claimed. Editorial approach.

Try another free drill