In cache-aside as well as Read-through patterns, in both the patterns we need to write code to write to the database. So whats the real advantage of read-through,write-behind approach?Please clarify my doubt.
Yes you need to write code in both these patterns but there are a number of benefits for using read-through/write-behind approach.
E.g. in cache-aside pattern, your application is responsible for reading and writing from the database and also to keep cache synchronize with the database. This will make your application's code complex and also may cause code duplication if multiple applications are dealing with the same data. Read-through/write-behind on the other hand simplifies the application's logic.
Furthermore read-through may reduce database calls by blocking parallel calls for same object. As explained in this article by NCache
There are many situations where a cache-item expires and multiple parallel user threads end up hitting the database. Multiplying this with millions of cached-items and thousands of parallel user requests, the load on the database becomes noticeably higher.
Similarly write-behind(asynchronous) can improve your application's performance by speeding up the write operation,
In cache-aside, application updates the database directly synchronously. Whereas, a Write- behind lets your application quickly update the cache and return. Then it lets the cache update the database in the background.
See this article for further details on advantages of using read-through/write-behind over cache-aside. I hope this will help :)
© 2022 - 2024 — McMap. All rights reserved.