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
チームの境界をブチ抜いていけ
tokai235
0
220
Claude CodeによるAI駆動開発の実践 〜そこから見えてきたこれからのプログラミング〜
iriikeita
0
320
スマホから Youtube Shortsを見られないようにする
lemolatoon
27
34k
GC25 Recap: The Code You Reviewed is Not the Code You Built / #newt_gophercon_tour
mazrean
0
110
pnpm に provenance のダウングレード を検出する PR を出してみた
ryo_manba
1
150
Six and a half ridiculous things to do with Quarkus
hollycummins
0
210
The Past, Present, and Future of Enterprise Java
ivargrimstad
0
600
Catch Up: Go Style Guide Update
andpad
0
250
オープンソースソフトウェアへの解像度🔬
utam0k
17
3.1k
NIKKEI Tech Talk#38
cipepser
0
190
ソフトウェア設計の実践的な考え方
masuda220
PRO
4
640
Goで実践するドメイン駆動開発 AIと歩み始めた新規プロダクト開発の現在地
imkaoru
4
890
Featured
See All Featured
Balancing Empowerment & Direction
lara
5
700
Stop Working from a Prison Cell
hatefulcrawdad
272
21k
GitHub's CSS Performance
jonrohan
1032
470k
Rebuilding a faster, lazier Slack
samanthasiow
84
9.2k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
990
Being A Developer After 40
akosma
91
590k
Visualization
eitanlees
149
16k
4 Signs Your Business is Dying
shpigford
185
22k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.2k
Raft: Consensus for Rubyists
vanstee
140
7.2k
Automating Front-end Workflow
addyosmani
1371
200k
For a Future-Friendly Web
brad_frost
180
10k
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