Redis / Advanced: persistence, distribution and operations / Lesson 17
Observability, latency and safe diagnosis
Diagnose end-to-end latency from command work, queueing, network and resource evidence. Inspect bounded metadata without using scans, intrusive tooling or universal tuning prescriptions.
On this page
Lesson goals
- Separate client latency, server execution time and command complexity.
- Use versioned counters and safe iteration with explicit limitations.
The user waits for more than command execution
End-to-end latency includes application queueing, pool wait, connection setup when relevant, network transfer, server scheduling, command work and reply decoding. An operation can be cheap internally yet slow because the client is overloaded or the response is large. Record the actual command family, argument/result size, topology, persistence activity and concurrent workload. Repeated representative percentiles are more useful than one fast local request. A benchmark number from another machine is not a service guarantee, and this course runs no network load test or configured Redis command.
Read bounded diagnostics with the required authority
INFO sections and a limited SLOWLOG GET can provide complementary evidence in an authorized operational session. Slow-log execution time excludes client/network transfer and should not be equated with the full request duration. Logging can expose command arguments, so share narrowly and redact through the approved process. The example is non-runnable and does not enable logging or retrieve real data. Managed services may expose a curated dashboard instead of these commands. Correlate timestamps and counter resets with the incident window before drawing conclusions from one sample.
INFO stats
INFO commandstats
SLOWLOG GET 5
Actual counters and entries are unspecified. No sensitive arguments, observed slow commands or healthy thresholds are fabricated.
Bound the work and understand SCAN’s guarantees
KEYS can block while traversing a large keyspace and is not a routine production discovery recipe. SCAN supports incremental iteration, but COUNT is a hint rather than an exact batch size, duplicates can occur and concurrent changes mean the result is not a point-in-time snapshot. A complete iteration has documented guarantees for keys present throughout, with weaker conclusions about changing keys. Use bounded, authorized observation and do not dump private key values into an incident report. Expensive set operations, large lists and scripts can still stall work despite a generally fast server.
Expose a latency explanation as a model
The synthetic budget shows that client pool waiting and network time dominate a one-unit command execution component. It is not profiler output or a universal decomposition formula. Real observations need consistent measurement boundaries and should avoid double-counting overlapping intervals. Use the model to explain why an empty slow log does not prove an application request was fast. A remedy should address the evidenced component: increasing Redis memory, for example, is not a justified response to a client-side queue without corroborating memory or eviction evidence.
latency_units = {'pool_wait': 40, 'network': 30, 'server_command': 1, 'decode': 4}
assert sum(latency_units.values()) == 75
assert latency_units['pool_wait'] + latency_units['network'] > latency_units['server_command']
The model totals 75 units with 70 outside command execution in the two stated components. These are invented units, not milliseconds measured on Redis.
Select the smallest justified operational change
Correlate latency with slow commands, payloads, pool saturation, hot keys, persistence peaks, replication synchronization and host constraints. Avoid enabling intrusive tracing, changing global limits or running a large scan as an unreviewed troubleshooting shortcut. Compare correctness, latency distribution, throughput, rejected work and recovery before accepting a fix. Keep the deployed product/version and client retry behavior with the evidence because command implementation and managed restrictions can change. A useful incident result identifies what was measured, what remains uncertain and which owner will verify the next hypothesis, rather than producing a long unsorted dump of metrics.
Common errors and fixes
A slow application has an empty slow log
- Why it happens
- End-to-end latency was assumed equal to command execution time.
- How to fix it
- Inspect pool, network, payload and queueing evidence at the same times.
- Prevent it next time
- Document measurement boundaries for each metric.
SCAN output is treated as a unique frozen snapshot
- Why it happens
- Incremental iteration guarantees were overstated.
- How to fix it
- Handle duplicates and changing-key uncertainty according to the use case.
- Prevent it next time
- Avoid using an ordinary scan as proof of exact inventory at one instant.
A diagnostic dump exposes private key data
- Why it happens
- Observation scope and sensitive arguments were not controlled.
- How to fix it
- Stop unnecessary collection and follow the approved evidence handling process.
- Prevent it next time
- Prefer bounded metadata and reviewed redaction.
Check your understanding
1. A request takes one second, but its logged command execution is tiny. Which conclusion is justified?
Show worked solution
Command work alone does not explain the request duration. Investigate client pool waiting, network, connection/TLS setup, queueing, response size and decoding with aligned timestamps. Do not claim Redis is either healthy or faulty solely from the mismatch; establish the measured boundary and corroborating evidence before choosing a fix.
2. SCAN COUNT 100 returns a different number of entries and later repeats a key. Is this necessarily a server bug?
Show worked solution
No. COUNT is a work hint and duplicate returns are part of the documented iteration behavior. The caller must follow the cursor until completion and handle duplicates appropriately for its purpose, while recognizing concurrent changes prevent a point-in-time snapshot. An exact inventory needs a separately designed consistency method.
Key takeaways
- Align measurement boundaries before interpreting latency.
- Bound diagnostics and state iteration limits honestly.