Cachingwrite-throughwrite through

Write-through cache

Definition

A write-through cache writes each update synchronously to both the cache and the backing store, acknowledging the write only after both have succeeded.

In practice

Reads that follow a write hit a warm, fresh cache, which suits data that is read soon after it is written, such as user profiles or session data. There is no window in which the cache holds an older value than the database, as long as both writes succeed.

Writes become slower, since they pay for two stores, and data that is written but never read still fills the cache, so it is usually combined with a TTL. If the second write fails the two copies disagree unless the code handles it. Write-through does nothing for keys that were never written through, so reads still need a miss path.

Example

Updating a user's display name writes the row to PostgreSQL and then SET user:7 in Redis, and returns 200 only after both succeed, adding about 1 ms to the 4 ms write.