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
Offline first collaboration with event sourcing
Search
Steven Chan
May 10, 2017
Programming
1
460
Offline first collaboration with event sourcing
Demo code at
https://github.com/stevenchan/event-sourcing-todo-example
Steven Chan
May 10, 2017
Tweet
Share
More Decks by Steven Chan
See All by Steven Chan
Shape Recognition
stevenchan
0
38
Other Decks in Programming
See All in Programming
App Router 悲喜交々
quramy
7
370
C#および.NETに対する誤解をひも解く
ymd65536
0
230
tsconfig.jsonの最近の新機能 ファイルパス編
uhyo
6
1.4k
"noncopyable types" の使いどころについて考えてみた
andpad
0
130
[PHPカンファレンス沖縄2024]「無理なくできるだけ安全に」テストもないレガシーコードをリファクタリングするテクニック
ikezoemakoto
3
110
DjangoNinjaで高速なAPI開発を実現する
masaya00
0
440
A Journey of Contribution and Collaboration in Open Source
ivargrimstad
0
160
Делим тесты между QA и разработчиком
mariyasaygina
0
480
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
1.1k
5年分のツケを一気に払った話
soogie
3
1.2k
Re:PandasAI:生成AIがデータ分析業務にもたらすパラダイムシフト【増補改訂版】
negi111111
1
800
M5Stackボードの選び方
tanakamasayuki
0
200
Featured
See All Featured
GraphQLの誤解/rethinking-graphql
sonatard
65
9.9k
How GitHub (no longer) Works
holman
311
140k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
38
2.1k
The Straight Up "How To Draw Better" Workshop
denniskardys
231
130k
It's Worth the Effort
3n
183
27k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
30
2.6k
KATA
mclloyd
27
13k
What the flash - Photography Introduction
edds
67
11k
Fontdeck: Realign not Redesign
paulrobertlloyd
81
5.2k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
RailsConf 2023
tenderlove
28
840
How GitHub Uses GitHub to Build GitHub
holman
473
290k
Transcript
Offline First Collaboration with Event Sourcing Steven Chan - @stevnchan
GoodNotes
Syncing is hard
What we have tried
Apple CloudKit • Remote database API • Need to implement
syncing with local cache ourselves • Designing a correct algorithm to sync two object graphs is hard • Limited schema migration support • Undocumented limit for sharing records
Google Firebase • Real-time database • Mobile SDKs available •
Offline mode: store updates in a queue • Performance become worse as the queue become long
Event sourcing to rescue
Event sourcing to rescue 1. Store all changes as events
in a single queue 2. Only need to sync the event queue 3. Derive the app state from the event queue 4. Migration = rewrite the derivation function
Todo app example 1. {inserted, id123, “Buy milk”} 2. {completed,
id123} 3. {deleted, id123}
Update app state 1. {inserted, id123, “Buy milk”} 2. {completed,
id123} 3. {deleted, id123}
Update app state 1. {inserted, id123, “Buy milk”} 2. {completed,
id123} 3. {deleted, id123}
Update app state 1. {inserted, id123, “Buy milk”} 2. {completed,
id123} 3. {deleted, id123}
Update app state 1. {inserted, id123, “Buy milk”} 2. {completed,
id123} 3. {deleted, id123}
Syncing • Server: maintain an event queue = the source
of truth • Clients: upload local events to server, download unseen events, and then update the app state. • That’s it!
Syncing A B C A B C D E F
Client Server F D E
Syncing A B C A B C D E F
Client Server F D E
Syncing A B C A B C D E F
Client Server F D E
Conflicts handling • Pick the latest value by update time
• Pick the value with the largest update count • Use vector clocks to detect conflicts
Demo
Q&A