Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Scala With Cats: Case Study: CRDTs
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Kurochan
August 07, 2018
210
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Scala With Cats: Case Study: CRDTs
Kurochan
August 07, 2018
More Decks by Kurochan
See All by Kurochan
ABEMAのバグバウンティの取り組み
kurochan
1
1.2k
2026年の個人的テーマ: 「計算機を燃やせ🔥」
kurochan
1
230
つなぐ、届ける、変える- コンテンツ配信の最前線ト——ク
kurochan
0
190
サイバーエージェント流クラウドコスト削減施策「みんなで金塊堀太郎」
kurochan
4
3.4k
AWS Elemental MediaPackageと格闘🤼
kurochan
2
150
サイバーエージェントでのSlack活用事例 @ 2025
kurochan
5
300
15年入社者に聞く! これまでのCAのキャリアとこれから
kurochan
1
420
入門 電気通信事業者
kurochan
13
5.9k
AWS x さくらのクラウドのハイブリッドクラウドによる安価なフレッツ閉域網接続の実装
kurochan
10
6.5k
Featured
See All Featured
Making Projects Easy
brettharned
120
6.8k
Paper Plane (Part 1)
katiecoart
PRO
2
11k
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
560
Joys of Absence: A Defence of Solitary Play
codingconduct
1
530
Skip the Path - Find Your Career Trail
mkilby
1
240
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
290
Designing Dashboards & Data Visualisations in Web Apps
destraynor
232
55k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
440
Java REST API Framework Comparison - PWX 2021
mraible
34
9.7k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
The browser strikes back
jonoalderson
0
1.7k
RailsConf 2023
tenderlove
30
1.6k
Transcript
Scala with Cats Case Study: CRDTs https://underscore.io/books/scala-with-cats/
CRDTs • Commutative Replicated Data Types • or Conflict-free Replicated
Data Types • ݁Ռ߹ੑͷ͋Δσʔλߏ • ϞϊΠυ͕ͲͷΑ͏ʹཱ͔ͭͷྫͱͯ͠CRDTsΛհ
Consistency • γεςϜ͕εέʔϧ͢Δͱ୯ҰͷϚγϯΛ͑ͯσʔλ Λཧ͠ͳ͍ͱ͍͚ͳ͘ͳΔ • શͯͷϚγϯ͕ಉ͡σʔλΛ࣋ͭڥΛఆ͢Δ • 1ͭͷϚγϯ͕ϢʔβͷύεϫʔυΛߋ৽͢Δͱɺ શͷϚγϯ͕ಉ͡ίϐʔΛ࣋ͭ •
શͷϚγϯ͕ͦΕΛड͚ೖΕͨ͋ͱ ͦͷૢ࡞ྃ͢Δ
Eventual Consistency • લϖʔδͷྫͩͱ߹ੑ͕อͯΔ͕ɺ1ͭͷૢ࡞ͷͨΊʹશ ͱಉظΛͱΔͷͰϨΠςϯγ͕ѱԽ͢Δ • ωοτϫʔΫোʹΑΔஅൃੜ͢Δ • ߹ੑΛอͭͨΊʹૢ࡞Λڋ൱͢Δ͔͠ͳ͍ •
݁Ռ߹ੑͷ͋ΔγεςϜͰ֤Ϛγϯ͕Ұ࣌తʹҟͳΔ ঢ়ଶΛ࣋ͭࣄΛڐ༰͢Δ • ݁Ռతʹ߹ੑ͕औΕΕ͍͍ͷͰૢ࡞ʹର͢ΔԠ ૣ͘ͳΔ • ωοτϫʔΫোʹΑΔஅ͕ൃੜͯ͠ॲཧΛܧଓͰ͖Δ
CRDT • ͲͷΑ͏ʹͯ͠ϚγϯؒͰ݁Ռ߹ੑΛऔΔͷ͔ʁ • CRDT͕ͻͱͭͷղͱͳΔ • Commutative Replicated Data Types
• CRDTͷ࣮ͷͻͱͭͱͯ͠G-CounterΛհ͢Δ
G-Counters • ࢄΧϯλͱͯ͑͠Δ • ૿Ճ͢ΔΦϖϨʔγϣϯʹͷΈରԠ͢Δ • webαʔόͷ๚ऀͷΧϯτʹ͑Δ
Simple counters • ୯ʹड͚औͬͨϦΫΤετΛ௨ͯ͠͠߹ΘͤΔ
Simple counters • ՃͰϦΫΤετ͕དྷͨͱ͖ʹΧϯλͷΛ্͠ ͛Δͱ͓͔͘͠ͳΔ • 2ͱ"6"Λอ͍࣋ͯ͠ͳ͍ͱ͍͚ͳ͍ͣ…
G-Counters • G-Counter֤ϚγϯͷΧϯλΛ͍࣋ͬͯΔ • ΛΠϯΫϦϝϯτͰ͖ΔͷࣗͷΧϯλ͚ͩ • ঢ়ଶߋ৽ͷϝοηʔδ͕དྷͨΒɺͦͷϚγϯͷΧ ϯλͷ࠷େͰஔ͖͑Δ(Grow only)
G-Counters • ͦͷϚγϯͷΧϯλͷ࠷େͰஔ͖͑Δ
11.2.3 Exercise: GCounter Implementation • G-CounterΛ࣮ͯ͠Έ·͠ΐ͏ • counter: Map[String, Int]
• key͕machine id, value͕Χϯτ • increment: GCounter • ࢦఆͨ͠machineͷΧϯτΛࢦఆͨ͠ amount͚ͩ͢ • merge: GCounter • 2ͭͷGCounterΛϚʔδ͢Δ
11.2.3 Exercise: GCounter Implementation • G-CounterΛ࣮ͯ͠Έ·͠ΐ͏
Additional Exercise: PN-Counter Implementation • PN-CounterΛ࣮ͯ͠Έ·͠ΐ͏ • Ҿ͖ࢉՄೳʹͨ͠CRDTs (Positive, Negative)
Additional Exercise: PN-Counter Implementation • PN-CounterΛ࣮ͯ͠Έ·͠ΐ͏ • Ҿ͖ࢉՄೳʹͨ͠CRDTs
Generalisation • ͖͞΄ͲͷG-CounterΛநԽ͍ͯ͘͠ • G-Counter • Ճࢉ: ΠϯΫϦϝϯτ͞Εͨ߹ܭΛ࣋ͭ • ࠷େ:
Ϛʔδ࣌࠷େΛ࣋ͭ • ॳظ 0 • => ϞϊΠυͰ͋Δ • (a + b) + c == a + (b + c) • 0 + a == a + 0 == a • a max a = a (mergeͷૢ࡞ႈੑ͕͋Δ)
Generalisation • ͖͞΄ͲͷG-CounterΛநԽ͍ͯ͘͠ • increment: monoid • total: monoid +
Մ • merge: monoid + ႈ + Մ • => ༗քଋͱݴ͏
Generalisation • લड़ͷಛΑΓɺGCounterࣗવͱಉ༷ͳૢ࡞͕Ͱ ͖Δͷʹஔ͖͑ΒΕΔ • ࣗવͷΘΓʹSet[A]ΛͬͯGSetͱ͍͏ܕΛ࣮ ͢Δ͜ͱͰ͖Δͣ
Bounded SemiLattice • ༗քଋ • https://qiita.com/yasuabe2613/items/ ba2c5136a4e0822b6ba4
11.3.2 Exercise: BoundedSemiLattice Instances • IntͱSet༻ͷ༗քଋΛ࣮ͯ͠Έ·͠ΐ͏ • Intࣗવ(0ΛؚΉ)͔࣋ͨ͠ͳ͍ͱԾఆͯ͠Α͍
11.3.2 Exercise: BoundedSemiLattice Instances • IntͱSet༻ͷ༗քଋΛ࣮ͯ͠Έ·͠ΐ͏ • Intࣗવ(0ΛؚΉ)͔࣋ͨ͠ͳ͍ͱԾఆͯ͠Α͍
11.3.3 Exercise:Generic G-Counter • MonoidͱBoundedSemiLatticeΛͬͯGCounterΛ ࣮͠·͠ΐ͏ • Monoidͷจ๏Λͬͯγϯϓϧʹॻ͖·͠ΐ͏
Abstracting G-Counter to a Type Class • TypeClassΛͬͯG-CounterΛ͞ΒʹநԽ͢Δ • Map2ͭͷܕύϥϝʔλΛऔΔԿ͔ͳΒΑ͍ͷͰ
Abstracting a Key Value Store • MapKVSʹஔ͖͑ΒΕΔͣ • Mapͩͬͨ෦ΛநԽ͢Δ
Abstracting a Key Value Store • MapKVSʹஔ͖͑ΒΕΔͣ • σʔλܕͷૢ࡞Λ֦ு͢Δimplicit class
Abstracting a Key Value Store • KVS͕நԽͰ͖ͨ͜ͱͰKVSͷ༷Λຬ͍ͨͯ͠Ε ͲΜͳܕͰG-Counter͕࡞ΕΔΑ͏ʹͳͬͨ
Summary • γϯϓϧͳCRDTͰ͋ΔG-CounterΛTypeClassΛ༻͍ͯ Ͳ͏࣮͢Δ͔Λࣔͨ͠ • ίʔυͷ࠶ར༻ੑΛߴΊɺΧϯτ͢Δͱ͍͏ૢ࡞ʹ ͚ͩʹറΒΕͳ͘ͳͬͨ • ଞʹCRDTs͍Ζ͍Ζ͋ΔͷͰҎԼΛࢀߟʹ •
https://hal.inria.fr/inria-00609399v2/document
None