diff --git a/docs/2024-01-20-backend-thinking.html b/docs/2024-01-20-backend-thinking.html index f260b5e..98c2b40 100644 --- a/docs/2024-01-20-backend-thinking.html +++ b/docs/2024-01-20-backend-thinking.html @@ -453,34 +453,99 @@
Start with basic: getting data from database.
+sequenceDiagram
+ participant service
+ participant database
+
+ service ->> database: get (100ms)
+ Getting data from cache first, then database later.
+sequenceDiagram
+ participant service
+ participant cache
+ participant database
+
+ service ->> cache: get (5ms)
+ alt not exist in cache
+ service ->> database: get (100ms)
+ end
+ + If data is already in cache, we can get it so fast (5ms), nearly instant. + But if not, we hit penalty, must get database after then re-update cache + if need (>105ms). The best case is worth even if hitting penalty + sometimes. +
+Basic cache strategy: combine Write Through and Read Through
+sequenceDiagram
+ participant service
+ participant cache
+ participant database
+
+ note over service,database: Read Through
+ service ->> cache: get
+ alt not exist in cache
+ service ->> database: get
+ service ->> cache: set
+ end
+
+ note over service,database: Write Through
+ service ->> database: set
+ service ->> cache: set
+ TODO: Take care incident