Member-only story
Consistency between Cache and Database, Part 2
- Part 1: Read Aside Caching
- Part 2: Enhanced Approaches
This is the last article in the series. In the previous article we introduced why caching is needed and also introduced the Read Aside process and potential problems, and of course explained how to improve the consistency of Read Aside. Nevertheless, Read Aside is not enough for high consistency requirements.
One of the reasons why Read Aside can cause problems is because all users have access to the cache and database. When users manipulate data at the same time, inconsistencies occur due to various combinations of operation order.
Then we can effectively avoid inconsistency by limiting the behavior of manipulating data, which is the core concept of the next few methods.
Read Through
Read Path
- Reading data from cache
- If the cache data does not exist
- Read from database by cache
- Cache returns to the application client
Write Path
- Don’t care, usually used in combination with Write Through or Write Ahead.
Potential Problems
The biggest problem with this approach is that not all caches are supported, and the Redis example in this article does not support this approach.
Of course, some caches are supported, such as NCache, but NCache also has its problems.
First, it does not support many client-side SDKs. .NET Core is the native support language and there are not many options left.
Besides, it is divided into open source version and enterprise version, but you should know that if the open source version is not used by many people, then it is a tragedy when something goes wrong. Even so, the Enterprise version requires a license fee, not only for the infrastructure, but also for the software license.
How to Improve
Since NCache has its high cost, can we implement Read Through ourselves? The answer is yes.