oday 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
9. Brownfield project
Scenario
several mobile apps for tracking user generated
data (calendar, notes, bio data)
iOS & Android
~10 K users steadily growing at 1.2 K/month
10. MongoDB
Scenario
Legacy App based on Codeigniter
Existing RPC-wannabe-REST API for data sync
11. For every resource
get updates:
Scenario
POST /m/:app/get/:user_id/:res/:updated_from
send updates:
POST /m/:app/update/:user_id/:res_id/:dev_id/:res
17. Not Invented Here?
Don't Reinvent The Wheel,
Unless You Plan on Learning More About Wheels
J. Atwood
18. Architecture
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
47. what to transfer
we choose to transfer states
{id: ‘1’, ’type’: ‘measure’, ‘_deleted’: true}
{id: 2’, ‘type’: ‘note’}
{id: ‘3’, ‘type’: ‘note’}
ps: soft delete all the things!
49. unique identifiers
How do we generate an unique id in a distributed
system?
UUID (RFC 4122): several implementations in PHP
(https://github.com/ramsey/uuid)
50. unique identifiers
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
77. enforcing domain constraints
e.g. “only one temperature can be registered in a
given day”
how to we enforce domain constraints on data?
78. enforcing domain constraints
e.g. “only one temperature can be registered in a
given day”
how to we enforce domain constraints on data?
1) relax constraints
79. enforcing domain constraints
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
80. enforcing domain constraints
from findByGuid to findSimilar
first lookup by GUID then by domain rules
“two measures are similar if are referred to the
same date”
93. CRDT
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
94. Couchbase Mobile
Gateways handles sync
Data flows through channels
- partition data set
- authorization
- limit the data
Use revision trees
95. Riak
Distributed DB
Eventually/Strong Consistency
Data Types
Configurable conflict resolution
- db level for built-in data types
- application level for custom
data
96. That’s all folks!
Questions?
Please leave feedback! https://joind.in/12959