Today mobile apps are everywhere. These apps cannot count on a reliable and constant internet connection: working in offline mode is becoming a common pattern. This is quite easy for read-only apps but it becomes rapidly tricky for apps that create data in offline mode. This talk is a case study about a possible architecture for enabling data synchronization in these situations. Some of the topics touched will be:
- id generation
- hierarchical data
- managing differente data types
- sync algorithm
7. Brownfield project
several mobile apps for tracking user generated
data (calendar, notes, bio data)
iOS & Android
~10 K users steadily growing at 1.2 K/month
Scenario
9. For every resource
get updates:
POST /m/:app/get/:user_id/:res/:updated_from
create/send updates:
POST /m/:app/update/:user_id/:res_id/:dev_id/:res
Scenario
15. Not Invented Here?
Don't Reinvent The Wheel,
UnlessYou Plan on Learning More About Wheels
J. Atwood
16. 2 different mobile platforms
Several teams with different skill level
Changing storage wasn’t an option
Forcing a particular technology client side wasn’t
an option
Architecture
39. How do we generate an unique id in a distributed
system?
unique identifiers
40. How do we generate an unique id in a distributed
system?
UUID (RFC 4122): several implementations in PHP
(https://github.com/ramsey/uuid)
unique identifiers
41. How do we generate an unique id in a distributed
system?
Local/Global Id: only the server generates GUIDs
clients use local ids to manage their records
unique identifiers
68. e.g.“only one temperature can be registered in a
given day”
how to we enforce domain constraints on data?
enforcing domain constraints
69. e.g.“only one temperature can be registered in a
given day”
how to we enforce domain constraints on data?
1) relax constraints
enforcing domain constraints
70. e.g.“only one temperature can be registered in a
given day”
how to we enforce domain constraints on data?
1) relax constraints
2) integrate constraints in sync algorithm
enforcing domain constraints
71. from findByGuid to findSimilar
first lookup by GUID then by domain rules
“two measures are similar if are referred to the
same date”
enforcing domain constraints
83. Conflict-free Replicated Data Types (CRDTs)
Constraining the types of operations in order to:
- ensure convergence of changes to shared data by
uncoordinated, concurrent actors
- eliminate network failure modes as a source of
error
CRDT
84. Gateways handles sync
Data flows through channels
- partition data set
- authorization
- limit the data
Use revision trees
Couchbase Mobile