feat: more draft
parent
2d4701b4c8
commit
1eb0c04c6e
|
@ -453,34 +453,99 @@
|
||||||
</ul>
|
</ul>
|
||||||
<h2>
|
<h2>
|
||||||
<a
|
<a
|
||||||
id="user-content-system-design"
|
id="user-content-system-design-concept"
|
||||||
class="anchor"
|
class="anchor"
|
||||||
aria-hidden="true"
|
aria-hidden="true"
|
||||||
tabindex="-1"
|
tabindex="-1"
|
||||||
href="#system-design"
|
href="#system-design-concept"
|
||||||
><span aria-hidden="true" class="octicon octicon-link"></span></a
|
><span aria-hidden="true" class="octicon octicon-link"></span></a
|
||||||
>System Design
|
>System Design Concept
|
||||||
</h2>
|
</h2>
|
||||||
<h2>
|
<p>Start with basic: getting data from database.</p>
|
||||||
|
<div class="highlight highlight-source-mermaid">
|
||||||
|
<pre><span class="pl-k">sequenceDiagram</span>
|
||||||
|
<span class="pl-k">participant</span> <span class="pl-ent">service</span>
|
||||||
|
<span class="pl-k">participant</span> <span class="pl-ent">database</span>
|
||||||
|
|
||||||
|
<span class="pl-ent">service </span><span class="pl-k">->></span> <span class="pl-ent">database</span><span class="pl-k">:</span> <span class="pl-s">get (100ms)</span></pre>
|
||||||
|
</div>
|
||||||
|
<p>Getting data from cache first, then database later.</p>
|
||||||
|
<div class="highlight highlight-source-mermaid">
|
||||||
|
<pre><span class="pl-k">sequenceDiagram</span>
|
||||||
|
<span class="pl-k">participant</span> <span class="pl-ent">service</span>
|
||||||
|
<span class="pl-k">participant</span> <span class="pl-ent">cache</span>
|
||||||
|
<span class="pl-k">participant</span> <span class="pl-ent">database</span>
|
||||||
|
|
||||||
|
<span class="pl-ent">service </span><span class="pl-k">->></span> <span class="pl-ent">cache</span><span class="pl-k">:</span> <span class="pl-s">get (5ms)</span>
|
||||||
|
<span class="pl-k">alt</span> <span class="pl-s">not exist in cache</span>
|
||||||
|
<span class="pl-s">service ->> database: get (100ms)</span>
|
||||||
|
<span class="pl-k">end</span></pre>
|
||||||
|
</div>
|
||||||
|
<p>
|
||||||
|
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.
|
||||||
|
</p>
|
||||||
|
<p>Basic cache strategy: combine Write Through and Read Through</p>
|
||||||
|
<div class="highlight highlight-source-mermaid">
|
||||||
|
<pre><span class="pl-k">sequenceDiagram</span>
|
||||||
|
<span class="pl-k">participant</span> <span class="pl-ent">service</span>
|
||||||
|
<span class="pl-k">participant</span> <span class="pl-ent">cache</span>
|
||||||
|
<span class="pl-k">participant</span> <span class="pl-ent">database</span>
|
||||||
|
|
||||||
|
<span class="pl-k">note over </span><span class="pl-ent">service</span><span class="pl-sg">,</span><span class="pl-ent">database</span>: <span class="pl-ent">Read Through</span>
|
||||||
|
<span class="pl-ent">service </span><span class="pl-k">->></span> <span class="pl-ent">cache</span><span class="pl-k">:</span> <span class="pl-s">get</span>
|
||||||
|
<span class="pl-k">alt</span> <span class="pl-s">not exist in cache</span>
|
||||||
|
<span class="pl-s">service ->> database: get</span>
|
||||||
|
<span class="pl-s">service ->> cache: set</span>
|
||||||
|
<span class="pl-k">end</span>
|
||||||
|
|
||||||
|
<span class="pl-k">note over </span><span class="pl-ent">service</span><span class="pl-sg">,</span><span class="pl-ent">database</span>: <span class="pl-ent">Write Through</span>
|
||||||
|
<span class="pl-ent">service </span><span class="pl-k">->></span> <span class="pl-ent">database</span><span class="pl-k">:</span> <span class="pl-s">set</span>
|
||||||
|
<span class="pl-ent">service </span><span class="pl-k">->></span> <span class="pl-ent">cache</span><span class="pl-k">:</span> <span class="pl-s">set</span></pre>
|
||||||
|
</div>
|
||||||
|
<h3>
|
||||||
<a
|
<a
|
||||||
id="user-content-performance"
|
id="user-content-references-2"
|
||||||
class="anchor"
|
class="anchor"
|
||||||
aria-hidden="true"
|
aria-hidden="true"
|
||||||
tabindex="-1"
|
tabindex="-1"
|
||||||
href="#performance"
|
href="#references-2"
|
||||||
><span aria-hidden="true" class="octicon octicon-link"></span></a
|
><span aria-hidden="true" class="octicon octicon-link"></span></a
|
||||||
>Performance
|
>References
|
||||||
</h2>
|
</h3>
|
||||||
<h2>
|
<ul>
|
||||||
<a
|
<li>
|
||||||
id="user-content-security"
|
<a href="https://apenwarr.ca/log/20201227" rel="nofollow"
|
||||||
class="anchor"
|
>Systems design explains the world: volume 1</a
|
||||||
aria-hidden="true"
|
>
|
||||||
tabindex="-1"
|
</li>
|
||||||
href="#security"
|
<li>
|
||||||
><span aria-hidden="true" class="octicon octicon-link"></span></a
|
<a href="https://apenwarr.ca/log/20230415" rel="nofollow"
|
||||||
>Security
|
>Systems design 2: What we hope we know</a
|
||||||
</h2>
|
>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a
|
||||||
|
href="https://martin.kleppmann.com/2016/02/08/how-to-do-distributed-locking.html"
|
||||||
|
rel="nofollow"
|
||||||
|
>How to do distributed locking</a
|
||||||
|
>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="http://antirez.com/news/101" rel="nofollow"
|
||||||
|
>Is Redlock safe?</a
|
||||||
|
>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a
|
||||||
|
href="https://danielw.cn/cache-consistency-with-database#cache-patterns"
|
||||||
|
rel="nofollow"
|
||||||
|
>Cache Consistency with Database</a
|
||||||
|
>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
<h2>
|
<h2>
|
||||||
<a
|
<a
|
||||||
id="user-content-damage-control"
|
id="user-content-damage-control"
|
||||||
|
@ -491,7 +556,6 @@
|
||||||
><span aria-hidden="true" class="octicon octicon-link"></span></a
|
><span aria-hidden="true" class="octicon octicon-link"></span></a
|
||||||
>Damage control
|
>Damage control
|
||||||
</h2>
|
</h2>
|
||||||
<p>TODO: Take care incident</p>
|
|
||||||
<h2>
|
<h2>
|
||||||
<a
|
<a
|
||||||
id="user-content-bonus"
|
id="user-content-bonus"
|
||||||
|
|
|
@ -207,16 +207,66 @@ Some tips:
|
||||||
- [Imaginary Problems Are the Root of Bad Software](https://cerebralab.com/Imaginary_Problems_Are_the_Root_of_Bad_Software)
|
- [Imaginary Problems Are the Root of Bad Software](https://cerebralab.com/Imaginary_Problems_Are_the_Root_of_Bad_Software)
|
||||||
- [Speed up writing Go test ASAP](https://haunt98.github.io/posts-go/2022-12-25-go-test-asap.html)
|
- [Speed up writing Go test ASAP](https://haunt98.github.io/posts-go/2022-12-25-go-test-asap.html)
|
||||||
|
|
||||||
## System Design
|
## System Design Concept
|
||||||
|
|
||||||
## Performance
|
Start with basic: getting data from database.
|
||||||
|
|
||||||
## Security
|
```mermaid
|
||||||
|
sequenceDiagram
|
||||||
|
participant service
|
||||||
|
participant database
|
||||||
|
|
||||||
|
service ->> database: get (100ms)
|
||||||
|
```
|
||||||
|
|
||||||
|
Getting data from cache first, then database later.
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
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
|
||||||
|
|
||||||
|
```mermaid
|
||||||
|
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
|
||||||
|
```
|
||||||
|
|
||||||
|
### References
|
||||||
|
|
||||||
|
- [Systems design explains the world: volume 1](https://apenwarr.ca/log/20201227)
|
||||||
|
- [Systems design 2: What we hope we know](https://apenwarr.ca/log/20230415)
|
||||||
|
- [How to do distributed locking](https://martin.kleppmann.com/2016/02/08/how-to-do-distributed-locking.html)
|
||||||
|
- [Is Redlock safe?](http://antirez.com/news/101)
|
||||||
|
- [Cache Consistency with Database](https://danielw.cn/cache-consistency-with-database#cache-patterns)
|
||||||
|
|
||||||
## Damage control
|
## Damage control
|
||||||
|
|
||||||
TODO: Take care incident
|
|
||||||
|
|
||||||
## Bonus
|
## Bonus
|
||||||
|
|
||||||
- [IntelliJ IDEA Ultimate](https://www.jetbrains.com/idea/download/): Java
|
- [IntelliJ IDEA Ultimate](https://www.jetbrains.com/idea/download/): Java
|
||||||
|
|
Loading…
Reference in New Issue