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.

Play the level

Cache size and hit ratioDrag or use arrow keys to change the cache size

1,600 keys · hit 81% · mean 3.2 ms

Answers with a time to liveDrag or use arrow keys to change the TTL

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.

Case 1
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%
HTTP/2SQLUsersRedis cache0.25 vCPU · 0.5 GBPostgres0.5 vCPU · 1 GB
HTTP/2SQLUsersRedis cache0.25 vCPU · 0.5 GBPostgres0.5 vCPU · 1 GB
Cache-aside: misses a goal
HTTP/2SQLUsersRedis cache0.25 vCPU · 0.5 GBPostgres0.5 vCPU · 1 GB
HTTP/2SQLUsersRedis cache0.25 vCPU · 0.5 GBPostgres0.5 vCPU · 1 GB
Write-through: meets the goals