Scrivio Interview library
DebuggingIntermediate7 min read · updated 13 November 2026

Instances of a notification service subscribed to Redis pub/sub disconnect and reconnect every few minutes during peaks, losing messages. The Redis log shows lines saying such clients were scheduled to be closed for overcoming output buffer limits.

Explain the cause and the fixes on both the server and the client side.

The subscribers read more slowly than Redis publishes, so the messages waiting for them pile up in their output buffers on the server until they pass the pub/sub limit (32 MB at once, or 8 MB for 60 seconds by default) and Redis disconnects them. The real fix is on the client: keep the reading thread free by handing each message to a bounded executor, subscribe only to what the instance needs, send smaller messages, and add catch-up from a durable source because pub/sub never redelivers.

Why this question is asked

Pub/sub looks free until a peak arrives. Then a slow consumer turns into a memory problem on the Redis server, Redis protects itself by cutting the consumer off, and every message published while it was gone is lost for good. Interviewers like this question because it tests whether we know that Redis buffers per client, that pub/sub has no replay, and whether we fix the slow reader instead of only raising a limit. In this answer, we will recap how Redis delivers pub/sub messages, follow the buffer as it grows during a peak, fix the client, look at the server settings and their cost, and add the monitoring and catch-up that make lost messages recoverable.

1A Quick Recap of Pub/Sub Delivery and Output Buffers

In Redis pub/sub, a publisher sends PUBLISH channel message, and Redis immediately pushes that message to every client currently subscribed to the channel, or to a pattern that matches it. Redis does not store the message anywhere. If a subscriber is not connected at that moment, it never sees the message.

Pushing a message means writing it into the subscriber's output buffer, a piece of server memory that holds data Redis has produced for a client but the client has not read from the socket yet. Normally the buffer drains in microseconds. But if the client stops reading, the buffer keeps growing with every published message.

So Redis puts limits on output buffers, separately for three classes of clients: normal clients, replicas and pub/sub subscribers. The pub/sub default is client-output-buffer-limit pubsub 32mb 8mb 60. The first number is a hard limit: the moment a subscriber's buffer passes 32 MB, Redis closes it. The other two form a soft limit: if the buffer stays above 8 MB for 60 seconds in a row, Redis closes it too. The log line in the question, a client scheduled to be closed for overcoming output buffer limits, is exactly this rule firing.

2Why the Buffer Grows During Peaks

Redis can publish far faster than a typical listener can process. Suppose a peak brings 4,000 notifications per second of 2 KB each, which is 8 MB per second of data for each subscriber. If the listener handles each message with a database lookup and an HTTP call taking 5 ms, one thread processes only 200 messages per second. The other 3,800 per second stay in the server-side buffer, and after about 4 seconds it passes 32 MB.

The usual cause is that the listener does this blocking work on the very thread that reads from the Redis connection. While that thread waits for the database, nobody reads the socket, the TCP window fills, and Redis has to keep everything in memory. Here is the broken shape with Jedis, whose subscribe call runs the listener on the subscribing thread.

Java
JedisPubSub listener = new JedisPubSub() {
@Override public void onMessage(String channel, String message) {
Notification n = repository.load(message); // 3 ms database call on the reading thread
pushGateway.send(n); // 2 ms HTTP call, still on the reading thread
}
};
jedis.psubscribe(listener, "notify:*"); // blocks; this thread is also the socket reader
Step throughHow a slow subscriber gets disconnected
  1. Publisher sends PUBLISH4,000 messages per second at the peak
  2. Redis writes each message to every subscriber's bufferno copy is kept anywhere else
  3. Subscriber thread is busy in a database callsocket is not read
  4. Buffer above 32 MB, or above 8 MB for 60 s?
    YesRedis closes the clientNoBuffer keeps growing
  5. Client reconnects and resubscribesmessages published meanwhile are gone

5 steps in order. Play them, or step through them one at a time.

Notice the second problem in the last line. A broad pattern such as notify:* makes every instance receive every notification, even the ones meant for users connected to other instances, so each instance does more work than it needs.

3Fixing the Client First

The fix is to make the reading thread do nothing except take the message and hand it on. The work moves to a separate, bounded pool of threads. Bounded matters: an unbounded queue would only move the memory problem from the Redis server into our JVM.

Java
ExecutorService workers = new ThreadPoolExecutor(16, 16, 0, TimeUnit.SECONDS,
new ArrayBlockingQueue<>(10_000), // at most 10,000 waiting messages
new ThreadPoolExecutor.DiscardOldestPolicy()); // when full, drop the oldest and count it
JedisPubSub listener = new JedisPubSub() {
@Override public void onMessage(String channel, String id) {
workers.execute(() -> deliver(id)); // returns in microseconds; the socket keeps draining
}
};
jedis.subscribe(listener, "notify:instance-7"); // only this instance's channel

Now the reading thread keeps up with Redis, so the server-side buffer stays near zero. If the workers fall behind, the decision about what to drop is made in our code, where we can count the drops and trigger a catch-up, instead of Redis dropping the whole connection.

With Spring Data Redis, the RedisMessageListenerContainer already dispatches messages to listeners through a task executor, but its default executor starts a new thread for each message, which has no bound at all. Give it a ThreadPoolTaskExecutor with a fixed size and queue capacity through setTaskExecutor, and check the details for your version.

The subscription itself shrinks too. Instead of every instance listening to notify:*, each instance subscribes to its own channel, or to the channels of the users connected to it, so it receives only the messages it will actually deliver.

4What to Change on the Server, and What It Costs

Raising the limit is tempting, for example CONFIG SET client-output-buffer-limit "pubsub 64mb 16mb 60". It can be reasonable to absorb short bursts, but every slow subscriber may now hold up to 64 MB of server memory, and with 50 subscribers that is over 3 GB that maxmemory does not plan for. A higher limit also delays the disconnect without fixing the slow reader, so do it only after the client is fixed, and only by a measured amount.

The better server-side change is smaller messages. Publish the notification id, perhaps 40 bytes, instead of a 2 KB payload. The buffers then hold fifty times more messages for the same memory, and the subscriber loads the details from the store that owns them.

5Catching Up and Watching the Buffers

Disconnects will still happen during deploys, network blips or failovers, and pub/sub cannot redeliver. So every subscriber needs a catch-up path from a durable source: on reconnect, it asks the notification store, or reads a Redis Stream or Kafka topic, for anything since the last id it processed.

To see the problem before it bites, run CLIENT LIST and look at the omem field, the output buffer memory of each client, for clients with flags=P (pub/sub). Export it, together with a count of reconnects per instance, and alert when omem grows steadily or reconnects jump during peaks.

Shell
redis-cli CLIENT LIST TYPE pubsub
# id=81 addr=10.0.3.7:52114 ... sub=1 psub=0 ... omem=0 ... cmd=subscribe # healthy
# id=94 addr=10.0.3.9:40022 ... sub=0 psub=1 ... omem=29360128 ... # 28 MB, about to be cut off

6Follow-up questions

Which other client class has its own output buffer limit?

Replicas have their own class, with a default of client-output-buffer-limit replica 256mb 64mb 60. A primary uses that buffer to hold write commands for a replica, including all writes that arrive during a full synchronisation. If the buffer passes the limit, the primary drops the replica and the sync starts again, which can turn into an endless loop on a busy primary. The third class, normal, has no limit by default (0 0 0).

Would Redis Streams avoid this problem?

Mostly, yes. A stream stores entries, and consumers pull them with XREAD or XREADGROUP at their own pace, so a slow consumer falls behind instead of being disconnected and losing data. The cost is memory for the stream itself, so we cap it with MAXLEN or MINID, and consumers in groups must acknowledge entries with XACK.

Does sharded pub/sub in Redis 7 change this?

Sharded pub/sub (SSUBSCRIBE and SPUBLISH) spreads channels over the shards of a cluster, so a message no longer travels to every node. That reduces cluster traffic, but each subscriber still has an output buffer with the same limit, so a slow reader is disconnected in the same way.

7Conclusion

In this answer, we saw that Redis pushes pub/sub messages into a per-client output buffer, and that a subscriber which reads slowly lets that buffer pass the pubsub limit of 32 MB hard or 8 MB for 60 seconds, after which Redis closes it and the messages are lost. We fixed the client by keeping the reading thread free with a bounded executor and narrowing the subscriptions, treated a higher limit as a careful extra rather than the fix, shrank messages to ids, and added catch-up and omem monitoring.

What to say in the interviewAbout 90 seconds aloud

Open with

The log line tells us Redis closed the subscribers for passing the pub/sub output buffer limit, which by default is 32 megabytes at once or 8 megabytes held for 60 seconds.

Then, if they want more

Redis pushes every published message into each subscriber's buffer, and if the subscriber is not reading its socket fast enough, that buffer grows on the server.

During peaks our listener was doing database and HTTP work on the same thread that reads from Redis, so reading stopped while it waited, and with a broad pattern subscription every instance received every message.

My first fix is on the client: the listener only hands the message to a bounded thread pool and returns, and each instance subscribes only to its own channels. I would also publish ids instead of full payloads, so each buffered message is tiny.

Only after that would I consider raising the pubsub limit a little, because a higher limit means slow subscribers can hold more server memory.

Since pub/sub has no persistence or replay, disconnects will still lose messages, so I would add a catch-up path from a durable source, such as the notification table or a stream, keyed by the last id each instance processed.

Finally I would monitor omem in CLIENT LIST for pub/sub clients and the reconnect count per instance, so we see a slow reader before Redis cuts it off.

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 "Explain the cause and the fixes on both the server and the client side.": https://scrivio-interview-library.netlify.app/databases/redis-patterns/51b0cb14cf/