-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
1193 lines (808 loc) · 80.2 KB
/
index.html
File metadata and controls
1193 lines (808 loc) · 80.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Inertia</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="description" content="site.desc">
<meta property="og:type" content="website">
<meta property="og:title" content="Inertia">
<meta property="og:url" content="http://nberserk.github.io/index.html">
<meta property="og:site_name" content="Inertia">
<meta property="og:description" content="site.desc">
<meta property="og:locale" content="ko_KR">
<meta property="article:author" content="@nberserk">
<meta name="twitter:card" content="summary">
<link rel="alternate" href="/atom.xml" title="Inertia" type="application/atom+xml">
<link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css" integrity="sha384-XdYbMnZ/QjLh6iI4ogqCTaIjrFk87ip+ekIjefZch0Y+PvJ8CDYtEs1ipDmPorQ+" crossorigin="anonymous">
<link rel="stylesheet" href="/css/styles.css">
<!-- Google Analytics -->
<script type="text/javascript">
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-63706532-1', 'auto');
ga('send', 'pageview');
</script>
<!-- End Google Analytics -->
<meta name="generator" content="Hexo 5.4.0"></head>
<body>
<nav class="navbar navbar-inverse">
<div class="container">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#main-menu-navbar" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="main-menu-navbar">
<ul class="nav navbar-nav">
<li><a class="active"
href="/index.html">Home</a></li>
<li><a class=""
href="/archives/">Archives</a></li>
</ul>
<!--
<ul class="nav navbar-nav navbar-right">
<li><a href="/atom.xml" title="RSS Feed"><i class="fa fa-rss"></i></a></li>
</ul>
-->
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
<div class="container">
<div class="blog-header">
<h1 class="blog-title">Inertia</h1>
</div>
<div class="row">
<div class="col-sm-8 blog-main">
<article id="post-select-db" class="article article-type-post" itemscope itemprop="blogPost">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2021/06/26/select-db/">select the right db</a>
</h1>
</header>
<div class="article-meta">
<div class="article-datetime">
<a href="/2021/06/26/select-db/" class="article-date"><time datetime="2021-06-26T15:00:00.000Z" itemprop="datePublished">2021-06-27</time></a>
</div>
</div>
<div class="article-inner">
<div class="article-entry" itemprop="articleBody">
<h2 id="DB-selection"><a href="#DB-selection" class="headerlink" title="DB selection"></a>DB selection</h2><p><a target="_blank" rel="noopener" href="https://www.youtube.com/watch?v=cODCpXtPHbQ">https://www.youtube.com/watch?v=cODCpXtPHbQ</a></p>
<ul>
<li>Structured data<ul>
<li>yes<ul>
<li>Need ACID<ul>
<li>RDBMS(yes): mysql, orcle, sql server, postgres</li>
</ul>
</li>
</ul>
</li>
<li>no<ul>
<li>Ever increasing data && + finite queries -> Columnar DB: Cassandra, HBase</li>
<li>++ Data types && ++ queries -> document DB: mongoDB, Couch Base</li>
</ul>
</li>
</ul>
</li>
</ul>
<p>interesting example: At ecommerece site, we shouldn’t sell more than the remaining quantity. it should support ACID. so we can use SQL before placing order. but once order is created, then you can use MongoDB to save the data.</p>
</div>
<footer class="article-footer">
<a data-url="http://nberserk.github.io/2021/06/26/select-db/" data-id="ckqq7lx5z0001gnqyhk3o2r5s" class="article-share-link">
<i class="fa fa-share"></i> Share
</a>
<a href="http://nberserk.github.io/2021/06/26/select-db/#disqus_thread" class="article-comment-link">
<i class="fa fa-comment"></i> Comments
</a>
<ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/design/" rel="tag">design</a></li></ul>
</footer>
</div>
</article>
<article id="post-rate-limiter" class="article article-type-post" itemscope itemprop="blogPost">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2021/06/26/rate-limiter/">Rate limiting service</a>
</h1>
</header>
<div class="article-meta">
<div class="article-datetime">
<a href="/2021/06/26/rate-limiter/" class="article-date"><time datetime="2021-06-26T15:00:00.000Z" itemprop="datePublished">2021-06-27</time></a>
</div>
</div>
<div class="article-inner">
<div class="article-entry" itemprop="articleBody">
<h2 id="Requirements"><a href="#Requirements" class="headerlink" title="Requirements"></a>Requirements</h2><p>functional:</p>
<ul>
<li>allowRequest(request)</li>
</ul>
<p>non functiona:</p>
<ul>
<li>low latency</li>
<li>accurate</li>
<li>scalable</li>
<li><del>highly available</del> since we can assume that default is allow the request if the throttling service is not available.</li>
</ul>
<h2 id="request-processing"><a href="#request-processing" class="headerlink" title="request processing"></a>request processing</h2><p><img src="https://user-images.githubusercontent.com/900639/124370124-a29e0680-dc28-11eb-9ca0-039aa7db62bd.png" alt="image"></p>
<h2 id="token-bucket-algorithm"><a href="#token-bucket-algorithm" class="headerlink" title="token bucket algorithm"></a>token bucket algorithm</h2><p>one of the popular algorithm for rate-limiting algorithm.</p>
<p><img src="https://user-images.githubusercontent.com/900639/124370140-c8c3a680-dc28-11eb-914e-8541dcf0f632.png" alt="image"></p>
<h2 id="interfaces-and-classes"><a href="#interfaces-and-classes" class="headerlink" title="interfaces and classes"></a>interfaces and classes</h2><ul>
<li>JobSceduler: fetch rules from RuleService periodically</li>
<li>RulesCache: store token bucket objects</li>
<li>ClientIdentifier: identify client form the request </li>
<li>RateLimiter: provide <code>allowRequest()</code> api</li>
</ul>
<h2 id="Distributed-world"><a href="#Distributed-world" class="headerlink" title="Distributed world"></a>Distributed world</h2><p>as we move to distributed world, we need to share local remaining tokens to other hosts. </p>
<h3 id="message-boarcasting"><a href="#message-boarcasting" class="headerlink" title="message boarcasting"></a>message boarcasting</h3><p>possible approaches:</p>
<ul>
<li>Tell everyone everything: not scalable, message grows quadratically</li>
<li>gossip communication</li>
<li>distributed cache cluster</li>
<li>coordination service: one host takes coordination leader role. Paxos, Raft</li>
<li>random leader selection</li>
</ul>
<p><img src="https://user-images.githubusercontent.com/900639/124373547-eeac7380-dc47-11eb-8fb3-1b6be446ed7f.png" alt="image"></p>
<h3 id="TCP-VS-UDP"><a href="#TCP-VS-UDP" class="headerlink" title="TCP VS UDP"></a>TCP VS UDP</h3><p>TCP: slow, accuracy, order guaranteed<br>UDP: fast, not reliable, order not guaranteed</p>
<h3 id="How-to-integrate-all-this-with-the-service"><a href="#How-to-integrate-all-this-with-the-service" class="headerlink" title="How to integrate all this with the service?"></a>How to integrate all this with the service?</h3><p><img src="https://user-images.githubusercontent.com/900639/124373585-46e37580-dc48-11eb-9efe-b70fef4cb38c.png" alt="image"></p>
<h2 id="final-look"><a href="#final-look" class="headerlink" title="final look"></a>final look</h2><p><img src="https://user-images.githubusercontent.com/900639/124373721-adb55e80-dc49-11eb-8643-d77ec2b938c3.png" alt="image"></p>
<h2 id="Reference"><a href="#Reference" class="headerlink" title="Reference"></a>Reference</h2><ul>
<li><a target="_blank" rel="noopener" href="https://www.youtube.com/watch?v=FU4WlwfS3G0&t=815s">https://www.youtube.com/watch?v=FU4WlwfS3G0&t=815s</a></li>
</ul>
</div>
<footer class="article-footer">
<a data-url="http://nberserk.github.io/2021/06/26/rate-limiter/" data-id="ckqq7lx600003gnqygqzsdrrs" class="article-share-link">
<i class="fa fa-share"></i> Share
</a>
<a href="http://nberserk.github.io/2021/06/26/rate-limiter/#disqus_thread" class="article-comment-link">
<i class="fa fa-comment"></i> Comments
</a>
<ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/design/" rel="tag">design</a></li></ul>
</footer>
</div>
</article>
<article id="post-top-K-problem" class="article article-type-post" itemscope itemprop="blogPost">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2021/06/13/top-K-problem/">Top K problem</a>
</h1>
</header>
<div class="article-meta">
<div class="article-datetime">
<a href="/2021/06/13/top-K-problem/" class="article-date"><time datetime="2021-06-13T15:00:00.000Z" itemprop="datePublished">2021-06-14</time></a>
</div>
</div>
<div class="article-inner">
<div class="article-entry" itemprop="articleBody">
<h2 id="Requirements"><a href="#Requirements" class="headerlink" title="Requirements"></a>Requirements</h2><p>functional</p>
<ul>
<li>topK(k, startTime, endTime)</li>
<li>scalable</li>
<li>available</li>
<li>highly performant: few ten milliseconds to return top 100 list</li>
<li>accurate</li>
</ul>
<h2 id="single-host-approach"><a href="#single-host-approach" class="headerlink" title="single host approach"></a>single host approach</h2><p><img src="https://user-images.githubusercontent.com/900639/122692932-788e2280-d1ec-11eb-9cfb-0249ec71d401.png" alt="image"></p>
<ul>
<li>build hashTable<Key, Count> <ul>
<li>sort the whole list: O(nLog(n))</li>
<li>use heap: O(nLog(k))</li>
</ul>
</li>
</ul>
<p>but it’s not scalable.</p>
<h2 id="Hash-table-multiple-hosts"><a href="#Hash-table-multiple-hosts" class="headerlink" title="Hash table, multiple hosts"></a>Hash table, multiple hosts</h2><p><img src="https://user-images.githubusercontent.com/900639/122692782-d5d5a400-d1eb-11eb-9bf4-00d09955517a.png" alt="image"></p>
<p>you can scale previous approach by using data paritioner. scalability and througput has been addressed.</p>
<p>But streaming data is not bounded. It has infinite data. what if we need to calculate top K for a day or a week?</p>
<h2 id="count-min-sketch-multiple-hosts"><a href="#count-min-sketch-multiple-hosts" class="headerlink" title="count-min sketch, multiple hosts"></a>count-min sketch, multiple hosts</h2><p>There is well-known data structure called count-min sketch, kind of approximation algorithm, which guarantees fixed memory usage. basically it tradedoff between accuracy and memory. </p>
<p><img src="https://user-images.githubusercontent.com/900639/122708501-2c090e00-d211-11eb-93de-435e82166873.png" alt="image"></p>
<p>count-min sketch uses 2 dimensional array, each row is different hash function, column is count. whenever new event comes in, calculate hash value for each row, and increment the value of the cell by 1. This means that it could have collision, that’s why we take the smallest value as a result.</p>
<p>But this doesn’t give us accurate top K lists. if constraints don’t allow inaccuracy, then we need a different approach.</p>
<h2 id="high-level-design"><a href="#high-level-design" class="headerlink" title="high level design"></a>high level design</h2><p><img src="https://user-images.githubusercontent.com/900639/122709631-80ad8880-d213-11eb-8601-41b433e54634.png" alt="image"></p>
<h2 id="Reference"><a href="#Reference" class="headerlink" title="Reference"></a>Reference</h2><ul>
<li><a href="https://www.youtube.com/watch?v=kx-XDoPjoHw" target="_blank" rel="noopener">https://www.youtube.com/watch?v=kx-XDoPjoHw</a></li>
<li><a href="http://nathanmarz.com/blog/how-to-beat-the-cap-theorem.html" target="_blank" rel="noopener">http://nathanmarz.com/blog/how-to-beat-the-cap-theorem.html</a></li>
</ul>
</div>
<footer class="article-footer">
<a data-url="http://nberserk.github.io/2021/06/13/top-K-problem/" data-id="ckqe4m43k002urcqyi16wru96" class="article-share-link">
<i class="fa fa-share"></i> Share
</a>
<a href="http://nberserk.github.io/2021/06/13/top-K-problem/#disqus_thread" class="article-comment-link">
<i class="fa fa-comment"></i> Comments
</a>
<ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/system-design/" rel="tag">system design</a></li></ul>
</footer>
</div>
</article>
<article id="post-distributed-cache" class="article article-type-post" itemscope itemprop="blogPost">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2021/06/12/distributed-cache/">Design distributed Cache</a>
</h1>
</header>
<div class="article-meta">
<div class="article-datetime">
<a href="/2021/06/12/distributed-cache/" class="article-date"><time datetime="2021-06-12T15:00:00.000Z" itemprop="datePublished">2021-06-13</time></a>
</div>
</div>
<div class="article-inner">
<div class="article-entry" itemprop="articleBody">
<h2 id="Requirements"><a href="#Requirements" class="headerlink" title="Requirements"></a>Requirements</h2><p>Functional:</p>
<ul>
<li>put(key, value)</li>
<li>get(key)</li>
</ul>
<p>Non-Functional:</p>
<ul>
<li>Scalable</li>
<li>highly available(survives hardware/network failures)</li>
<li>highly performant(fast put/get)</li>
</ul>
<h2 id="LRU-Cache"><a href="#LRU-Cache" class="headerlink" title="LRU Cache"></a>LRU Cache</h2><p>The basic data structure for cache would be <strong>hash table</strong> since it provides O(1) time complexity for put/get operation. So far so good. </p>
<p>One machine has finite memory capacity so we can’t put keys endlessely. If the cache is full, we need to delete existing data so that we can add new one. Then which key should be evicted(deleted)? This is called <a target="_blank" rel="noopener" href="https://en.wikipedia.org/wiki/Cache_replacement_policies">cache eviction(replacement) policy</a>. The most popular one is Least recently Used(LRU).</p>
<p>LRU discards the least recently used items first. So the algorithm needs to keep track of access time of the items. </p>
<p>Order can be easily expressed by linked list and cache is basically hash table. Then we can combine these two into one data structure, called <strong>Linked Hash Table.</strong>. basic idea is whenever the key is accessed, we add the item into head of the list. Then the tail of the list will be always the one last accessed, which is the target item to be removed when capacity is full.</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Node</span></span>{</span><br><span class="line"> <span class="keyword">private</span> <span class="keyword">final</span> String key;</span><br><span class="line"> <span class="keyword">private</span> String value;</span><br><span class="line"> <span class="keyword">private</span> Node prev, next;</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">public</span> <span class="title">Node</span><span class="params">(String key, String value)</span></span>{</span><br><span class="line"> <span class="keyword">this</span>.key=key;</span><br><span class="line"> <span class="keyword">this</span>.value=value;</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">LRUCache</span></span>{</span><br><span class="line"> Map<String, Node> map;</span><br><span class="line"> <span class="keyword">int</span> capacity;</span><br><span class="line"> NOde head = <span class="keyword">null</span>;</span><br><span class="line"> Node tail = <span class="keyword">null</span>;</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">private</span> <span class="title">deleteFromList</span><span class="params">(Node node)</span></span>{</span><br><span class="line"></span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">private</span> <span class="title">setListHead</span><span class="params">(Node node)</span></span>{</span><br><span class="line"></span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">public</span> <span class="title">put</span><span class="params">(String key, String value)</span> </span>{</span><br><span class="line"> <span class="keyword">if</span>(map.containsKey(key)){</span><br><span class="line"> map.get(key).setValue(value);</span><br><span class="line"> deleteFromList(node);</span><br><span class="line"> setListHead(node);</span><br><span class="line"> } <span class="keyword">else</span>{</span><br><span class="line"> <span class="keyword">if</span>(map.size()>=capacity){</span><br><span class="line"> map.remove(tail.getKey());</span><br><span class="line"> deleteFromList(tail);</span><br><span class="line"> }</span><br><span class="line"> Node node = <span class="keyword">new</span> Node(key,value);</span><br><span class="line"> map.put(key, node);</span><br><span class="line"> setListHead(node);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="function"><span class="keyword">public</span> String <span class="title">get</span><span class="params">(String key)</span></span>{</span><br><span class="line"> <span class="keyword">if</span>(!map.containsKey(key)){</span><br><span class="line"> <span class="keyword">return</span> <span class="keyword">null</span>;</span><br><span class="line"> }</span><br><span class="line"> Node node = map.get(key);</span><br><span class="line"> deleteFromList(node);</span><br><span class="line"> setListHead(node);</span><br><span class="line"> <span class="keyword">return</span> node.getValue();</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<h2 id="2-possible-approaches"><a href="#2-possible-approaches" class="headerlink" title="2 possible approaches"></a>2 possible approaches</h2><h3 id="dedicated-cache-cluster"><a href="#dedicated-cache-cluster" class="headerlink" title="dedicated cache cluster"></a>dedicated cache cluster</h3><ul>
<li>isolation of resources between service and cache</li>
<li>can be used by multiple services</li>
<li>flexibility in choosing hardware<h3 id="co-located-cache"><a href="#co-located-cache" class="headerlink" title="co-located cache"></a>co-located cache</h3>cache service is co-located with the service host.</li>
<li>No extra hardware and operation cost</li>
<li>scales together with the service</li>
</ul>
<h2 id="choosing-a-cache-host"><a href="#choosing-a-cache-host" class="headerlink" title="choosing a cache host"></a>choosing a cache host</h2><p>Definitely one cache host can’t server all the items. They need to be split across multiple hosts by hash of key of the item. How keys can be distributed? </p>
<h3 id="MOD"><a href="#MOD" class="headerlink" title="MOD"></a>MOD</h3><p>Cache host number = hash_function(key) MOD #hosts</p>
<p>mod operator would be the most easy one to implement but it has obvious weakness. entire cache need to be rewritten whenever a new host is added or deleted. Generally this kind of overhead is not acceptable in production environment.</p>
<h3 id="Consistent-hashing"><a href="#Consistent-hashing" class="headerlink" title="Consistent hashing"></a>Consistent hashing</h3><p>consistent hashing is basically placing host on a circle. 12 oclock will be value 0 or 2^32. the point will be mapped to the point on the circle boundary based on the hash value. for example 2^32/4 will be mapped to 3 o’clock. we will place cache host along the circle with even distance. the keys between the two hosts belong to the first clockwise host. </p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">before:</span><br><span class="line">H1 --- H2 --- H3 --- H1</span><br><span class="line"></span><br><span class="line">after:</span><br><span class="line">H1 --- H2 --- H2.5 --- H3 --- H1</span><br></pre></td></tr></table></figure>
<p>Let’s say we added H2.5 between H2 and H3. then the affected hosts are H2 and only. very limited blast radius compared to the MOD approach.</p>
<h2 id="Cache-client"><a href="#Cache-client" class="headerlink" title="Cache client"></a>Cache client</h2><p>cache client knows about all cache servers. all cache clients should have the same list of servers. It stores list of servers in sorted order. just like TreeMap in java. binary search is used to identify server, which is O(logn). It uses TCP or UDP protocol to talke to servers. If cache server is unavailable, client proceeds as if it was a cache miss. </p>
<h3 id="maintaining-a-list-of-cache-servers"><a href="#maintaining-a-list-of-cache-servers" class="headerlink" title="maintaining a list of cache servers"></a>maintaining a list of cache servers</h3><ul>
<li>use configuration file in local host</li>
<li>use external file like S3</li>
<li>use configuration service like ZooKeeper<ul>
<li>config service will check heartbeat with all the cache hosts. if it fails it will be deleted from the cache list</li>
</ul>
</li>
</ul>
<h2 id="high-availability"><a href="#high-availability" class="headerlink" title="high availability"></a>high availability</h2><p>hot shard problem can be solved by replication.</p>
<p>there are two categories of data replication protocols.</p>
<ul>
<li>a set of probablistic protocol -> eventual consistency<ul>
<li>gossip</li>
<li>epdemic broadcast</li>
<li>trees</li>
<li>bimodal multicast</li>
</ul>
</li>
<li>consensus protocol -> strong consistency<ul>
<li>2 or 3 phase commit</li>
<li>paxos</li>
<li>raft</li>
<li>chain replication</li>
</ul>
</li>
</ul>
<p>master-slave replication</p>
<h2 id="what-else"><a href="#what-else" class="headerlink" title="what else?"></a>what else?</h2><ul>
<li>consistency. The consistency issues can happen. consistency can be achieved by performing synchronous replication. but this will introduce additional latency and overall complexity of the system. so it’s heavily depends on the service requireemnts.</li>
<li><p>data expiration. The data can be expired after some time later depends on business requiremetns. If that’s the case we can schedule a batch job to remove expired keys. Or passively delete expired cache on a regular basis.</p>
</li>
<li><p>Local cache can be used on the clinet library side. LRU cache or Guava cache can be used.</p>
</li>
<li>Security.<ul>
<li>firewall</li>
<li>encrypt the data</li>
</ul>
</li>
<li>monitoring and loggin<ul>
<li>number of errors, latency, cache hit/miss, cpu, memory</li>
</ul>
</li>
<li>cache client<ul>
<li>maintain a list of cache servers</li>
<li>pick a shard</li>
<li>remote call</li>
<li>delegate many responsibilities to proxy, ref twemproxy project<br>or make cache servers responsible for picking a shard</li>
</ul>
</li>
<li>consistent hasing has 2 flaws. domino effect and not split the circle evenly-> add server on the circle multiple times</li>
</ul>
<h2 id="Reference"><a href="#Reference" class="headerlink" title="Reference"></a>Reference</h2><ul>
<li><a target="_blank" rel="noopener" href="https://youtu.be/iuqZvajTOyA">https://youtu.be/iuqZvajTOyA</a></li>
<li>TCP vs UDP, <a target="_blank" rel="noopener" href="https://www.geeksforgeeks.org/differences-between-tcp-and-udp/">https://www.geeksforgeeks.org/differences-between-tcp-and-udp/</a></li>
</ul>
</div>
<footer class="article-footer">
<a data-url="http://nberserk.github.io/2021/06/12/distributed-cache/" data-id="ckqq7lx5v0000gnqy9qde0s6r" class="article-share-link">
<i class="fa fa-share"></i> Share
</a>
<a href="http://nberserk.github.io/2021/06/12/distributed-cache/#disqus_thread" class="article-comment-link">
<i class="fa fa-comment"></i> Comments
</a>
<ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/system-design/" rel="tag">system design</a></li></ul>
</footer>
</div>
</article>
<article id="post-distributed-message-queue" class="article article-type-post" itemscope itemprop="blogPost">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2021/06/03/distributed-message-queue/">distribute message queue</a>
</h1>
</header>
<div class="article-meta">
<div class="article-datetime">
<a href="/2021/06/03/distributed-message-queue/" class="article-date"><time datetime="2021-06-03T15:00:00.000Z" itemprop="datePublished">2021-06-04</time></a>
</div>
</div>
<div class="article-inner">
<div class="article-entry" itemprop="articleBody">
<h2 id="requirements"><a href="#requirements" class="headerlink" title="requirements"></a>requirements</h2><p>Functional</p>
<ul>
<li>sendMsg(messageBody)</li>
<li>receiveMessage()</li>
</ul>
<p>Non-functional</p>
<ul>
<li>scalable(handles load increases, more queues, and messages)</li>
<li>highly avaiable(survive hardware/network failures)</li>
<li>performant(single digit latency for main operations)</li>
<li>durable(once submitted, data is not lost)</li>
</ul>
<h2 id="High-level-architecture"><a href="#High-level-architecture" class="headerlink" title="High-level architecture"></a>High-level architecture</h2><p><img src="https://user-images.githubusercontent.com/900639/123561015-d2499c00-d75a-11eb-9c83-28613d939fe2.png" alt="image"></p>
<h2 id="VIP-and-Load-balancer"><a href="#VIP-and-Load-balancer" class="headerlink" title="VIP and Load balancer"></a>VIP and Load balancer</h2><p>VIP can be SPOF. so VIP partitioning is required.</p>
<p><img src="https://user-images.githubusercontent.com/900639/123561052-1d63af00-d75b-11eb-8788-d3c35f2371e6.png" alt="image"></p>
<h2 id="FrontEnd-Service"><a href="#FrontEnd-Service" class="headerlink" title="FrontEnd Service"></a>FrontEnd Service</h2><ul>
<li>a lightweight web service</li>
<li>stateless service deployed across several data centers</li>
</ul>
<p>Functions</p>
<ul>
<li>request validation<ul>
<li>required parameters are present</li>
<li>data falss within an acceptable range</li>
</ul>
</li>
<li>Authentication/Authorization<ul>
<li>validating identity of a user of a service</li>
<li></li>
</ul>
</li>
<li>TLS(SSL) termination<ul>
<li>SSL on the load balancer is expensive</li>
<li>termination is </li>
</ul>
</li>
<li>Server-side encryption</li>
<li>Caching</li>
<li>Rate limiting(Throttling)<ul>
<li>leaky bucket algorithm</li>
</ul>
</li>
<li>request dispatching<ul>
<li>circuit breaker pattern prevents an application from repeately trying to execute an opertion that will be likely to fail</li>
<li>bulkhead pattern helps to isolate elements of an application into pools so that if one fails, the other will continue to function.</li>
</ul>
</li>
<li>request depulication<ul>
<li>may occur when a successful sendMessage fails to reach a client.</li>
</ul>
</li>
<li>usage data collection<ul>
<li>billing/ realtime usage</li>
</ul>
</li>
</ul>
<h2 id="Metadata-service"><a href="#Metadata-service" class="headerlink" title="Metadata service"></a>Metadata service</h2><ul>
<li>caching layer between frontend and a storage</li>
<li>many read, little writes</li>
<li>strong consistency storage preferred</li>
</ul>
<p><img src="https://user-images.githubusercontent.com/900639/123562894-58b7ab00-d766-11eb-825c-a607022ddf6f.png" alt="image"></p>
<h2 id="backend-service"><a href="#backend-service" class="headerlink" title="backend service"></a>backend service</h2><ul>
<li>where and how do we store message? -> RAM and local disk</li>
<li>how do we replicate data?</li>
<li>how does FrontEnd select a backend host to send data to? Metadata service</li>
<li>how does frontend know where to retrive data from? Metadata service</li>
</ul>
<h3 id="Option-A-Leader-follower-relationshiop"><a href="#Option-A-Leader-follower-relationshiop" class="headerlink" title="Option A: Leader-follower relationshiop"></a>Option A: Leader-follower relationshiop</h3><p><img src="https://user-images.githubusercontent.com/900639/123564263-9cfa7980-d76d-11eb-93f6-cae05e3e7262.png" alt="image"></p>
<h3 id="OPtion-B"><a href="#OPtion-B" class="headerlink" title="OPtion B:"></a>OPtion B:</h3><p><img src="https://user-images.githubusercontent.com/900639/123564280-b3083a00-d76d-11eb-9ede-73dc47643b62.png" alt="image"></p>
<p>comparions OPtion A/B :</p>
<table>
<thead>
<tr>
<th></th>
<th>in-cluster manager</th>
<th>out-cluster manager</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td>manages queue assignment within the cluster</td>
<td>managers queue assignment among clusters</td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td>maintains a list of hosts in the cluster</td>
<td>maintains a list of cluters</td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td>monitors heartbeats from hosts</td>
<td>monitos each cluster health</td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td>deals with leader and follower failures</td>
<td>deals with overheated clusters</td>
<td></td>
</tr>
<tr>
<td></td>
<td>split queue between cluster nodes(partitioning)</td>
<td>splits queue between clusters</td>
</tr>
</tbody>
</table>
<h2 id="What-else-is-important"><a href="#What-else-is-important" class="headerlink" title="What else is important"></a>What else is important</h2><ul>
<li>Queue creation and deletion</li>
<li>message deletion<ul>
<li>do not delete message. it can be deleted by batch job</li>
<li>consumer needs to call deleteMessae</li>
</ul>
</li>
<li>message replication<ul>
<li>async replication: low latency. how to sync when one host is down?</li>
<li>sync replication: high latency. hit consistency</li>
<li>hard to achieve <code>exactly once delivery</code></li>
</ul>
</li>
<li>push vs pull</li>
<li>FIFO. doesn’t guarantee the strict order of the message</li>
<li>security: encrypte messages</li>
<li>monitoring</li>
</ul>
<h2 id="final-look"><a href="#final-look" class="headerlink" title="final look"></a>final look</h2><p><img src="https://user-images.githubusercontent.com/900639/123564724-5279fc80-d76f-11eb-8a57-129d319cb3ae.png" alt="image"></p>
<h2 id="DB-selection"><a href="#DB-selection" class="headerlink" title="DB selection"></a>DB selection</h2><p><a target="_blank" rel="noopener" href="https://www.youtube.com/watch?v=cODCpXtPHbQ">https://www.youtube.com/watch?v=cODCpXtPHbQ</a></p>
<ul>
<li>Structured data<ul>
<li>yes<ul>
<li>Need ACID<ul>
<li>RDBMS(yes): mysql, orcle, sql server, postgres</li>
</ul>
</li>
</ul>
</li>
<li>no<ul>
<li>Ever increasing data && + finite queries -> Columnar DB: Cassandra, HBase</li>
<li>++ Data types && ++ queries -> document DB: mongoDB, Couch Base</li>
</ul>
</li>
</ul>
</li>
</ul>
<p>interesting example: At ecommerece site, we shouldn’t sell more than the remaining quantity. it should support ACID. so we can use SQL before placing order. but once order is created, then you can use MongoDB to save the data.</p>
<h2 id="Reference"><a href="#Reference" class="headerlink" title="Reference"></a>Reference</h2>
</div>
<footer class="article-footer">
<a data-url="http://nberserk.github.io/2021/06/03/distributed-message-queue/" data-id="ckqe4m43i002srcqy6ij6ozgy" class="article-share-link">
<i class="fa fa-share"></i> Share
</a>
<a href="http://nberserk.github.io/2021/06/03/distributed-message-queue/#disqus_thread" class="article-comment-link">
<i class="fa fa-comment"></i> Comments
</a>
<ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/design/" rel="tag">design</a></li></ul>
</footer>
</div>
</article>
<article id="post-design-patterns" class="article article-type-post" itemscope itemprop="blogPost">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2020/09/06/design-patterns/">design patterns</a>
</h1>
</header>
<div class="article-meta">
<div class="article-datetime">
<a href="/2020/09/06/design-patterns/" class="article-date"><time datetime="2020-09-06T15:00:00.000Z" itemprop="datePublished">2020-09-07</time></a>
</div>
</div>
<div class="article-inner">
<div class="article-entry" itemprop="articleBody">
<p>interesting topics during design pattern lectures</p>
<h1 id="implmenetation-by-intentions"><a href="#implmenetation-by-intentions" class="headerlink" title="implmenetation by intentions"></a>implmenetation by intentions</h1><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">printReport</span> <span class="params">(String CustomerID)</span> </span>{ </span><br><span class="line"> <span class="keyword">if</span>(!isValid(CustomerID)) <span class="keyword">throw</span> <span class="keyword">new</span> ArgumentException(); </span><br><span class="line"> Employee[] emps = getEmployees(CustomerID);</span><br><span class="line"> <span class="keyword">if</span>(needsSorting(emps)) </span><br><span class="line"> sortEmployees(emps); </span><br><span class="line"> printHeader(CustomerID);</span><br><span class="line"> printFormattedEmployees(emps);</span><br><span class="line"> printFooter(CustomerID);</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
<p>one public method contains multiple private methods fulfilling one specifc logic at a time. it’s your logical sequences when you implement <code>printReport</code> in your head. by doing this you can achieve</p>
<ul>
<li>Method cohesion</li>
<li>separation of concerns<ul>
<li>sergeant method: calls other methods</li>
<li>private methods: implementing code</li>
</ul>
</li>
<li>clarity - clear code is better than comments</li>
<li>easy in finding/forming certain patterns</li>
<li>no extra work is required</li>
</ul>
<h1 id="Commonality-Variability-Analysis-CVA"><a href="#Commonality-Variability-Analysis-CVA" class="headerlink" title="Commonality-Variability Analysis, CVA"></a>Commonality-Variability Analysis, CVA</h1><p>Assume you start a new project solving software problem in a certain domain. you heard bunch of requirments from your clients. how would you find a entities, create an abstraction with whom, find a suitable patterns among them.</p>
<p>at this time CVA can help you</p>
<p>requirements</p>
<ul>
<li>US Tax</li>
<li>Canadian PST, GST</li>
<li>Validation of addresses strcuture in different locations</li>
</ul>
<p>from this requirments you can derive a following potential entities and abstractions.</p>
<p>examle of CVA:</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">Country</span><br><span class="line">----</span><br><span class="line">US</span><br><span class="line">Canada</span><br><span class="line"></span><br><span class="line">Tax</span><br><span class="line">-----</span><br><span class="line">Canadian Province</span><br><span class="line">Canadian Fed</span><br><span class="line">US</span><br><span class="line"></span><br><span class="line">AddressValidation</span><br><span class="line">------</span><br><span class="line">US</span><br><span class="line">Canada</span><br></pre></td></tr></table></figure>
</div>
<footer class="article-footer">
<a data-url="http://nberserk.github.io/2020/09/06/design-patterns/" data-id="ckqe4m43h002rrcqy7vyo0alk" class="article-share-link">
<i class="fa fa-share"></i> Share
</a>
<a href="http://nberserk.github.io/2020/09/06/design-patterns/#disqus_thread" class="article-comment-link">
<i class="fa fa-comment"></i> Comments
</a>
<ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/CVA/" rel="tag">CVA</a></li></ul>
</footer>
</div>
</article>
<article id="post-wordgrep-pp" class="article article-type-post" itemscope itemprop="blogPost">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2020/08/31/wordgrep-pp/">WordGrep Privacy Policy</a>
</h1>
</header>
<div class="article-meta">
<div class="article-datetime">
<a href="/2020/08/31/wordgrep-pp/" class="article-date"><time datetime="2020-08-31T15:00:00.000Z" itemprop="datePublished">2020-09-01</time></a>
</div>
</div>
<div class="article-inner">
<div class="article-entry" itemprop="articleBody">
<p><strong>Privacy Policy</strong></p>
<p>nberserk built the WordGrep app as a Free app. This SERVICE is provided by nberserk at no cost and is intended for use as is.</p>
<p>This page is used to inform visitors regarding my policies with the collection, use, and disclosure of Personal Information if anyone decided to use my Service.</p>
<p>If you choose to use my Service, then you agree to the collection and use of information in relation to this policy. The Personal Information that I collect is used for providing and improving the Service. I will not use or share your information with anyone except as described in this Privacy Policy.</p>
<p>The terms used in this Privacy Policy have the same meanings as in our Terms and Conditions, which is accessible at WordGrep unless otherwise defined in this Privacy Policy.</p>
<p><strong>Information Collection and Use</strong></p>
<p>For a better experience, while using our Service, I may require you to provide us with certain personally identifiable information, including but not limited to name. The information that I request will be retained on your device and is not collected by me in any way.</p>
<p>The app does use third party services that may collect information used to identify you.</p>
<p>Link to privacy policy of third party service providers used by the app</p>
<ul>
<li><a href="https://www.google.com/policies/privacy/" target="_blank" rel="noopener">Google Play Services</a></li>
<li><a href="https://firebase.google.com/policies/analytics" target="_blank" rel="noopener">Google Analytics for Firebase</a></li>
</ul>
<p><strong>Log Data</strong></p>
<p>I want to inform you that whenever you use my Service, in a case of an error in the app I collect data and information (through third party products) on your phone called Log Data. This Log Data may include information such as your device Internet Protocol (“IP”) address, device name, operating system version, the configuration of the app when utilizing my Service, the time and date of your use of the Service, and other statistics.</p>
<p><strong>Cookies</strong></p>
<p>Cookies are files with a small amount of data that are commonly used as anonymous unique identifiers. These are sent to your browser from the websites that you visit and are stored on your device’s internal memory.</p>
<p>This Service does not use these “cookies” explicitly. However, the app may use third party code and libraries that use “cookies” to collect information and improve their services. You have the option to either accept or refuse these cookies and know when a cookie is being sent to your device. If you choose to refuse our cookies, you may not be able to use some portions of this Service.</p>
<p><strong>Service Providers</strong></p>
<p>I may employ third-party companies and individuals due to the following reasons:</p>
<ul>
<li>To facilitate our Service;</li>
<li>To provide the Service on our behalf;</li>
<li>To perform Service-related services; or</li>
<li>To assist us in analyzing how our Service is used.</li>
</ul>
<p>I want to inform users of this Service that these third parties have access to your Personal Information. The reason is to perform the tasks assigned to them on our behalf. However, they are obligated not to disclose or use the information for any other purpose.</p>
<p><strong>Security</strong></p>
<p>I value your trust in providing us your Personal Information, thus we are striving to use commercially acceptable means of protecting it. But remember that no method of transmission over the internet, or method of electronic storage is 100% secure and reliable, and I cannot guarantee its absolute security.</p>
<p><strong>Links to Other Sites</strong></p>
<p>This Service may contain links to other sites. If you click on a third-party link, you will be directed to that site. Note that these external sites are not operated by me. Therefore, I strongly advise you to review the Privacy Policy of these websites. I have no control over and assume no responsibility for the content, privacy policies, or practices of any third-party sites or services.</p>
<p><strong>Children’s Privacy</strong></p>
<p>These Services do not address anyone under the age of 13. I do not knowingly collect personally identifiable information from children under 13. In the case I discover that a child under 13 has provided me with personal information, I immediately delete this from our servers. If you are a parent or guardian and you are aware that your child has provided us with personal information, please contact me so that I will be able to do necessary actions.</p>
<p><strong>Changes to This Privacy Policy</strong></p>
<p>I may update our Privacy Policy from time to time. Thus, you are advised to review this page periodically for any changes. I will notify you of any changes by posting the new Privacy Policy on this page.</p>
<p>This policy is effective as of 2020-09-02</p>
<p><strong>Contact Us</strong></p>
<p>If you have any questions or suggestions about my Privacy Policy, do not hesitate to contact me at <a href="mailto:wordgrep@gmail.com" target="_blank" rel="noopener">wordgrep@gmail.com</a>.</p>
</div>
<footer class="article-footer">
<a data-url="http://nberserk.github.io/2020/08/31/wordgrep-pp/" data-id="ckqe4m43g002qrcqy23xz5d1k" class="article-share-link">
<i class="fa fa-share"></i> Share
</a>
<a href="http://nberserk.github.io/2020/08/31/wordgrep-pp/#disqus_thread" class="article-comment-link">
<i class="fa fa-comment"></i> Comments
</a>
<ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/wordgrep/" rel="tag">wordgrep</a></li></ul>
</footer>
</div>
</article>
<article id="post-rake" class="article article-type-post" itemscope itemprop="blogPost">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2020/04/20/rake/">rake</a>
</h1>
</header>
<div class="article-meta">
<div class="article-datetime">
<a href="/2020/04/20/rake/" class="article-date"><time datetime="2020-04-20T15:00:00.000Z" itemprop="datePublished">2020-04-21</time></a>
</div>
</div>
<div class="article-inner">
<div class="article-entry" itemprop="articleBody">
<p>rake is Makefile for ruby world. I am not big fan of Ruby but I like Rake as a task execuion library.</p>
<h1 id="task-defintion-amp-dependency"><a href="#task-defintion-amp-dependency" class="headerlink" title="task defintion & dependency"></a>task defintion & dependency</h1><figure class="highlight ruby"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">task <span class="symbol">:A</span> <span class="keyword">do</span></span><br><span class="line"> sh <span class="string">"echo A task executed"</span></span><br><span class="line"><span class="keyword">end</span></span><br><span class="line"></span><br><span class="line">task <span class="symbol">B:</span> [<span class="symbol">:A</span> ] <span class="keyword">do</span></span><br><span class="line"> sh <span class="string">"echo A task executed"</span></span><br><span class="line"><span class="keyword">end</span></span><br></pre></td></tr></table></figure>
<h1 id="find-directory-where-rake-is-invoked"><a href="#find-directory-where-rake-is-invoked" class="headerlink" title="find directory where rake is invoked."></a>find directory where rake is invoked.</h1><p>sometimes, maven or gradle build command should be executed at project root directory. but current directory is changed by Rake where the Rakefile is located. so build command would fail by that reason. in this case we can get the origial directory by using the following Ruby APIs.</p>
<figure class="highlight ruby"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">dir = Rake.application.original_dir</span><br><span class="line">Dir.chdir(dir) <span class="keyword">do</span></span><br><span class="line"> sh <span class="string">"mvn"</span></span><br><span class="line"> sh <span class="string">"gradle"</span></span><br><span class="line"><span class="keyword">end</span></span><br></pre></td></tr></table></figure>
</div>
<footer class="article-footer">
<a data-url="http://nberserk.github.io/2020/04/20/rake/" data-id="ckqe4m43f002prcqynzq93jil" class="article-share-link">
<i class="fa fa-share"></i> Share
</a>
<a href="http://nberserk.github.io/2020/04/20/rake/#disqus_thread" class="article-comment-link">
<i class="fa fa-comment"></i> Comments
</a>
<ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/rake/" rel="tag">rake</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/ruby/" rel="tag">ruby</a></li></ul>
</footer>
</div>
</article>
<article id="post-fzf-ripgrep" class="article article-type-post" itemscope itemprop="blogPost">
<header class="article-header">
<h1 itemprop="name">
<a class="article-title" href="/2019/11/11/fzf-ripgrep/">fzf ripgrep</a>
</h1>
</header>
<div class="article-meta">
<div class="article-datetime">
<a href="/2019/11/11/fzf-ripgrep/" class="article-date"><time datetime="2019-11-11T15:00:00.000Z" itemprop="datePublished">2019-11-12</time></a>
</div>
</div>
<div class="article-inner">
<div class="article-entry" itemprop="articleBody">
<p>two useful command line tools. highly recommen to use those.</p>
<h1 id="fzf-fuzzy-finder"><a href="#fzf-fuzzy-finder" class="headerlink" title="fzf - fuzzy finder"></a>fzf - fuzzy finder</h1><p>see this video : <a href="https://www.youtube.com/watch?v=qgG5Jhi_Els" target="_blank" rel="noopener">https://www.youtube.com/watch?v=qgG5Jhi_Els</a></p>
<p><a href="https://github.com/junegunn/fzf" target="_blank" rel="noopener">https://github.com/junegunn/fzf</a></p>
<h1 id="ripgrep"><a href="#ripgrep" class="headerlink" title="ripgrep"></a>ripgrep</h1><p>whenever I need to use grep, I have to find the right syntax on the web. It’s because the syntax is not intuitive at all. but after switiching to ripgrep, no more search is required. </p>
<p><a href="https://github.com/BurntSushi/ripgrep" target="_blank" rel="noopener">https://github.com/BurntSushi/ripgrep</a></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">rg <span class="string">'fn write\('</span></span><br></pre></td></tr></table></figure>
</div>
<footer class="article-footer">
<a data-url="http://nberserk.github.io/2019/11/11/fzf-ripgrep/" data-id="ckqe4m43e002orcqy8a517l32" class="article-share-link">
<i class="fa fa-share"></i> Share
</a>
<a href="http://nberserk.github.io/2019/11/11/fzf-ripgrep/#disqus_thread" class="article-comment-link">
<i class="fa fa-comment"></i> Comments
</a>
<ul class="article-tag-list" itemprop="keywords"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/fzf/" rel="tag">fzf</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/ripgrep/" rel="tag">ripgrep</a></li></ul>
</footer>
</div>
</article>
<article id="post-tmux" class="article article-type-post" itemscope itemprop="blogPost">
<header class="article-header">