Cache-aside vs write-through
With cache-aside the service writes to the database and the cache keeps its old copy until the entry expires. With write-through each write updates the cache and the database together. When 50 percent of requests are writes, only write-through returns no old values.
1,600 keys · hit 81% · mean 3.2 ms
TTL 5 minutes · 12 lookups/h · old answers up to 5 minutes
Case 1
Half of the requests read and half write. Each write takes 300 ms to reach the database, and the cache crashes for 2 s at 0:10. No read may return an old value.
| Measure | Goal | Cache-aside | Write-through |
|---|---|---|---|
| Lost writes | none | 0 Pass | 0 Pass |
| Stale reads | none | 152 Fail | 0 Pass |
| Monthly cost | 8 USD/mo | 8 USD/mo | |
| p99 latency | 372 ms | 372 ms | |
| Error rate | 6.7% | 6.7% |