Scrivio Interview library
DebuggingFoundations6 min read · updated 13 November 2026

A Spring Boot MVC service with 200 Tomcat threads uses Jedis through Spring Data Redis with default pool settings. Under a load test, requests fail with 'Could not get a resource from the pool' while Redis CPU stays at 15 percent.

What is the bottleneck, and how do you size and configure the pool?

The bottleneck is the client's connection pool, not Redis. Jedis connections cannot be shared between threads, so each Redis call borrows one from a commons-pool2 pool whose default maximum, spring.data.redis.jedis.pool.max-active, is 8, and 200 Tomcat threads end up queuing for 8 connections until they time out. We fix it by sizing max-active to the concurrency that really calls Redis, setting a short max-wait and a sensible min-idle, checking the total against Redis maxclients, removing code that holds connections for long, or by switching to Lettuce, which multiplexes threads over one connection per node.

Why this question is asked

"Could not get a resource from the pool" is one of the most common Redis errors in Java services, and it nearly always appears while Redis itself is relaxed. Interviewers like it because it tests whether we look at the client side of a bottleneck before blaming the server. In this answer, we will recap how the Jedis pool works, see why 200 threads collide with a pool of 8, size and configure the pool, check the server-side limit, look for code that holds connections too long, and consider switching to Lettuce.

1A Quick Recap of the Jedis Pool

A Jedis connection is a blocking TCP socket, and it is not thread-safe. Spring Data Redis's JedisConnectionFactory therefore keeps a pool, built on Apache commons-pool2. For every Redis operation, RedisTemplate borrows a connection, runs the command, and returns it. If no idle connection exists and the pool has not reached its maximum, it opens a new one; if it has reached the maximum, the borrowing thread waits up to the maximum wait time and then fails.

Spring Boot's defaults for this pool are small: max-active 8, max-idle 8, min-idle 0. The default max-wait in Spring Boot is -1, meaning wait indefinitely, so the exact error depends on what the service configured; when a wait limit is set, a borrower that gives up surfaces as the error in the question. Check the defaults for your version.

2Why 200 Threads Collide With 8 Connections

Each Tomcat thread that serves a request and needs Redis borrows a connection. During the load test, far more than 8 threads need Redis at the same moment. The first 8 get connections; the rest queue. Since each call takes about a millisecond plus network time, the 8 connections are busy all the time, the queue keeps growing, and threads that wait longer than the limit fail. Redis meanwhile sees at most 8 commands at a time and sits at 15 percent CPU.

Step throughThreads waiting for a pool of 8
Tomcat threads 1-8Tomcat threads 9-200Jedis pool (max 8)Redis
borrow
8 connections handed out
borrow (pool exhausted, wait)
GET / SET, ~1 ms each
return connections
a few waiters get one
the rest time out: Could not get a resource

7 messages in order. Play them, or step through them one at a time.

Redis is idle because the client lets only 8 commands through at a time.

3Sizing and Configuring the Pool

The pool should be as large as the number of threads that call Redis at the same time, not the total number of threads. We can estimate it with Little's law: concurrency equals request rate times time per call. If the service makes 20,000 Redis calls per second and each takes 2 ms including network, it needs about 40 connections busy on average, so a maximum of 64 to 128 leaves room for bursts.

Java
# application.yml
spring:
data:
redis:
client-type: jedis
timeout: 500ms # socket read timeout per command
jedis:
pool:
enabled: true
max-active: 96 # concurrent Redis callers, not Tomcat threads
max-idle: 96 # keep them open; no churn after bursts
min-idle: 16 # warm connections after quiet periods
max-wait: 50ms # fail fast instead of piling up threads

Notice why each value matters. A short max-wait makes callers fail quickly when Redis really is unavailable, instead of holding Tomcat threads for seconds and spreading the outage upstream. Setting max-idle equal to max-active avoids closing connections after a burst only to reopen them on the next one. min-idle keeps some connections ready, so a quiet period followed by a spike does not open dozens of connections at once.

4Checking the Server Side

A bigger pool per pod multiplies across the fleet. Redis has a limit on client connections, maxclients, which defaults to 10,000 and is often lower on managed services. With 50 pods and a pool of 128, the service alone could open 6,400 connections, and other services share the same Redis. So we add up pods times max-active for every client and keep the total well below maxclients, and we watch connected_clients in INFO clients during the test. Each connection also costs some memory on the server, so thousands of idle ones are not free.

5Finding Code That Holds Connections Too Long

Sometimes the pool is large enough, but connections are held far longer than a single command. Common causes are large replies such as HGETALL on huge hashes or LRANGE 0 -1 on long lists, blocking commands such as BLPOP, and pipelines or SessionCallback blocks that do slow work, like calling another service, while holding the connection. Using RedisTemplate's normal operations returns the connection immediately after each command; code that takes a connection directly through getConnection() must close it in a finally block or a try-with-resources, or the connection leaks and the pool slowly empties.

6Or Switch to Lettuce

Lettuce avoids the problem by design. Its connection is thread-safe, so all 200 threads share one connection per Redis node and their commands are pipelined over it. There is no borrowing and no pool limit for ordinary commands. A pool is only needed for blocking commands and transactions, which need a connection to themselves. For a Spring Boot MVC service, removing the Jedis dependency usually switches back to Lettuce, the default, with no code changes, but test it under the same load, because the latency behaviour changes.

Options compared
OptionConnections per podTrade-off
Default Jedis pool8threads queue and time out
Sized Jedis pool64 to 128more server connections; simple model
Lettuce shared connection1 per node (+ small pool for blocking)one slow reply delays others

7Follow-up questions

Which metrics would show pool waits in production?

The commons-pool2 pool registers JMX beans with values such as NumActive, NumIdle, NumWaiters, MeanBorrowWaitTimeMillis and MaxBorrowWaitTimeMillis, which can be exported to Prometheus. NumActive at max-active together with a non-zero NumWaiters and growing borrow wait time means the pool is the bottleneck. On the Redis side, connected_clients and the latency of commands stay normal, which confirms the server is not the limit. Request latency percentiles of the endpoints that use Redis complete the picture.

Why not just set max-active to 200 to match the Tomcat threads?

It would work for one pod but wastes connections, since rarely all 200 threads call Redis at once, and across many pods it can exceed Redis's maxclients. Sizing to real concurrency, measured or estimated with Little's law, is cheaper and safer.

Should testOnBorrow be enabled?

It sends a PING on each borrow to verify the connection, which adds a round trip per call. testWhileIdle with an eviction interval catches dead connections in the background at much lower cost, and is usually the better choice.

8Conclusion

In this answer, we found the bottleneck in the client: Jedis connections cannot be shared, so 200 Tomcat threads queued for the default 8 pooled connections while Redis was idle. We sized the pool from real concurrency, added a short max-wait and a warm min-idle, checked the fleet total against maxclients, and looked for code that holds connections too long. Switching to Lettuce, which shares one connection per node, removes the pool limit for ordinary commands.

What to say in the interviewAbout 90 seconds aloud

Open with

Redis at 15 percent CPU tells me the bottleneck is on the client. Jedis connections are not thread-safe, so Spring Data Redis keeps a commons-pool2 pool, and each Redis call borrows a connection for the duration of the call.

Then, if they want more

The default max-active is 8, so 200 Tomcat threads queue for 8 connections, Redis only ever sees 8 commands at a time, and the waiters time out with could not get a resource from the pool. I would size the pool to the concurrency that actually calls Redis, not to the Tomcat thread count.

With Little's law, 20,000 calls per second at 2 milliseconds each is about 40 busy connections, so a max-active of 64 to 128 gives room for bursts.

I would set max-wait short, around 50 milliseconds, so callers fail fast instead of holding threads, set max-idle equal to max-active, and set min-idle so a burst after a quiet period does not open many connections at once.

Then I check the server side: pods times pool size must fit within maxclients, and 50 pods with 128 each is already 6,400. I would also look for code that holds connections, like huge replies, blocking commands or slow work inside a pipeline.

Or I would switch to Lettuce, which multiplexes all threads over one connection per node and needs a pool only for blocking commands and transactions.

About this answer

Last updated
13 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
Redis documentation
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "What is the bottleneck, and how do you size and configure the pool?": https://scrivio-interview-library.netlify.app/databases/redis-scaling/df35e6a204/