Rules for Low-Latency Systems
Practical habits that keep response times low and predictable under load.
Low latency is rarely about one clever trick. It comes from removing work from the critical path: fewer hops, less waiting, less data and fewer surprises at the tail.
The rules below apply whether you build trading systems, real-time games or an ordinary API that must answer in under 100 ms.
Diagram
How it works
- Measure first: trace a request and find where the time goes.
- Remove or parallelise network calls on the critical path.
- Keep hot data in memory and use connection pools.
- Move non-essential work (emails, analytics, resizing) to background queues.
- Compress and trim payloads; return only the fields the client needs.
- Avoid locks and garbage-collection pressure in hot code; reuse buffers.
- Deploy close to users and keep services in the same region as their data.
- Set timeouts everywhere so one slow dependency cannot stall the request.
Key concepts
- Critical path
- The chain of work the user must wait for. Everything else should happen in parallel or later.
- Connection pooling
- Reuse database and HTTP connections instead of paying for handshakes on every call.
- Batching
- Combine many small reads or writes into one round trip.
- Pre-computation
- Calculate expensive results ahead of time (materialised views, denormalised read models).
- Tail latency
- Optimise p99, not just the average. Hedged requests and timeouts help.
Trade-offs
Benefits
- Better user experience and conversion
- Lower latency usually means lower resource use
- More headroom under traffic spikes
Costs
- Pre-computation and caching add complexity and staleness
- Micro-optimisation can make code hard to maintain
Use it when
- User-facing APIs with strict response targets
- Real-time features: chat, games, live dashboards, payments
Common mistakes
- Optimising without profiling
- Logging synchronously to disk or a remote service on every request
- Cross-region database calls hidden inside an innocent repository method
Interview questions
Q1Your API p50 is 40 ms but p99 is 2 seconds. Where do you look?
Things that affect a few requests: garbage-collection pauses, lock contention, cold caches, slow database queries for large tenants, retries and a slow downstream dependency. Distributed traces of slow requests show which.
Q2What is a hedged request?
If a call has not returned within, say, the p95 time, send a duplicate to another replica and use whichever answers first. It cuts tail latency at a small cost in extra load.
Q3Why does async logging help latency?
Writing logs to a lock-free in-memory buffer returns immediately; a background thread flushes to disk or the network, keeping I/O off the request path.
Related lessons
Foundations
Latency Numbers & the Memory Hierarchy
Rough timings for memory, disk and network that make back-of-the-envelope design possible.
APIs & SecurityImproving API Performance
Pagination, caching, compression, async processing and connection pooling.
Scalability & PerformanceCaching Strategies
Keep frequently read data close and fast, and decide carefully how it stays fresh.