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
470
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
43
Other Decks in Programming
See All in Programming
中級グラフィックス入門~効率的なメッシュレット描画~
projectasura
4
2.6k
decksh - a little language for decks
ajstarks
4
21k
SwiftでMCPサーバーを作ろう!
giginet
PRO
2
230
変化を楽しむエンジニアリング ~ いままでとこれから ~
murajun1978
0
710
What's new in Adaptive Android development
fornewid
0
140
新しいモバイルアプリ勉強会(仮)について
uetyo
1
250
11年かかって やっとVibe Codingに 時代が追いつきましたね
yimajo
1
260
CLI ツールを Go ライブラリ として再実装する理由 / Why reimplement a CLI tool as a Go library
ktr_0731
3
1.1k
なぜあなたのオブザーバビリティ導入は頓挫するのか
ryota_hnk
5
590
新世界の理解
koriym
0
130
あなたとJIT, 今すぐアセンブ ル
sisshiki1969
1
610
JetBrainsのAI機能の紹介 #jjug
yusuke
0
200
Featured
See All Featured
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
44
2.4k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
Statistics for Hackers
jakevdp
799
220k
The Cost Of JavaScript in 2023
addyosmani
51
8.8k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
139
34k
A designer walks into a library…
pauljervisheath
207
24k
Become a Pro
speakerdeck
PRO
29
5.5k
Faster Mobile Websites
deanohume
308
31k
Speed Design
sergeychernyshev
32
1.1k
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3.4k
[RailsConf 2023] Rails as a piece of cake
palkan
56
5.8k
How GitHub (no longer) Works
holman
314
140k
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