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
フロントエンド開発のためのブラウザ組み込みAI入門
masashi
7
3.4k
オープンソースソフトウェアへの解像度🔬
utam0k
17
3.1k
エンジニアインターン「Treasure」とHonoの2年、そして未来へ / Our Journey with Hono Two Years at Treasure and Beyond
carta_engineering
0
400
O Que É e Como Funciona o PHP-FPM?
marcelgsantos
0
180
実践Claude Code:20の失敗から学ぶAIペアプログラミング
takedatakashi
16
6.6k
あなたとKaigi on Rails / Kaigi on Rails + You
shimoju
0
180
AI Agent 時代的開發者生存指南
eddie
4
2.1k
Devvox Belgium - Agentic AI Patterns
kdubois
1
140
はじめてのDSPy - 言語モデルを『プロンプト』ではなく『プログラミング』するための仕組み
masahiro_nishimi
3
11k
CSC305 Lecture 09
javiergs
PRO
0
300
Server Side Kotlin Meetup vol.16: 内部動作を理解して ハイパフォーマンスなサーバサイド Kotlin アプリケーションを書こう
ternbusty
3
230
Android16 Migration Stories ~Building a Pattern for Android OS upgrades~
reoandroider
0
130
Featured
See All Featured
For a Future-Friendly Web
brad_frost
180
10k
4 Signs Your Business is Dying
shpigford
185
22k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.6k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Faster Mobile Websites
deanohume
310
31k
Six Lessons from altMBA
skipperchong
29
4k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.5k
Imperfection Machines: The Place of Print at Facebook
scottboms
269
13k
Why Our Code Smells
bkeepers
PRO
340
57k
Designing for humans not robots
tammielis
254
26k
How STYLIGHT went responsive
nonsquared
100
5.8k
Code Review Best Practice
trishagee
72
19k
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