Around Go: MongoDB and Redis · 3 MIN READ

Redis pipelines save round trips; they are not transactions

Bound command batches, inspect command errors and separate batching from atomicity.

Pipelining lets a client send multiple commands without waiting for every individual round trip. It can improve throughput for independent work, but it does not make the group indivisible. Large batches also retain commands and replies in memory and can worsen latency for other work.

Around Go: data stores · A MAP OF THE IDEA

  1. Bounded batch
  2. One network exchange
  3. Per-command result
  4. Partial-failure policy

Useful when

  • Bound command batches, inspect command errors and separate batching from atomicity.

Watch out

  • MULTI/EXEC does not roll back already executed commands after a runtime command error.

Implementation & operation cost: Batches reduce network round trips while retaining command/reply memory and increasing ambiguous partial-outcome work.

01

Batch independent work

Queue a small known batch and inspect the returned command objects. An error from Exec needs interpretation alongside each command result. A connection failure can leave the caller uncertain which writes the server executed; a batch is not an automatic rollback boundary.

go
pipe := rdb.Pipeline()
a := pipe.Get(ctx, "demo:a")
b := pipe.Get(ctx, "demo:b")
_, err := pipe.Exec(ctx)
if err != nil && !errors.Is(err, redis.Nil) { return err }
for _, cmd := range []*redis.StringCmd{a, b} {
    if cmd.Err() != nil && !errors.Is(cmd.Err(), redis.Nil) { return cmd.Err() }
}
Read the code

This fragment batches two independent reads and tolerates missing keys explicitly. A write pipeline needs its own partial-outcome and retry policy; replaying all writes after an ambiguous error can duplicate effects.

02

Choose atomicity separately

MULTI/EXEC groups commands atomically with respect to interleaving, but runtime command errors do not provide relational-database rollback. WATCH adds optimistic checks and can require a whole retry. A Lua script can perform a short conditional transition, but expensive scripts block other work on the server execution path.

bash
redis-cli <<'REDIS'
MULTI
SET demo:a 1
INCR demo:count
EXEC
REDIS
Read the code

The heredoc sends all commands through one redis-cli connection against an isolated development instance. Starting separate redis-cli processes for MULTI and EXEC would not create one transaction; connection ownership is part of the protocol.

03

Set a memory and latency budget for batches

Cap commands and total encoded bytes, not only the number of business items. Measure batch duration, reply sizes and tail latency while other clients work. Client versions may use separate pipeline pools, so inspect the pinned version when calculating deployment-wide connection limits.

TAKE THIS WITH YOU

Batch bounded independent work to reduce round trips, and choose atomicity and retry semantics explicitly. Inspect partial outcomes rather than assuming Exec implies rollback.

Check your understanding

What does pipelining guarantee about the whole batch?

Go to the source

Progress stays in this browser. No account needed.