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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
AIエージェントで 変わるAndroid開発環境
takahirom
2
720
ソフトウェア設計に溶けるインフラ ― AWS CDK のインフラ認識論
konokenj
3
650
SLOをサービス品質の共通言語にするために 取り組んできたこと
wakana0222
0
550
全PRの83%がAIレビューだけでマージできるようになった開発組織はその後どうなったか
athug
0
380
Embedded SREと共に達成した会員管理システムのAWS移行 - SRE NEXT 2026 ランチスポンサーセッション
niftycorp
PRO
1
3k
今さら聞けない .NET CLI
htkym
0
130
ITヒヤリハットを整理してみた ~ライフサイクルと原因から考える再発防止策~
koukimiura
1
110
分散システム、なんですぐ死んでしまうん?耐障害性を高めたいあなたのためのレジリエンスパターン入門
mshibuya
7
6.9k
Welcome to the "Parametricity" 🏙️ − Generic だけど Specific な世界 −
guvalif
PRO
1
180
Claude Opus 4.6以後の受託開発エンジニアの変化(Claude Code開発ノウハウ大公開スペシャルbyクラスメソッド)
iidatakuma
1
860
【SRE NEXT 2026 Lunch Session】一人目専任SREの立ち上げを加速する ― AIと進めたオンボーディングで2分を0.04秒にした話
pkshadeck
PRO
0
3k
AI時代のPHPer生存戦略 ~「言語、もうなんでもよくない?」に本気で向き合う~
vivion
0
170
Featured
See All Featured
The SEO identity crisis: Don't let AI make you average
varn
0
520
Mobile First: as difficult as doing things right
swwweet
225
10k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
64
56k
Are puppies a ranking factor?
jonoalderson
1
3.7k
The Spectacular Lies of Maps
axbom
PRO
1
870
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
240
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
420
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
3k
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
880
From π to Pie charts
rasagy
0
240
My Coaching Mixtape
mlcsv
0
180
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
910
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