Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
designing for concurrency with riak
Search
Mathias Meyer
May 29, 2012
Programming
1.9k
11
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
designing for concurrency with riak
http://riakhandbook.com
Mathias Meyer
May 29, 2012
More Decks by Mathias Meyer
See All by Mathias Meyer
Building and Scaling an Distributed and Inclusive Team
roidrage
0
1.4k
cooking infrastructure with chef
roidrage
4
250
The Message Queue is Dead, Long Live the Message Queue
roidrage
4
730
riak-js
roidrage
1
320
metrics, monitoring, logging
roidrage
82
15k
design for cloud - jax 2012
roidrage
2
340
A Riak Query Tale
roidrage
5
1k
Don't Use NoSQL
roidrage
10
1.1k
Designing Applications for Amazon Web Services (GOTO Aarhus)
roidrage
6
380
Other Decks in Programming
See All in Programming
【やさしく解説 設計編 #1】「ドメイン駆動」と「実装駆動」ってなに? 〜設計の考え方を、たとえ話で学ぼう〜
panda728
PRO
1
130
エンジニア向け会社紹介/Findy Company Profile
findyinc
6
360k
AI時代の仕事技芸論〜ソフトウェア開発で「遊ぶように働く」職人的熟達のすすめ(スクフェス仙台 2026バージョン)
kuranuki
0
720
Laravel Boostに学ぶ、AIにPHPを書かせる技術 〜OSSの実装から蒸留するエージェント制御の王道〜
kentaroutakeda
3
530
今さら聞けない .NET CLI
htkym
0
130
生成AI導入の「期待外れ」を乗り越える ー 開発フロー改革が目指す、真の組織変革
starfish719
0
2.2k
PostgreSQL 18で考えるUUID主キー
kazuhiro1982
0
380
JAWS-UG横浜 #102 AWSサ終供養LT会 成仏できない AWS サービスたち 〜本日、三体供養します〜
maroon1st
0
240
アルゴリズムは何を圧縮しているのか ─ Haskell から育った「圧縮代数」というメンタルモデル
naoya
16
3.6k
The Bowling Game- From Imperative to Functional Programming - Part 1
philipschwarz
PRO
0
340
AIキャラアプリkaiwaの低遅延音声通話基盤をどう作ったか - AWS Gravitonで支える低遅延・低コストAI Agent基盤
mogamit
0
190
Welcome to the "Parametricity" 🏙️ − Generic だけど Specific な世界 −
guvalif
PRO
1
180
Featured
See All Featured
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
390
My Coaching Mixtape
mlcsv
0
180
Writing Fast Ruby
sferik
630
63k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.7k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Become a Pro
speakerdeck
PRO
31
6k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.9k
Thoughts on Productivity
jonyablonski
76
5.3k
Avoiding the “Bad Training, Faster” Trap in the Age of AI
tmiket
0
200
Redefining SEO in the New Era of Traffic Generation
szymonslowik
1
370
Why You Should Never Use an ORM
jnunemaker
PRO
61
9.9k
Digital Ethics as a Driver of Design Innovation
axbom
PRO
1
350
Transcript
designing for concurrency with riak nosql matters mathias meyer, @roidrage
None
http://riakhandbook.com
design for concurrency?
design data for concurrency
data starts out simple
ID Username Email 1 roidrage
[email protected]
2 thomas
[email protected]
3
karen
[email protected]
single source of truth
always consistent
mostly consistent
monotonic
increase number of sources
replication
ID Username Email 1 roidrage
[email protected]
2 thomas
[email protected]
3
karen
[email protected]
ID Username Email 1 roidrage
[email protected]
2 thomas
[email protected]
3 karen
[email protected]
ID Username Email 1 roidrage
[email protected]
2 thomas
[email protected]
3
karen
[email protected]
ID Username Email 1 roidrage
[email protected]
2 thomas
[email protected]
3 karen
[email protected]
ID Username Email 1 roidrage
[email protected]
2 thomas
[email protected]
3 karen
[email protected]
ID Username Email 1 roidrage
[email protected]
2 thomas
[email protected]
3
karen
[email protected]
ID Username Email 1 roidrage
[email protected]
2 thomas
[email protected]
3 karen
[email protected]
ID Username Email 1 roidrage
[email protected]
2 thomas
[email protected]
3 karen
[email protected]
ID Username Email 1 roidrage
[email protected]
2 thomas
[email protected]
3 karen
[email protected]
ID Username Email 1 roidrage
[email protected]
2 thomas
[email protected]
3 karen
[email protected]
ID Username Email 1 roidrage
[email protected]
2 thomas
[email protected]
3 karen
[email protected]
eventual consistency* * if no new updates are made to
the object, eventually all accesses will return the last updated value. werner vogels, 2008, http://queue.acm.org/detail.cfm?id=1466448
multiple clients
ID Username Email 1 roidrage
[email protected]
2 thomas
[email protected]
3
karen
[email protected]
ID Username Email 1 roidrage
[email protected]
2 thomas
[email protected]
3 karen
[email protected]
Client 1 Client 2 PUT PUT
conflicting writes
siblings
data diverges
the challenge
determine the winner
determine order
designing data for concurrency
designing data for non-monotonic writes
no atomicity in riak
no coordination
all state is in the data
(eventual) consistency and logical monoticity * hellerstein: the declarative imperative:
experiences and conjectures in distributed logic (2010)
designing data with conflicts in mind
write now, converge later
rethink the data structures
ID Username Email 1 roidrage
[email protected]
{ "id": 1,
"username": "roidrage", "email": "
[email protected]
" }
track updates
{ "id": 1, "username": "roidrage", "email": "
[email protected]
"
"changes": [ { "client": "client-‐1", "timestamp": 1337001337, "updates": [ "firstname": "Mathias", "lastname": "Meyer" ] } ] }
{ "id": 1, "username": "roidrage", "email": "
[email protected]
"
"changes": [ { "client": "client-‐2", "timestamp": 1337001337, "updates": [ "email": "
[email protected]
" ] } ] }
apply all updates ordered by time
what about removing data?
{ "id": 1, "username": "roidrage", "email": "
[email protected]
"
"changes": [{ "client": "client-‐1", "timestamp": 1337001337, "updates": [ { "_op": "delete", "attribute": "email" } ] }] }
{ "id": 1, "username": "roidrage", "email": "
[email protected]
"
"changes": [{ "client": "client-‐2", "timestamp": 1337001337, "updates": [ { "_op": "add", "attribute": "email", "value": "
[email protected]
" } ] }] }
keep a changelog
client converges data
time as a means of ordering* * leslie lamport, et.
al.: time, clocks and the ordering of events in a distributed system (1977)
time is not a guarantee for uniqueness
vector clocks?
{ "id": 1, "username": "roidrage", "email": "
[email protected]
"
"changes": [{ "id": "ca0cb932-‐a74e-‐11e1-‐9ce4-‐1093e90b5d80", "timestamp": 1337001337, "updates": [ { "_op": "delete", "attribute": "email" } ] ] }
timelines* * riak at yammer: http://basho.com/blog/technical/2011/03/28/Riak-and-Scala-at-Yammer/
time-ordered series of events
kept per user
{ "events": [ {
"id": "ca0cb932-‐a74e-‐11e1-‐9ce4-‐1093e90b5d80", "timestamp": 1337001337, "event": { "type": "push", "repository": "rails/rails", "sha1": "0ea43bf" } }, { "id": "e018f024-‐a74e-‐11e1-‐9feb-‐1093e90b5d80", "timestamp": 1337001337, "event": { "type": "pull_request", "repository": "rails/rails", "sha1": "84efda0" } } ] }
clients dedup, sort and truncate
observation: clients manage the data
sets, counters, graphs
monotonic data structures
sets
an unordered bag of unique items
simplest thing that could possibly work...in riak
secondary indexes
X-‐Riak-‐Index-‐tags_bin: nosql, cloud, infrastructure { "id": 1, "username":
"roidrage", "email": "
[email protected]
" }
always unique
useful for simple things
useful for object associations
add-only
set: time-ordered list of operations
{ "set": [ {
"id": "e018f024-‐a74e-‐11e1-‐9feb-‐1093e90b5d80", "timestamp": 1337001337, "op": "add", "value": "roidrage" } ] }
{ "set": [ {
"id": "e018f024-‐a74e-‐11e1-‐9feb-‐1093e90b5d80", "timestamp": 1337001337, "op": "add", "value": "roidrage" }, { "id": "56707cee-‐a757-‐11e1-‐8e1b-‐1093e90b5d80", "timestamp": 1337001339, "op": "add", "value": "josh" } ] }
{ "set": [ {
"id": "e018f024-‐a74e-‐11e1-‐9feb-‐1093e90b5d80", "timestamp": 1337001337, "op": "add", "value": "roidrage" }, { "id": "56707cee-‐a757-‐11e1-‐8e1b-‐1093e90b5d80", "timestamp": 1337001339, "op": "add", "value": "josh" }, { "id": "a525f16c-‐a968-‐11e1-‐8b07-‐1093e90b5d80", "timestamp": 1337001343, "op": "remove", "value": "josh" } ] }
slightly inefficient
2-phase set* * https://github.com/aphyr/meangirls
{ "set": { "adds": ["roidrage", "josh"],
"removes": ["josh"] } }
counters
increment, decrement
{ "counter": [ {
"id": "e018f024-‐a74e-‐11e1-‐9feb-‐1093e90b5d80", "timestamp": 1337001337, "op": "incr", "value": 4 } ], }
g-counters* *a comprehensive study of convergent and commutative replicated data
types http://hal.inria.fr/docs/00/55/55/88/PDF/techreport.pdf
{ "elements": { "client-‐1": 1,
"client-‐2": 3, "client-‐3": 5 } } value = 1 + 3 + 5 = 9
counters are easy when you increment only
convergent replicated data types *shapiro et. al.: a comprehensive study
of convergent and commutative replicated data types http://hal.inria.fr/docs/00/55/55/88/PDF/techreport.pdf
statebox for erlang* * https://github.com/mochi/statebox
knockbox for clojure* * https://github.com/reiddraper/knockbox
data represents state
state-based means growth
data increases with lots of updates
dealing with growth
truncate
roll up, discard
{ "counter": [{ "id": "458f5936-‐a752-‐11e1-‐a876-‐1093e90b5d80",
"timestamp": 1337001347, "op": "inc", "value": 1 }], "value": 2 }
garbage collection
not easy with riak
not easy with stateful data
garbage collection requires coordination
network partitions cause stale data
the solution?
trade off data size vs. consistency
commutative replicated data types* *shapiro et. al.: a comprehensive study
of convergent and commutative replicated data types http://hal.inria.fr/docs/00/55/55/88/PDF/techreport.pdf
operations instead of state
not yet possible with riak
eventual consistency is hard
thanks