Skip to content

Commit 09ee779

Browse files
committed
Add Write-through section
1 parent adda68c commit 09ee779

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,3 +1312,38 @@ Subsequent reads of data added to cache are fast. Cache-aside is also referred
13121312
* Each cache miss results in three trips, which can cause a noticeable delay.
13131313
* Data can become stale if it is updated in the database. This issue is mitigated by setting a time-to-live (TTL) which forces an update of the cache entry, or by using write-through.
13141314
* When a node fails, it is replaced by a new, empty node, increasing latency.
1315+
1316+
#### Write-through
1317+
1318+
<p align="center">
1319+
<img src="http://i.imgur.com/0vBc0hN.png">
1320+
<br/>
1321+
<i><a href=http://www.slideshare.net/jboner/scalability-availability-stability-patterns/>Source: Scalability, availability, stability, patterns</a></i>
1322+
</p>
1323+
1324+
The application uses the cache as the main data store, reading and writing data to it, while the cache is responsible for reading and writing to the database:
1325+
1326+
* Application adds/updates entry in cache
1327+
* Cache synchronously writes entry to data store
1328+
* Return
1329+
1330+
Application code:
1331+
1332+
```
1333+
set_user(12345, {"foo":"bar"})
1334+
```
1335+
1336+
Cache code:
1337+
1338+
```
1339+
def set_user(user_id, values):
1340+
user = db.query("UPDATE Users WHERE id = {0}", user_id, values)
1341+
cache.set(user_id, user)
1342+
```
1343+
1344+
Write-through is a slow overall operation due to the write operation, but subsequent reads of just written data are fast. Users are generally more tolerant of latency when updating data than reading data. Data in the cache is not stale.
1345+
1346+
##### Disadvantage(s): write through
1347+
1348+
* When a new node is created due to failure or scaling, the new node will not cache entries until the entry is updated in the database. Cache-aside in conjunction with write through can mitigate this issue.
1349+
* Most data written might never read, which can be minimized with a TTL.

0 commit comments

Comments
 (0)