Theory / 10 min
Pipelining And Output Buffers
Pipelining is one of Redis' simplest performance wins because it attacks a cost outside the database: waiting for the network.
Without pipelining, a client often behaves like this:
send command
wait for reply
send command
wait for reply
send command
wait for reply
Each wait pays at least one round trip. If the client and server are separated by even a few milliseconds, the delay dominates small Redis commands.
With pipelining, the client sends several commands before reading replies:
send command A
send command B
send command C
read reply A
read reply B
read reply C
The server still executes the commands in order for that connection. The improvement comes from keeping the wire busy.
No Special Server Mode Is Required
RESP and the connection buffer already make pipelining natural.
The input buffer may contain multiple complete commands. The server parses one command, dispatches it, removes the consumed bytes, and continues parsing until it reaches incomplete input.
read bytes
-> parse command A
-> execute A
-> queue reply A
-> parse command B
-> execute B
-> queue reply B
From the command handler's perspective, nothing exotic is happening. It receives one command at a time. Pipelining is a property of how requests are batched over the connection, not a new semantic mode.
Replies Need Buffers
If the server produces replies faster than the socket can accept them, those replies need somewhere to live.
That place is the client's output buffer:
command reply -> serialized RESP bytes -> client output queue -> socket writes
Output buffering preserves reply order and handles partial writes. If the operating system accepts only part of a response, the remaining bytes stay queued until the socket becomes writable again.
This is especially important for pipelining because one read can produce many replies before the client reads any of them.
Slow Clients Are A Memory Problem
Output buffers turn network delay into memory usage. That is fine when the buffer is small and temporary. It is dangerous when a client stops reading or reads too slowly.
Pub/Sub makes the issue sharper. A client may receive messages it did not explicitly request one by one. Replicas also depend on output-like replication streams. If a replica falls behind, the primary has to decide how much backlog and buffering it is willing to carry.
Redis therefore uses output buffer limits, often with different policies for normal clients, Pub/Sub clients, and replicas. A server must be willing to disconnect clients that cannot keep up.
Pipelining Is Not Atomicity
Pipelining reduces network waiting. It does not group commands into an atomic transaction.
If a client pipelines:
SET a 1
INCR a
GET a
those commands are executed in order on that connection, but other clients may execute commands between them unless they are wrapped in a transaction or script. Pipelining is about transport efficiency, not isolation.
The Clean Separation
The beauty of Redis pipelining is that it falls out of three good boundaries:
RESP parser handles multiple frames
command dispatcher handles one command at a time
output buffer preserves reply order despite socket timing
That separation lets Redis gain large throughput improvements without complicating command semantics.
See what actually stuck.
Take the practice scenarios now.