Per-Operation Timeout Configuration
What you'll learn: How to set different timeout values for different types of operations based on their expected execution times.
Not all operations are created equal. A simple read from cache might complete in 10ms, while a complex analytical query could legitimately take 5 seconds. Using the same timeout for both would either fail fast operations unnecessarily or wait too long for slow ones.
The Core Idea
Per-operation timeout configuration means assigning different timeout values to different operations based on their expected behavior and acceptable latency. Rather than a one-size-fits-all timeout, you tune each operation independently.
For example:
- Read operations from a primary database: 100ms timeout
- Write operations to the same database: 500ms timeout (writes often take longer due to replication, fsync, index updates)
- Cache reads: 20ms timeout (should be fast)
- Batch export job: 30-second timeout (legitimately slow)
Why This Matters
Operations have different performance characteristics. Writes typically involve:
- Acquiring locks
- Writing to disk with fsync
- Replicating to followers
- Updating indexes
Reads from replicas can be much faster, especially if data is in memory. Using a 100ms timeout for both would either cause unnecessary write failures or tolerate unacceptably slow reads.
Configuration Strategy
Base timeouts on observed P95 or P99 latencies from production metrics (as covered in Adaptive Timeouts Based on Historical Latency). Add a safety margin. For a read operation with P99 of 50ms, you might set a 150ms timeout. For writes with P99 of 300ms, perhaps 800ms.
Key Takeaway: Configure timeouts per operation type based on expected execution time—fast operations get tight timeouts, complex operations get appropriate headroom, preventing both false failures and hanging requests.