The square-root rule
A cost that grows with the interval against a fixed cost spread over it: the best interval is a square root, the same shape as the economic order quantity of a warehouse.
- Interval
- how long you wait (or how much you gather) before paying the fixed cost
- Growing cost
- cost per unit of interval that accumulates while you wait (reads slowed by deltas, time spent waiting)
- Fixed cost
- cost paid once per interval (a rewrite, an fsync)
How it behaves
One input on the horizontal axis, the others held fixed.
Data table
| Compaction interval τ (hours) | Seconds of work per hour |
|---|---|
| 0.02 | 2.01K |
| 0.021 | 1.87K |
| 0.023 | 1.75K |
| 0.025 | 1.63K |
| 0.026 | 1.53K |
| 0.028 | 1.43K |
| 0.03 | 1.33K |
| 0.032 | 1.25K |
| 0.035 | 1.16K |
| 0.037 | 1.09K |
| 0.04 | 1.02K |
| 0.043 | 951 |
| 0.046 | 890 |
| 0.049 | 833 |
| 0.053 | 780 |
| 0.056 | 731 |
| 0.06 | 685 |
| 0.065 | 642 |
| 0.069 | 602 |
| 0.074 | 566 |
| 0.08 | 532 |
| 0.085 | 500 |
| 0.091 | 471 |
| 0.098 | 444 |
| 0.105 | 419 |
| 0.112 | 397 |
| 0.12 | 376 |
| 0.129 | 357 |
| 0.138 | 339 |
| 0.148 | 324 |
| 0.159 | 309 |
| 0.17 | 297 |
| 0.182 | 285 |
| 0.195 | 275 |
| 0.209 | 267 |
| 0.224 | 259 |
| 0.24 | 253 |
| 0.257 | 248 |
| 0.275 | 244 |
| 0.295 | 242 |
| 0.316 | 240 |
| 0.339 | 240 |
| 0.363 | 241 |
| 0.389 | 243 |
| 0.417 | 246 |
| 0.447 | 250 |
| 0.478 | 256 |
| 0.513 | 263 |
| 0.549 | 271 |
| 0.589 | 280 |
| 0.631 | 290 |
| 0.676 | 302 |
| 0.724 | 316 |
| 0.776 | 331 |
| 0.831 | 347 |
| 0.89 | 365 |
| 0.954 | 385 |
| 1.02 | 407 |
| 1.1 | 431 |
| 1.17 | 457 |
| 1.26 | 484 |
| 1.35 | 515 |
| 1.44 | 547 |
| 1.55 | 583 |
| 1.66 | 621 |
| 1.78 | 662 |
| 1.9 | 706 |
| 2.04 | 753 |
| 2.18 | 805 |
| 2.34 | 860 |
| 2.51 | 919 |
| 2.69 | 982 |
| 2.88 | 1.05K |
| 3.08 | 1.12K |
| 3.3 | 1.2K |
| 3.54 | 1.29K |
| 3.79 | 1.38K |
| 4.06 | 1.47K |
| 4.36 | 1.58K |
| 4.67 | 1.69K |
| 5 | 1.81K |
Worked examples, recomputed
Every number the mechanisms quote for this relationship is recomputed from it, so none of them disagrees with it.
- IVF: N = 10⁸, nprobe = 1 → nlist ≈ 10,000
- cost ≈ 20,000 comparisons instead of 10⁸
- nprobe = 16 → nlist ≈ 40,000
- partitions: P = 50 → 250
- partitions: P = 100 → 200
- partitions: P = 200 → 250
- C = 30 s, MTBF = 1 day → I* ≈ 2,277 s (38 min)
- overhead at I* ≈ 2.6%
- spot: τ = 30 min, M = 6 h → ≈ 4.2% lost work
- C = 1,800 s, r = 0.25 → T* = 120 hours
- four times the writes → only half the interval (60 h)
- fsync 1 ms, λ = 10,000 commits/s → W* ≈ 0.45 ms
- cost per commit at W* ≈ 0.22 ms + 0.22 ms ≈ 0.45 ms
Where it appears
Each mechanism states it in its own names. The general symbol each name stands for is shown with it.
- Persistence & Durability
When a system says "yes, your data is safe", what exactly has it promised, and what did it have to do to keep that promise?
W (wait before the flush) = · fsync ÷ λ (fsync share) = · 1/2 (average wait) =
- Indexing
When does a separate "where is it?" structure pay for itself, and what does it cost to keep it true?
nlist (centroids) = · N · nprobe (vectors compared in probed cells) = · 1 (per centroid) =
- Distributed Systems Coordination
Who is allowed to decide, and how does everyone else learn the decision without asking?
P (partitions) = · f (fixed cost per partition) = · c (imbalance) =
- Fault Tolerance & Delivery Semantics
What is the cheapest thing that can be safely done twice?
I (checkpoint interval) = · C (cost of one checkpoint) = · 1 / (2·MTBF) (lost work per unit interval) =
- Scheduling & Workload Management
Which work runs now, which work waits, and who pays for the waiting?
τ (checkpoint interval) = · 1/(2M) (lost work per unit interval) =
- Table & Storage Maintenance
Who pays for the gap between the order data arrives in and the order it is read in: the writer, every reader, or a background job, and what is the break-even?
T (interval) = · C (one rewrite) = · r/2 (degradation) =