Write-back vs write-through

Write-back confirms a write as soon as the cache has it and sends it to the database later. Write-through confirms only after the database has the write. When the cache crashes for 2 s, write-back loses confirmed writes and write-through loses none.

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

A backup and its restoreArrow keys change the backup interval. Tap to change the restore rate.

Backup every 60 minutes · RPO 60 minutes · RTO 11 hours at 100 Mbps

Case 1

Half of the requests write. Each write takes 300 ms to reach the database, and the cache crashes for 2 s at 0:10. No confirmed write may be lost.

Case 1
Measure Goal Write-back Write-through
Lost writes none 15 Fail 0 Pass
Stale reads none 0 Pass 0 Pass
Monthly cost 8 USD/mo 8 USD/mo
p99 latency 368 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
Write-back: 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