Sync or Swim:
The Challenge of Complex Offline
Apps
Technical Webinar
Sync or Swim
The Challenge of Complex Offline Apps
With Bruno Martinho from OutSystems FE & Mobile
February 14th
2PM (GMT) / 9AM (EDT) / 10PM (SGT)
goo.gl/NsIsq7 Ricardo Ferreira
R & D
@ OutSystems
So...
• You have decided to develop offline apps
• You are aware that things might get complicated
• You know that now is time to “Sync or Swim”
5
BE PREPARED...
Design Offline-First
How Would Your App Work Without Internet Connection?
6
Design Offline-First
7
Features
• What?
• When?
• How?
“Measure twice, cut once”
Data
Synchronization:
What?
8
“Measure twice, cut once”
Data
● Define the subset of data necessary in the device
○ Scope
○ Range
● Redefine the data structure in the device
Common Pitfalls
● Don’t blindly accept: “all data must be on device”
● Don’t blindly accept: “all data must be on device”
When?
9
“Measure twice, cut once”
Data
● Define when data should be synched with the server
○ Device to Server
○ Server to Device
● Define the frequency of each entity
Common Pitfalls
● Trying to always sync all data, even when it is not
necessary
How?
10
● No Silver Bullets
● Depends on business requirements
● Five common patterns:
○ Read-only
○ Read-only (optimized)
○ Read-write, last wins
○ Read-write, conflict resolution
○ Read-write, one-to-many
Data sync is a huge challenge on offline apps:
One of the patterns;
More than one pattern;
None of these patterns.
The solution for your own use case might be:
“Measure seven times, cut once” - Russian version
How Sync Works
Quick Overview of What We Have in OutSystems 10
11
Disclaimer: We’re Teaching You How To Fish
12
How To Set Up Offline
13
Just create a mobile app:
How To Set Up Offline
14
Data Sync Flow
15
t
trigger
sync
start
end / error
sync
sync process
asynchronous
OfflineDataSyncEvents
16
● Block that is automatically placed inside the layout
● Raise 3 events:
○ OnSyncStart - when the sync process starts
○ OnSyncComplete - when the sync process is
sucessfull
○ OnSyncError - when the sync process has an
error
Client Actions
17
● OfflineDataSyncConfiguration - allows to configure the
behavior of the sync process and trigger it automatically
in some occasions:
○ SyncOnOnline - Indicates if a sync process runs when the app is offline and
changes to online
○ SyncOnLogin - Indicates if a sync process runs when the login action is success
○ SyncOnResume - Indicates if a sync process runs when the user resumes the
application from background
○ RetryOnError - Indicated whether to retry in case of an error
○ RetryIntervalInSeconds - Indicates the interval to wait before the next retry
Client Actions
18
● OfflineDataSync - This action should have the logic to get the data from the device,
send it to the server and receive a response. With the response it may change the
local database with the server information.
● TriggerOfflineDataSync - Call this action whenever is necessary to create a manual
sync.
Common Pitfall
● When triggering manually a sync process, calling OfflineDataSync
instead of TriggerOfflineDataSync
Server Actions
19
● Use the server action to create the logic to sync information received from the
device in the server’s database
● The server action should be protected by checking if the user is authenticated. This
is a good practice for security reasons.
Sync Data Patterns
The Fantastic “Five”
20
Five Data Sync Patterns
21
● Read-Only
● Read-Only (Optimized)
● Read-Write, Last Wins
● Read-Write, Conflict Resolution
● Read-Write, One-to-Many
Unidirectional Data Flow
Bidirectional Data Flow
Five Data Sync Patterns
22
To help explaining each pattern, we are now featuring some well-known “Sink or
Swim” experts (fortunately more “swim” than “sink”)
Robinson Crusoe Chuck Noland Jack Sparrow not Titanic Jack...
Five Data Sync Patterns
23
The OutSystems Forge has an app with a collection of offline data synchronization
patterns that we will use during this webinar
Read-Only Data
24
Recommended for mobile apps where end users only need to read data while the
apps are offline and the amount of data is small.
● Local database doesn’t send data to the server
● Server data is Master
● For example, a Product Catalog App
● Has an accelerator in OutSystems Service Studio:
Sync Data A
Read-Only Data
25
ID Name
1 Robinson Crusoe
2 Chuck Noland
ID Name
1 Robinson Crusoe
2 Chuck Noland
3 Jack Sparrow
1. Get data from server
2. Delete all data from local device
3. Write all data received from server
1 Robinson Crusoe
2 Chuck Noland
3 Jack Sparrow
Read-Only Data
26
1. Get data from server 1
Read-Only Data
27
1. Get data from server
2. Delete all data from local device
2
Read-Only Data
28
1. Get data from server
2. Delete all data from local device
3. Write all data received from server
3
Read-Only Data (Optimized)
29
Recommended for mobile apps where end users only need to read data while the
apps are offline and the amount of data is small.
● Local database only sends timestamp to the server
● Server data is master
● Downloads less information from server
Sync Data
ALast Sync Date
Server entity data model:
● Last update date
● Soft delete field
Read-Only Data (optimized)
30
ID Name
1 Crusoe
2 Chuck Noland
3 Jack Sparrow
ID Name Modified Active
1 Robinson Today True
2 Chuck Noland 1 week True
3 Jack Sparrow Today False
Read-Only Data (optimized)
31
ID Name
1 Crusoe
2 Chuck Noland
3 Jack Sparrow
ID Name Modified Active
1 Robinson Today True
2 Chuck Noland 1 week True
3 Jack Sparrow Today False
1. Get device last sync date
Yesterday
Read-Only Data (optimized)
32
ID Name
1 Crusoe
2 Chuck Noland
3 Jack Sparrow
ID Name Modified Active
1 Robinson Today True
2 Chuck Noland 1 week True
3 Jack Sparrow Today False
1. Get device last sync date
Yesterday
2. Get modified and deleted in server
since last sync date UPDATED
DELETED
Read-Only Data (optimized)
33
ID Name
1 Robinson
2 Chuck Noland
3 Jack Sparrow
ID Name Modified Active
1 Robinson Today True
2 Chuck Noland 1 week True
3 Jack Sparrow Today False
1. Get device last sync date
Yesterday
2. Get modified and deleted in server
since last sync date UPDATED
DELETED
3. Insert or update modified in device
Read-Only Data (optimized)
34
ID Name
1 Robinson
2 Chuck Noland
3 Jack Sparrow
ID Name Modified Active
1 Robinson Today True
2 Chuck Noland 1 week True
3 Jack Sparrow Today False
1. Get device last sync date
Yesterday
2. Get modified and deleted in server
since last sync date UPDATED
DELETED
3. Insert or update modified in device
4. Delete in device the deleted rows in
the server
Read-Only Data (optimized)
35
ID Name
1 Robinson
2 Chuck Noland
3 Jack Sparrow
ID Name Modified Active
1 Robinson Today True
2 Chuck Noland 1 week True
3 Jack Sparrow Today False
1. Get device last sync date
2. Get modified and deleted in server
since last sync date UPDATED
DELETED
3. Insert or update modified in device
5. Update last sync date
Now
4. Delete in device the deleted rows in
the server
Read-Only Data (optimized)
36
1. Get device last sync date
1
Read-Only Data (optimized)
37
2. Get modified and deleted in server
since last sync date
1. Get device last sync date
2
Read-Only Data (optimized)
38
2. Get modified and deleted in server
since last sync date
1. Get device last sync date
33. Insert or update modified in device
Read-Only Data (optimized)
39
2. Get modified and deleted in server
since last sync date
1. Get device last sync date
4
3. Insert or update modified in device
4. Delete in device the deleted rows in
the server
Read-Only Data (optimized)
40
2. Get modified and deleted in server
since last sync date
1. Get device last sync date
3. Insert or update modified in device
5. Update last sync date
5
4. Delete in device the deleted rows in
the server
Read-Write, Last Wins
41
Recommended for mobile apps where it is not likely for multiple end users to change
the same data while the apps are offline.
● Local database change and sends data to the server
● Data in server is always overridable
● E.g., a Field Services App
● Has an accelerator in Service Studio:
A
A
1
A1
A
A2
A => A1 => A2
Read-Write, Last Wins
42
ID Name
1 Crusoe
2 Chuck Noland
ID Name Server Modified Active
1 Robinson True True True
2 Chuck Noland True False False
3 Jack Sparrow False True True
Read-Write, Last Wins
43
ID Name
1 Crusoe
2 Chuck Noland
ID Name Server Modified Active
1 Robinson True True True
2 Chuck Noland True False False
3 Jack Sparrow False True True
1. Check local data for new, updated
and deleted
UPDATED
DELETE
NEW
Read-Write, Last Wins
44
ID Name
1 Robinson
2 Chuck Noland
3 Jack Sparrow
ID Name Server Modified Active
1 Robinson True True True
2 Chuck Noland True False False
3 Jack Sparrow False True True
2. On server, create, update and delete
data
1. Check local data for new, updated
and deleted
UPDATED
DELETE
NEW
Read-Write, Last Wins
45
ID Name
1 Robinson
3 Jack Sparrow
ID Name Server Modified Active
1 Robinson True True True
2 Chuck Noland True False False
3 Jack Sparrow False True True
2. On server, create, update and delete
data
1. Check local data for new, updated
and deleted
UPDATED
DELETE
NEW
3. Get all data from server
Read-Write, Last Wins
46
ID Name
1 Robinson
3 Jack Sparrow
ID Name Server Modified Active
1 Robinson True True True
2 Chuck Noland True False False
3 Jack Sparrow False True True
2. On server, create, update and delete
data
1. Check local data for new, updated
and deleted
3. Get all data from server
4. Delete all data in device
Read-Write, Last Wins
47
ID Name
1 Robinson
3 Jack Sparrow
ID Name Server Modified Active
1 Robinson True True True
2 Chuck Noland True False False
3 Jack Sparrow False True True
2. On server, create, update and delete
data
1. Check local data for new, updated
and deleted
3. Get all data from server
4. Delete all data in device
5. Write all data from server in the
device
1 Robinson True False True
3 Jack Sparrow True False True
Read-Write, Last Wins
48
1. Check local data for new, updated
and deleted
1
Read-Write, Last Wins
49
2. On server, create, update and delete
data
1. Check local data for new, updated
and deleted
2
Read-Write, Last Wins
50
2. On server, create, update and delete
data
1. Check local data for new, updated
and deleted
3. Get all data from server
3
Read-Write, Last Wins
51
2. On server, create, update and delete
data
1. Check local data for new, updated
and deleted
3. Get all data from server
4. Delete all data in device
4
Read-Write, Last Wins
52
2. On server, create, update and delete
data
1. Check local data for new, updated
and deleted
3. Get all data from server
4. Delete all data in device
5. Write all data from server in the
device
5
Read-Write with Conflict Detection
53
Recommended for advanced scenarios where multiple end-users will change the
same data while the apps are offline
● Local database change and sends data to the server
● Data in server has conflict and need to be resolved
● E.g Field Services App with collaboration
● New an entity in device to store conflicts
A
A
1
A1
A
A2
A => A1 ???
A2 ???
Server entity data model:
● Last update date
● Soft delete field
Read-Write with Conflict Detection
54
ID Name Server Modified Active
1 Robinson True True True
2 Chuck Noland True False False
3 Jack Sparrow False True True
ID Name Modified Active
1 Crusoe Yesterday True
2 Chuck Noland 1 year True
1. Only allow sync if no data in device is
marked as conflict
Read-Write with Conflict Detection
55
ID Name Server Modified Active
1 Robinson True True True
2 Chuck Noland True False False
3 Jack Sparrow False True True
ID Name Modified Active
1 Crusoe Yesterday True
2 Chuck Noland 1 year True
1. Only allow sync if no data in device is
marked as conflict
2. Get last sync date from device
1 Month
Read-Write with Conflict Detection
56
ID Name Server Modified Active
1 Robinson True True True
2 Chuck Noland True False False
3 Jack Sparrow False True True
ID Name Modified Active
1 Crusoe Yesterday True
2 Chuck Noland 1 year True
1. Only allow sync if no data in device is
marked as conflict
2. Get last sync date from device
1 Month
3. Get local device data for new, update
and delete UPDATED
DELETE
NEW
Read-Write with Conflict Detection
57
ID Name Server Modified Active
1 Robinson True True True
2 Chuck Noland True False False
3 Jack Sparrow False True True
ID Name Modified Active
1 Crusoe Yesterday True
2 Chuck Noland 1 year True
3 Jack Sparrow Now True
1. Only allow sync if no data in device is
marked as conflict
2. Get last sync date from device
1 Month
3. Get local device data for new, update
and delete UPDATED
DELETE
NEW
4. On server, create new data
Read-Write with Conflict Detection
58
ID Name Server Modified Active
1 Robinson True True True
2 Chuck Noland True False False
3 Jack Sparrow False True True
ID Name Modified Active
1 Crusoe Yesterday True
2 Chuck Noland 1 year True
3 Jack Sparrow Now True
1. Only allow sync if no data in device is
marked as conflict
2. Get last sync date from device
1 Month
3. Get local device data for new, update
and delete UPDATED
DELETE
NEW
4. On server, create new data
5. Update rows with modified date
before last sync. Others will be marked
as conflict
Read-Write with Conflict Detection
59
ID Name Server Modified Active
1 Robinson True True True
2 Chuck Noland True False False
3 Jack Sparrow False True True
ID Name Modified Active
1 Crusoe Yesterday True
2 Chuck Noland 1 year True
3 Jack Sparrow Now True
1. Only allow sync if no data in device is
marked as conflict
2. Get last sync date from device
1 Month
3. Get local device data for new, update
and delete UPDATED
DELETE
NEW
4. On server, create new data
5. Update rows with modified date
before last sync. Others will be marked
as conflict
6. Delete rows with modified date
before last sync. Others will be marked
as conflict
Read-Write with Conflict Detection
60
ID Name Server Modified Active
1 Robinson True True True
2 Chuck Noland True False False
3 Jack Sparrow False True True
ID Name Modified Active
1 Crusoe Yesterday True
2 Chuck Noland 1 year True
3 Jack Sparrow Now True
7. Return from server last sync date and
two lists, conflicts and no-conflicts
1 Month
UPDATED
DELETE
NEW
N
ow
Read-Write with Conflict Detection
61
ID Name Server Modified Active
1 Robinson True True True
2 Chuck Noland True False False
3 Jack Sparrow False True True
ID Name Modified Active
1 Crusoe Yesterday True
2 Chuck Noland 1 year True
3 Jack Sparrow Now True
7. Return from server last sync date and
two lists, conflicts and no-conflicts
8. Add the ones with conflict to the
conflict table
1 Month
UPDATED
DELETE
NEW
N
ow
ID Name
1 Crusoe
Conflict
9. Delete data from local
Read-Write with Conflict Detection
62
ID Name Server Modified Active
1 Robinson True True True
2 Chuck Noland True False False
3 Jack Sparrow False True True
ID Name Modified Active
1 Crusoe Yesterday True
2 Chuck Noland 1 year True
3 Jack Sparrow Now True
7. Return from server last sync date and
two lists, conflicts and no-conflicts
8. Add the ones with conflict to the
conflict table
1 Month
Now
N
ow
ID Name
1 Crusoe
Conflict
9. Delete data from local
Read-Write with Conflict Detection
63
ID Name Server Modified Active
1 Robinson True True True
2 Chuck Noland True False False
3 Jack Sparrow False True True
ID Name Modified Active
1 Crusoe Yesterday True
2 Chuck Noland 1 year True
3 Jack Sparrow Now True
7. Return from server last sync date and
two lists, conflicts and no-conflicts
8. Add the ones with conflict to the
conflict table
1 Month
10. Write data on the device received
from server, except for conflict. With
conflicts keep the local data
ID Name
1 Crusoe
Conflict
1 Robinson True True True
3 Jack Sparrow True False True
9. Delete data from local
Read-Write with Conflict Detection
64
ID Name Server Modified Active
1 Robinson True True True
2 Chuck Noland True False False
3 Jack Sparrow False True True
ID Name Modified Active
1 Crusoe Yesterday True
2 Chuck Noland 1 year True
3 Jack Sparrow Now True
7. Return from server last sync date and
two lists, conflicts and no-conflicts
8. Add the ones with conflict to the
conflict table
Now
10. Write data on the device received
from server, except for conflict. With
conflicts keep the local data
11. Update last sync date
ID Name
1 Crusoe
Conflict
1 Robinson True True True
3 Jack Sparrow True False True
9. Delete data from local
Read-Write with Conflict Detection
65
ID Name Server Modified Active
1 Robinson True True True
2 Chuck Noland True False False
3 Jack Sparrow False True True
ID Name Modified Active
1 Crusoe Yesterday True
2 Chuck Noland 1 year True
3 Jack Sparrow Now True
7. Return from server last sync date and
two lists, conflicts and no-conflicts
8. Add the ones with conflict to the
conflict table
Now
10. Write data on the device received
from server, except for conflict. With
conflicts keep the local data
11. Update last sync date
ID Name
1 Crusoe
Conflict
1 Robinson True True True
3 Jack Sparrow True False True
12. Show conflicts to solve
DEMO
Conflict Detection
Read-Write with Conflict Detection
67
1
1. Only allow sync if no data in device is
marked as conflict
Read-Write with Conflict Detection
68
1. Only allow sync if no data in device is
marked as conflict
2. Get last sync date from device
2
Read-Write with Conflict Detection
69
1. Only allow sync if no data in device is
marked as conflict
2. Get last sync date from device
3. Get local device data for new, update
and delete
3
Read-Write with Conflict Detection
70
4
1. Only allow sync if no data in device is
marked as conflict
2. Get last sync date from device
3. Get local device data for new, update
and delete
4. On server, create new data
Read-Write with Conflict Detection
71
5
1. Only allow sync if no data in device is
marked as conflict
2. Get last sync date from device
3. Get local device data for new, update
and delete
4. On server, create new data
5. Update rows with modified date
before last sync. Others will be marked
as conflict
Read-Write with Conflict Detection
72
6
1. Only allow sync if no data in device is
marked as conflict
2. Get last sync date from device
3. Get local device data for new, update
and delete
4. On server, create new data
5. Update rows with modified date
before last sync. Others will be marked
as conflict
6. Delete rows with modified date
before last sync. Others will be marked
as conflict
Read-Write with Conflict Detection
73
7
7. Return from server last sync date and
two lists, conflicts and no-conflicts
Read-Write with Conflict Detection
74
8
7. Return from server last sync date and
two lists, conflicts and no-conflicts
8. Add the ones with conflict to the
conflict table
Read-Write with Conflict Detection
75
9. Delete data from local
7. Return from server last sync date and
two lists, conflicts and no-conflicts
8. Add the ones with conflict to the
conflict table
9
Read-Write with Conflict Detection
76
10
9. Delete data from local
7. Return from server last sync date and
two lists, conflicts and no-conflicts
8. Add the ones with conflict to the
conflict table
10. Write data on the device received
from server, except for conflict. With
conflicts keep the local data
Read-Write with Conflict Detection
77
9. Delete data from local
7. Return from server last sync date and
two lists, conflicts and no-conflicts
8. Add the ones with conflict to the
conflict table
10. Write data on the device received
from server, except for conflict. With
conflicts keep the local data
11. Update last sync date
11
Read-Write, One-to-Many Data
78
Recommended for mobile apps with entities that follow a one-to-many relationship
and where it is not likely for multiple end users to change the same data while the
apps are offline.
● Local database changes and sends data with relationships to the server.
● Data in server is always overridable.
A, B
A1, B1
ID Name Server Modified Active
1 Robinson Crusoe True False True
2 Chuck Noland False True True
3 Jack Sparrow True False True
Read-Write, One-to-Many Data
79
ID Name
1 Robinson Crusoe
2 Jack Sparrow
ID Name CastId Server Modified Active
1 Wilson 2 False True True
Friend
ID Name Server Modified Active
1 Robinson Crusoe True False True
2 Chuck Noland False True True
3 Jack Sparrow True False True
Read-Write, One-to-Many Data
80
ID Name
1 Robinson Crusoe
2 Jack Sparrow
ID Name CastId Server Modified Active
1 Wilson 2 False True True
Friend
1. Check local data on primary table for
new, updated and deleted
NEW
ID Name Server Modified Active
1 Robinson Crusoe True False True
2 Chuck Noland False True True
3 Jack Sparrow True False True
Read-Write, One-to-Many Data
81
ID Name
1 Robinson Crusoe
2 Jack Sparrow
ID Name CastId Server Modified Active
1 Wilson 2 False True True
Friend
1. Check local data on primary table for
new, updated and deleted
2. Check local data on foreign table
for new, updated and deleted
NEW
NEW
ID Name Server Modified Active
1 Robinson Crusoe True False True
2 Chuck Noland False True True
3 Jack Sparrow True False True
Read-Write, One-to-Many Data
82
ID Name
1 Robinson Crusoe
2 Jack Sparrow
3 Chuck Noland
ID Name CastId Server Modified Active
1 Wilson 2 False True True
Friend
1. Check local data on primary table for
new, updated and deleted
2. Check local data on foreign table
for new, updated and deleted
3. On server, create new data NEW
NEW
ID Name Server Modified Active
1 Robinson Crusoe True False True
2 Chuck Noland False True True
3 Jack Sparrow True False True
Read-Write, One-to-Many Data
83
ID Name
1 Robinson Crusoe
2 Jack Sparrow
3 Chuck Noland
ID Name CastId Server Modified Active
1 Wilson 2 False True True
Friend
1. Check local data on primary table for
new, updated and deleted
2. Check local data on foreign table
for new, updated and deleted
3. On server, create new data
4. Create dictionary with primary Ids
NEW
NEW
Dictionary
ID NewID
2 3
ID Name Server Modified Active
1 Robinson Crusoe True False True
2 Chuck Noland False True True
3 Jack Sparrow True False True
Read-Write, One-to-Many Data
84
ID Name
1 Robinson Crusoe
2 Jack Sparrow
3 Chuck Noland
ID Name CastId Server Modified Active
1 Wilson 2 False True True
Friend
1. Check local data on primary table for
new, updated and deleted
2. Check local data on foreign table
for new, updated and deleted
3. On server, create new data
4. Create dictionary with primary Ids
5. Update rows received from device
with the new ids in the dictionary
NEW
NEW
Dictionary
ID NewID
2 3
ID Name Server Modified Active
1 Robinson Crusoe True False True
2 Chuck Noland False True True
3 Jack Sparrow True False True
Read-Write, One-to-Many Data
85
ID Name
1 Robinson Crusoe
2 Jack Sparrow
3 Chuck Noland
ID Name CastId Server Modified Active
1 Wilson 2 False True True
Friend
6. Add, update and delete foreign entity
in the server
NEW
NEW
Dictionary
ID NewID
2 3
ID Name CastId
1 Wilson 3
ID Name Server Modified Active
1 Robinson Crusoe True False True
2 Chuck Noland False True True
3 Jack Sparrow True False True
Read-Write, One-to-Many Data
86
ID Name
1 Robinson Crusoe
2 Jack Sparrow
3 Chuck Noland
ID Name CastId Server Modified Active
1 Wilson 2 False True True
Friend
6. Add, update and delete foreign entity
in the server
7. Send both entities to the device
NEW
NEW
ID Name CastId
1 Wilson 3
ID Name Server Modified Active
1 Robinson Crusoe True False True
2 Chuck Noland False True True
3 Jack Sparrow True False True
Read-Write, One-to-Many Data
87
ID Name
1 Robinson Crusoe
2 Jack Sparrow
3 Chuck Noland
ID Name CastId Server Modified Active
1 Wilson 2 False True True
Friend
6. Add, update and delete foreign entity
in the server
7. Send both entities to the device
8. Delete the foreign entity in the
device
NEW
ID Name CastId
1 Wilson 3
ID Name Server Modified Active
1 Robinson Crusoe True False True
2 Chuck Noland False True True
3 Jack Sparrow True False True
Read-Write, One-to-Many Data
88
ID Name
1 Robinson Crusoe
2 Jack Sparrow
3 Chuck Noland
ID Name CastId Server Modified Active
1 Wilson 2 False True True
Friend
6. Add, update and delete foreign entity
in the server
7. Send both entities to the device
8. Delete the foreign entity in the
device
9. Delete the primary entity in the
device ID Name CastId
1 Wilson 3
ID Name Server Modified Active
1 Robinson Crusoe True False True
2 Chuck Noland False True True
3 Jack Sparrow True False True
Read-Write, One-to-Many Data
89
ID Name
1 Robinson Crusoe
2 Jack Sparrow
3 Chuck Noland
ID Name CastId Server Modified Active
1 Wilson 2 False True True
Friend
6. Add, update and delete foreign entity
in the server
7. Send both entities to the device
8. Delete the foreign entity in the
device
9. Delete the primary entity in the
device
10. Add all data for primary entity
received from the server
ID Name CastId
1 Wilson 3
1 Robinson Crusoe True False True
2 Jack Sparrow True False True
3 Chuck Noland True False True
ID Name Server Modified Active
1 Robinson Crusoe True False True
2 Chuck Noland False True True
3 Jack Sparrow True False True
Read-Write, One-to-Many Data
90
ID Name
1 Robinson Crusoe
2 Jack Sparrow
3 Chuck Noland
ID Name CastId Server Modified Active
1 Wilson 2 False True True
Friend
6. Add, update and delete foreign entity
in the server
7. Send both entities to the device
8. Delete the foreign entity in the
device
9. Delete the primary entity in the
device
10. Add all data for primary entity
received from the server
ID Name CastId
1 Wilson 3
1 Robinson Crusoe True False True
2 Jack Sparrow True False True
3 Chuck Noland True False True
11. Add all data for foreign entity
received from the server
1 Wilson 3 True False True
Read-Write, One-to-Many Data
91
1
1. Check local data on primary table for
new, updated and deleted
Read-Write, One-to-Many Data
92
2
1. Check local data on primary table for
new, updated and deleted
2. Check local data on foreign table
for new, updated and deleted
Read-Write, One-to-Many Data
93
3
1. Check local data on primary table for
new, updated and deleted
2. Check local data on foreign table
for new, updated and deleted
3. On server, create new data
Read-Write, One-to-Many Data
94
1. Check local data on primary table for
new, updated and deleted
2. Check local data on foreign table
for new, updated and deleted
3. On server, create new data
4. Create dictionary with primary Ids
4
Read-Write, One-to-Many Data
95
1. Check local data on primary table for
new, updated and deleted
2. Check local data on foreign table
for new, updated and deleted
3. On server, create new data
4. Create dictionary with primary Ids
5. Update rows received from device
with the new ids in the dictionary
5
Read-Write, One-to-Many Data
96
6. Add, update and delete foreign entity
in the server
3
Read-Write, One-to-Many Data
97
7
6. Add, update and delete foreign entity
in the server
7. Send both entities to the device
Read-Write, One-to-Many Data
98
8,10
6. Add, update and delete foreign entity
in the server
7. Send both entities to the device
8. Delete the foreign entity in the
device
9. Delete the primary entity in the
device
10. Add all data for primary entity
received from the server
Read-Write, One-to-Many Data
99
9,11
6. Add, update and delete foreign entity
in the server
7. Send both entities to the device
8. Delete the foreign entity in the
device
9. Delete the primary entity in the
device
10. Add all data for primary entity
received from the server
11. Add all data for foreign entity
received from the server
Summary
• Mobile Apps need offline support to deliver the best user experience.
• Design Offline-First:
○ What features or capabilities should be available offline?
○ What data do you need to store in the device database?
○ When should the data be synchronized?
○ How will you handle data in the device?
• OutSystems 10 makes building Offline Apps a walk in the park:
○ Easy offline data manipulation.
○ Out-of-the-box data synchronization patterns.
10
0
Further reading
Further Reading
10
2
https://goo.gl/40Qc3I
Further Reading
10
3
https://goo.gl/ovqUAX
Links
Links
• Offline Data Synchronization Patterns samples https://goo.gl/ISDsgf
• Offline Data Synchronization Patterns documentation https://goo.gl/By3xNH
• Ciphered Local Storage Plugin https://goo.gl/Tj02P0
10
5
Thank you!
www.outsystems.com10
7

Sync or swim: the challenge of complex offline apps

  • 1.
    Sync or Swim: TheChallenge of Complex Offline Apps
  • 2.
    Technical Webinar Sync orSwim The Challenge of Complex Offline Apps With Bruno Martinho from OutSystems FE & Mobile February 14th 2PM (GMT) / 9AM (EDT) / 10PM (SGT)
  • 4.
  • 5.
    So... • You havedecided to develop offline apps • You are aware that things might get complicated • You know that now is time to “Sync or Swim” 5 BE PREPARED...
  • 6.
    Design Offline-First How WouldYour App Work Without Internet Connection? 6
  • 7.
    Design Offline-First 7 Features • What? •When? • How? “Measure twice, cut once” Data Synchronization:
  • 8.
    What? 8 “Measure twice, cutonce” Data ● Define the subset of data necessary in the device ○ Scope ○ Range ● Redefine the data structure in the device Common Pitfalls ● Don’t blindly accept: “all data must be on device” ● Don’t blindly accept: “all data must be on device”
  • 9.
    When? 9 “Measure twice, cutonce” Data ● Define when data should be synched with the server ○ Device to Server ○ Server to Device ● Define the frequency of each entity Common Pitfalls ● Trying to always sync all data, even when it is not necessary
  • 10.
    How? 10 ● No SilverBullets ● Depends on business requirements ● Five common patterns: ○ Read-only ○ Read-only (optimized) ○ Read-write, last wins ○ Read-write, conflict resolution ○ Read-write, one-to-many Data sync is a huge challenge on offline apps: One of the patterns; More than one pattern; None of these patterns. The solution for your own use case might be: “Measure seven times, cut once” - Russian version
  • 11.
    How Sync Works QuickOverview of What We Have in OutSystems 10 11
  • 12.
    Disclaimer: We’re TeachingYou How To Fish 12
  • 13.
    How To SetUp Offline 13 Just create a mobile app:
  • 14.
    How To SetUp Offline 14
  • 15.
    Data Sync Flow 15 t trigger sync start end/ error sync sync process asynchronous
  • 16.
    OfflineDataSyncEvents 16 ● Block thatis automatically placed inside the layout ● Raise 3 events: ○ OnSyncStart - when the sync process starts ○ OnSyncComplete - when the sync process is sucessfull ○ OnSyncError - when the sync process has an error
  • 17.
    Client Actions 17 ● OfflineDataSyncConfiguration- allows to configure the behavior of the sync process and trigger it automatically in some occasions: ○ SyncOnOnline - Indicates if a sync process runs when the app is offline and changes to online ○ SyncOnLogin - Indicates if a sync process runs when the login action is success ○ SyncOnResume - Indicates if a sync process runs when the user resumes the application from background ○ RetryOnError - Indicated whether to retry in case of an error ○ RetryIntervalInSeconds - Indicates the interval to wait before the next retry
  • 18.
    Client Actions 18 ● OfflineDataSync- This action should have the logic to get the data from the device, send it to the server and receive a response. With the response it may change the local database with the server information. ● TriggerOfflineDataSync - Call this action whenever is necessary to create a manual sync. Common Pitfall ● When triggering manually a sync process, calling OfflineDataSync instead of TriggerOfflineDataSync
  • 19.
    Server Actions 19 ● Usethe server action to create the logic to sync information received from the device in the server’s database ● The server action should be protected by checking if the user is authenticated. This is a good practice for security reasons.
  • 20.
    Sync Data Patterns TheFantastic “Five” 20
  • 21.
    Five Data SyncPatterns 21 ● Read-Only ● Read-Only (Optimized) ● Read-Write, Last Wins ● Read-Write, Conflict Resolution ● Read-Write, One-to-Many Unidirectional Data Flow Bidirectional Data Flow
  • 22.
    Five Data SyncPatterns 22 To help explaining each pattern, we are now featuring some well-known “Sink or Swim” experts (fortunately more “swim” than “sink”) Robinson Crusoe Chuck Noland Jack Sparrow not Titanic Jack...
  • 23.
    Five Data SyncPatterns 23 The OutSystems Forge has an app with a collection of offline data synchronization patterns that we will use during this webinar
  • 24.
    Read-Only Data 24 Recommended formobile apps where end users only need to read data while the apps are offline and the amount of data is small. ● Local database doesn’t send data to the server ● Server data is Master ● For example, a Product Catalog App ● Has an accelerator in OutSystems Service Studio: Sync Data A
  • 25.
    Read-Only Data 25 ID Name 1Robinson Crusoe 2 Chuck Noland ID Name 1 Robinson Crusoe 2 Chuck Noland 3 Jack Sparrow 1. Get data from server 2. Delete all data from local device 3. Write all data received from server 1 Robinson Crusoe 2 Chuck Noland 3 Jack Sparrow
  • 26.
    Read-Only Data 26 1. Getdata from server 1
  • 27.
    Read-Only Data 27 1. Getdata from server 2. Delete all data from local device 2
  • 28.
    Read-Only Data 28 1. Getdata from server 2. Delete all data from local device 3. Write all data received from server 3
  • 29.
    Read-Only Data (Optimized) 29 Recommendedfor mobile apps where end users only need to read data while the apps are offline and the amount of data is small. ● Local database only sends timestamp to the server ● Server data is master ● Downloads less information from server Sync Data ALast Sync Date Server entity data model: ● Last update date ● Soft delete field
  • 30.
    Read-Only Data (optimized) 30 IDName 1 Crusoe 2 Chuck Noland 3 Jack Sparrow ID Name Modified Active 1 Robinson Today True 2 Chuck Noland 1 week True 3 Jack Sparrow Today False
  • 31.
    Read-Only Data (optimized) 31 IDName 1 Crusoe 2 Chuck Noland 3 Jack Sparrow ID Name Modified Active 1 Robinson Today True 2 Chuck Noland 1 week True 3 Jack Sparrow Today False 1. Get device last sync date Yesterday
  • 32.
    Read-Only Data (optimized) 32 IDName 1 Crusoe 2 Chuck Noland 3 Jack Sparrow ID Name Modified Active 1 Robinson Today True 2 Chuck Noland 1 week True 3 Jack Sparrow Today False 1. Get device last sync date Yesterday 2. Get modified and deleted in server since last sync date UPDATED DELETED
  • 33.
    Read-Only Data (optimized) 33 IDName 1 Robinson 2 Chuck Noland 3 Jack Sparrow ID Name Modified Active 1 Robinson Today True 2 Chuck Noland 1 week True 3 Jack Sparrow Today False 1. Get device last sync date Yesterday 2. Get modified and deleted in server since last sync date UPDATED DELETED 3. Insert or update modified in device
  • 34.
    Read-Only Data (optimized) 34 IDName 1 Robinson 2 Chuck Noland 3 Jack Sparrow ID Name Modified Active 1 Robinson Today True 2 Chuck Noland 1 week True 3 Jack Sparrow Today False 1. Get device last sync date Yesterday 2. Get modified and deleted in server since last sync date UPDATED DELETED 3. Insert or update modified in device 4. Delete in device the deleted rows in the server
  • 35.
    Read-Only Data (optimized) 35 IDName 1 Robinson 2 Chuck Noland 3 Jack Sparrow ID Name Modified Active 1 Robinson Today True 2 Chuck Noland 1 week True 3 Jack Sparrow Today False 1. Get device last sync date 2. Get modified and deleted in server since last sync date UPDATED DELETED 3. Insert or update modified in device 5. Update last sync date Now 4. Delete in device the deleted rows in the server
  • 36.
    Read-Only Data (optimized) 36 1.Get device last sync date 1
  • 37.
    Read-Only Data (optimized) 37 2.Get modified and deleted in server since last sync date 1. Get device last sync date 2
  • 38.
    Read-Only Data (optimized) 38 2.Get modified and deleted in server since last sync date 1. Get device last sync date 33. Insert or update modified in device
  • 39.
    Read-Only Data (optimized) 39 2.Get modified and deleted in server since last sync date 1. Get device last sync date 4 3. Insert or update modified in device 4. Delete in device the deleted rows in the server
  • 40.
    Read-Only Data (optimized) 40 2.Get modified and deleted in server since last sync date 1. Get device last sync date 3. Insert or update modified in device 5. Update last sync date 5 4. Delete in device the deleted rows in the server
  • 41.
    Read-Write, Last Wins 41 Recommendedfor mobile apps where it is not likely for multiple end users to change the same data while the apps are offline. ● Local database change and sends data to the server ● Data in server is always overridable ● E.g., a Field Services App ● Has an accelerator in Service Studio: A A 1 A1 A A2 A => A1 => A2
  • 42.
    Read-Write, Last Wins 42 IDName 1 Crusoe 2 Chuck Noland ID Name Server Modified Active 1 Robinson True True True 2 Chuck Noland True False False 3 Jack Sparrow False True True
  • 43.
    Read-Write, Last Wins 43 IDName 1 Crusoe 2 Chuck Noland ID Name Server Modified Active 1 Robinson True True True 2 Chuck Noland True False False 3 Jack Sparrow False True True 1. Check local data for new, updated and deleted UPDATED DELETE NEW
  • 44.
    Read-Write, Last Wins 44 IDName 1 Robinson 2 Chuck Noland 3 Jack Sparrow ID Name Server Modified Active 1 Robinson True True True 2 Chuck Noland True False False 3 Jack Sparrow False True True 2. On server, create, update and delete data 1. Check local data for new, updated and deleted UPDATED DELETE NEW
  • 45.
    Read-Write, Last Wins 45 IDName 1 Robinson 3 Jack Sparrow ID Name Server Modified Active 1 Robinson True True True 2 Chuck Noland True False False 3 Jack Sparrow False True True 2. On server, create, update and delete data 1. Check local data for new, updated and deleted UPDATED DELETE NEW 3. Get all data from server
  • 46.
    Read-Write, Last Wins 46 IDName 1 Robinson 3 Jack Sparrow ID Name Server Modified Active 1 Robinson True True True 2 Chuck Noland True False False 3 Jack Sparrow False True True 2. On server, create, update and delete data 1. Check local data for new, updated and deleted 3. Get all data from server 4. Delete all data in device
  • 47.
    Read-Write, Last Wins 47 IDName 1 Robinson 3 Jack Sparrow ID Name Server Modified Active 1 Robinson True True True 2 Chuck Noland True False False 3 Jack Sparrow False True True 2. On server, create, update and delete data 1. Check local data for new, updated and deleted 3. Get all data from server 4. Delete all data in device 5. Write all data from server in the device 1 Robinson True False True 3 Jack Sparrow True False True
  • 48.
    Read-Write, Last Wins 48 1.Check local data for new, updated and deleted 1
  • 49.
    Read-Write, Last Wins 49 2.On server, create, update and delete data 1. Check local data for new, updated and deleted 2
  • 50.
    Read-Write, Last Wins 50 2.On server, create, update and delete data 1. Check local data for new, updated and deleted 3. Get all data from server 3
  • 51.
    Read-Write, Last Wins 51 2.On server, create, update and delete data 1. Check local data for new, updated and deleted 3. Get all data from server 4. Delete all data in device 4
  • 52.
    Read-Write, Last Wins 52 2.On server, create, update and delete data 1. Check local data for new, updated and deleted 3. Get all data from server 4. Delete all data in device 5. Write all data from server in the device 5
  • 53.
    Read-Write with ConflictDetection 53 Recommended for advanced scenarios where multiple end-users will change the same data while the apps are offline ● Local database change and sends data to the server ● Data in server has conflict and need to be resolved ● E.g Field Services App with collaboration ● New an entity in device to store conflicts A A 1 A1 A A2 A => A1 ??? A2 ??? Server entity data model: ● Last update date ● Soft delete field
  • 54.
    Read-Write with ConflictDetection 54 ID Name Server Modified Active 1 Robinson True True True 2 Chuck Noland True False False 3 Jack Sparrow False True True ID Name Modified Active 1 Crusoe Yesterday True 2 Chuck Noland 1 year True 1. Only allow sync if no data in device is marked as conflict
  • 55.
    Read-Write with ConflictDetection 55 ID Name Server Modified Active 1 Robinson True True True 2 Chuck Noland True False False 3 Jack Sparrow False True True ID Name Modified Active 1 Crusoe Yesterday True 2 Chuck Noland 1 year True 1. Only allow sync if no data in device is marked as conflict 2. Get last sync date from device 1 Month
  • 56.
    Read-Write with ConflictDetection 56 ID Name Server Modified Active 1 Robinson True True True 2 Chuck Noland True False False 3 Jack Sparrow False True True ID Name Modified Active 1 Crusoe Yesterday True 2 Chuck Noland 1 year True 1. Only allow sync if no data in device is marked as conflict 2. Get last sync date from device 1 Month 3. Get local device data for new, update and delete UPDATED DELETE NEW
  • 57.
    Read-Write with ConflictDetection 57 ID Name Server Modified Active 1 Robinson True True True 2 Chuck Noland True False False 3 Jack Sparrow False True True ID Name Modified Active 1 Crusoe Yesterday True 2 Chuck Noland 1 year True 3 Jack Sparrow Now True 1. Only allow sync if no data in device is marked as conflict 2. Get last sync date from device 1 Month 3. Get local device data for new, update and delete UPDATED DELETE NEW 4. On server, create new data
  • 58.
    Read-Write with ConflictDetection 58 ID Name Server Modified Active 1 Robinson True True True 2 Chuck Noland True False False 3 Jack Sparrow False True True ID Name Modified Active 1 Crusoe Yesterday True 2 Chuck Noland 1 year True 3 Jack Sparrow Now True 1. Only allow sync if no data in device is marked as conflict 2. Get last sync date from device 1 Month 3. Get local device data for new, update and delete UPDATED DELETE NEW 4. On server, create new data 5. Update rows with modified date before last sync. Others will be marked as conflict
  • 59.
    Read-Write with ConflictDetection 59 ID Name Server Modified Active 1 Robinson True True True 2 Chuck Noland True False False 3 Jack Sparrow False True True ID Name Modified Active 1 Crusoe Yesterday True 2 Chuck Noland 1 year True 3 Jack Sparrow Now True 1. Only allow sync if no data in device is marked as conflict 2. Get last sync date from device 1 Month 3. Get local device data for new, update and delete UPDATED DELETE NEW 4. On server, create new data 5. Update rows with modified date before last sync. Others will be marked as conflict 6. Delete rows with modified date before last sync. Others will be marked as conflict
  • 60.
    Read-Write with ConflictDetection 60 ID Name Server Modified Active 1 Robinson True True True 2 Chuck Noland True False False 3 Jack Sparrow False True True ID Name Modified Active 1 Crusoe Yesterday True 2 Chuck Noland 1 year True 3 Jack Sparrow Now True 7. Return from server last sync date and two lists, conflicts and no-conflicts 1 Month UPDATED DELETE NEW N ow
  • 61.
    Read-Write with ConflictDetection 61 ID Name Server Modified Active 1 Robinson True True True 2 Chuck Noland True False False 3 Jack Sparrow False True True ID Name Modified Active 1 Crusoe Yesterday True 2 Chuck Noland 1 year True 3 Jack Sparrow Now True 7. Return from server last sync date and two lists, conflicts and no-conflicts 8. Add the ones with conflict to the conflict table 1 Month UPDATED DELETE NEW N ow ID Name 1 Crusoe Conflict
  • 62.
    9. Delete datafrom local Read-Write with Conflict Detection 62 ID Name Server Modified Active 1 Robinson True True True 2 Chuck Noland True False False 3 Jack Sparrow False True True ID Name Modified Active 1 Crusoe Yesterday True 2 Chuck Noland 1 year True 3 Jack Sparrow Now True 7. Return from server last sync date and two lists, conflicts and no-conflicts 8. Add the ones with conflict to the conflict table 1 Month Now N ow ID Name 1 Crusoe Conflict
  • 63.
    9. Delete datafrom local Read-Write with Conflict Detection 63 ID Name Server Modified Active 1 Robinson True True True 2 Chuck Noland True False False 3 Jack Sparrow False True True ID Name Modified Active 1 Crusoe Yesterday True 2 Chuck Noland 1 year True 3 Jack Sparrow Now True 7. Return from server last sync date and two lists, conflicts and no-conflicts 8. Add the ones with conflict to the conflict table 1 Month 10. Write data on the device received from server, except for conflict. With conflicts keep the local data ID Name 1 Crusoe Conflict 1 Robinson True True True 3 Jack Sparrow True False True
  • 64.
    9. Delete datafrom local Read-Write with Conflict Detection 64 ID Name Server Modified Active 1 Robinson True True True 2 Chuck Noland True False False 3 Jack Sparrow False True True ID Name Modified Active 1 Crusoe Yesterday True 2 Chuck Noland 1 year True 3 Jack Sparrow Now True 7. Return from server last sync date and two lists, conflicts and no-conflicts 8. Add the ones with conflict to the conflict table Now 10. Write data on the device received from server, except for conflict. With conflicts keep the local data 11. Update last sync date ID Name 1 Crusoe Conflict 1 Robinson True True True 3 Jack Sparrow True False True
  • 65.
    9. Delete datafrom local Read-Write with Conflict Detection 65 ID Name Server Modified Active 1 Robinson True True True 2 Chuck Noland True False False 3 Jack Sparrow False True True ID Name Modified Active 1 Crusoe Yesterday True 2 Chuck Noland 1 year True 3 Jack Sparrow Now True 7. Return from server last sync date and two lists, conflicts and no-conflicts 8. Add the ones with conflict to the conflict table Now 10. Write data on the device received from server, except for conflict. With conflicts keep the local data 11. Update last sync date ID Name 1 Crusoe Conflict 1 Robinson True True True 3 Jack Sparrow True False True 12. Show conflicts to solve
  • 66.
  • 67.
    Read-Write with ConflictDetection 67 1 1. Only allow sync if no data in device is marked as conflict
  • 68.
    Read-Write with ConflictDetection 68 1. Only allow sync if no data in device is marked as conflict 2. Get last sync date from device 2
  • 69.
    Read-Write with ConflictDetection 69 1. Only allow sync if no data in device is marked as conflict 2. Get last sync date from device 3. Get local device data for new, update and delete 3
  • 70.
    Read-Write with ConflictDetection 70 4 1. Only allow sync if no data in device is marked as conflict 2. Get last sync date from device 3. Get local device data for new, update and delete 4. On server, create new data
  • 71.
    Read-Write with ConflictDetection 71 5 1. Only allow sync if no data in device is marked as conflict 2. Get last sync date from device 3. Get local device data for new, update and delete 4. On server, create new data 5. Update rows with modified date before last sync. Others will be marked as conflict
  • 72.
    Read-Write with ConflictDetection 72 6 1. Only allow sync if no data in device is marked as conflict 2. Get last sync date from device 3. Get local device data for new, update and delete 4. On server, create new data 5. Update rows with modified date before last sync. Others will be marked as conflict 6. Delete rows with modified date before last sync. Others will be marked as conflict
  • 73.
    Read-Write with ConflictDetection 73 7 7. Return from server last sync date and two lists, conflicts and no-conflicts
  • 74.
    Read-Write with ConflictDetection 74 8 7. Return from server last sync date and two lists, conflicts and no-conflicts 8. Add the ones with conflict to the conflict table
  • 75.
    Read-Write with ConflictDetection 75 9. Delete data from local 7. Return from server last sync date and two lists, conflicts and no-conflicts 8. Add the ones with conflict to the conflict table 9
  • 76.
    Read-Write with ConflictDetection 76 10 9. Delete data from local 7. Return from server last sync date and two lists, conflicts and no-conflicts 8. Add the ones with conflict to the conflict table 10. Write data on the device received from server, except for conflict. With conflicts keep the local data
  • 77.
    Read-Write with ConflictDetection 77 9. Delete data from local 7. Return from server last sync date and two lists, conflicts and no-conflicts 8. Add the ones with conflict to the conflict table 10. Write data on the device received from server, except for conflict. With conflicts keep the local data 11. Update last sync date 11
  • 78.
    Read-Write, One-to-Many Data 78 Recommendedfor mobile apps with entities that follow a one-to-many relationship and where it is not likely for multiple end users to change the same data while the apps are offline. ● Local database changes and sends data with relationships to the server. ● Data in server is always overridable. A, B A1, B1
  • 79.
    ID Name ServerModified Active 1 Robinson Crusoe True False True 2 Chuck Noland False True True 3 Jack Sparrow True False True Read-Write, One-to-Many Data 79 ID Name 1 Robinson Crusoe 2 Jack Sparrow ID Name CastId Server Modified Active 1 Wilson 2 False True True Friend
  • 80.
    ID Name ServerModified Active 1 Robinson Crusoe True False True 2 Chuck Noland False True True 3 Jack Sparrow True False True Read-Write, One-to-Many Data 80 ID Name 1 Robinson Crusoe 2 Jack Sparrow ID Name CastId Server Modified Active 1 Wilson 2 False True True Friend 1. Check local data on primary table for new, updated and deleted NEW
  • 81.
    ID Name ServerModified Active 1 Robinson Crusoe True False True 2 Chuck Noland False True True 3 Jack Sparrow True False True Read-Write, One-to-Many Data 81 ID Name 1 Robinson Crusoe 2 Jack Sparrow ID Name CastId Server Modified Active 1 Wilson 2 False True True Friend 1. Check local data on primary table for new, updated and deleted 2. Check local data on foreign table for new, updated and deleted NEW NEW
  • 82.
    ID Name ServerModified Active 1 Robinson Crusoe True False True 2 Chuck Noland False True True 3 Jack Sparrow True False True Read-Write, One-to-Many Data 82 ID Name 1 Robinson Crusoe 2 Jack Sparrow 3 Chuck Noland ID Name CastId Server Modified Active 1 Wilson 2 False True True Friend 1. Check local data on primary table for new, updated and deleted 2. Check local data on foreign table for new, updated and deleted 3. On server, create new data NEW NEW
  • 83.
    ID Name ServerModified Active 1 Robinson Crusoe True False True 2 Chuck Noland False True True 3 Jack Sparrow True False True Read-Write, One-to-Many Data 83 ID Name 1 Robinson Crusoe 2 Jack Sparrow 3 Chuck Noland ID Name CastId Server Modified Active 1 Wilson 2 False True True Friend 1. Check local data on primary table for new, updated and deleted 2. Check local data on foreign table for new, updated and deleted 3. On server, create new data 4. Create dictionary with primary Ids NEW NEW Dictionary ID NewID 2 3
  • 84.
    ID Name ServerModified Active 1 Robinson Crusoe True False True 2 Chuck Noland False True True 3 Jack Sparrow True False True Read-Write, One-to-Many Data 84 ID Name 1 Robinson Crusoe 2 Jack Sparrow 3 Chuck Noland ID Name CastId Server Modified Active 1 Wilson 2 False True True Friend 1. Check local data on primary table for new, updated and deleted 2. Check local data on foreign table for new, updated and deleted 3. On server, create new data 4. Create dictionary with primary Ids 5. Update rows received from device with the new ids in the dictionary NEW NEW Dictionary ID NewID 2 3
  • 85.
    ID Name ServerModified Active 1 Robinson Crusoe True False True 2 Chuck Noland False True True 3 Jack Sparrow True False True Read-Write, One-to-Many Data 85 ID Name 1 Robinson Crusoe 2 Jack Sparrow 3 Chuck Noland ID Name CastId Server Modified Active 1 Wilson 2 False True True Friend 6. Add, update and delete foreign entity in the server NEW NEW Dictionary ID NewID 2 3 ID Name CastId 1 Wilson 3
  • 86.
    ID Name ServerModified Active 1 Robinson Crusoe True False True 2 Chuck Noland False True True 3 Jack Sparrow True False True Read-Write, One-to-Many Data 86 ID Name 1 Robinson Crusoe 2 Jack Sparrow 3 Chuck Noland ID Name CastId Server Modified Active 1 Wilson 2 False True True Friend 6. Add, update and delete foreign entity in the server 7. Send both entities to the device NEW NEW ID Name CastId 1 Wilson 3
  • 87.
    ID Name ServerModified Active 1 Robinson Crusoe True False True 2 Chuck Noland False True True 3 Jack Sparrow True False True Read-Write, One-to-Many Data 87 ID Name 1 Robinson Crusoe 2 Jack Sparrow 3 Chuck Noland ID Name CastId Server Modified Active 1 Wilson 2 False True True Friend 6. Add, update and delete foreign entity in the server 7. Send both entities to the device 8. Delete the foreign entity in the device NEW ID Name CastId 1 Wilson 3
  • 88.
    ID Name ServerModified Active 1 Robinson Crusoe True False True 2 Chuck Noland False True True 3 Jack Sparrow True False True Read-Write, One-to-Many Data 88 ID Name 1 Robinson Crusoe 2 Jack Sparrow 3 Chuck Noland ID Name CastId Server Modified Active 1 Wilson 2 False True True Friend 6. Add, update and delete foreign entity in the server 7. Send both entities to the device 8. Delete the foreign entity in the device 9. Delete the primary entity in the device ID Name CastId 1 Wilson 3
  • 89.
    ID Name ServerModified Active 1 Robinson Crusoe True False True 2 Chuck Noland False True True 3 Jack Sparrow True False True Read-Write, One-to-Many Data 89 ID Name 1 Robinson Crusoe 2 Jack Sparrow 3 Chuck Noland ID Name CastId Server Modified Active 1 Wilson 2 False True True Friend 6. Add, update and delete foreign entity in the server 7. Send both entities to the device 8. Delete the foreign entity in the device 9. Delete the primary entity in the device 10. Add all data for primary entity received from the server ID Name CastId 1 Wilson 3 1 Robinson Crusoe True False True 2 Jack Sparrow True False True 3 Chuck Noland True False True
  • 90.
    ID Name ServerModified Active 1 Robinson Crusoe True False True 2 Chuck Noland False True True 3 Jack Sparrow True False True Read-Write, One-to-Many Data 90 ID Name 1 Robinson Crusoe 2 Jack Sparrow 3 Chuck Noland ID Name CastId Server Modified Active 1 Wilson 2 False True True Friend 6. Add, update and delete foreign entity in the server 7. Send both entities to the device 8. Delete the foreign entity in the device 9. Delete the primary entity in the device 10. Add all data for primary entity received from the server ID Name CastId 1 Wilson 3 1 Robinson Crusoe True False True 2 Jack Sparrow True False True 3 Chuck Noland True False True 11. Add all data for foreign entity received from the server 1 Wilson 3 True False True
  • 91.
    Read-Write, One-to-Many Data 91 1 1.Check local data on primary table for new, updated and deleted
  • 92.
    Read-Write, One-to-Many Data 92 2 1.Check local data on primary table for new, updated and deleted 2. Check local data on foreign table for new, updated and deleted
  • 93.
    Read-Write, One-to-Many Data 93 3 1.Check local data on primary table for new, updated and deleted 2. Check local data on foreign table for new, updated and deleted 3. On server, create new data
  • 94.
    Read-Write, One-to-Many Data 94 1.Check local data on primary table for new, updated and deleted 2. Check local data on foreign table for new, updated and deleted 3. On server, create new data 4. Create dictionary with primary Ids 4
  • 95.
    Read-Write, One-to-Many Data 95 1.Check local data on primary table for new, updated and deleted 2. Check local data on foreign table for new, updated and deleted 3. On server, create new data 4. Create dictionary with primary Ids 5. Update rows received from device with the new ids in the dictionary 5
  • 96.
    Read-Write, One-to-Many Data 96 6.Add, update and delete foreign entity in the server 3
  • 97.
    Read-Write, One-to-Many Data 97 7 6.Add, update and delete foreign entity in the server 7. Send both entities to the device
  • 98.
    Read-Write, One-to-Many Data 98 8,10 6.Add, update and delete foreign entity in the server 7. Send both entities to the device 8. Delete the foreign entity in the device 9. Delete the primary entity in the device 10. Add all data for primary entity received from the server
  • 99.
    Read-Write, One-to-Many Data 99 9,11 6.Add, update and delete foreign entity in the server 7. Send both entities to the device 8. Delete the foreign entity in the device 9. Delete the primary entity in the device 10. Add all data for primary entity received from the server 11. Add all data for foreign entity received from the server
  • 100.
    Summary • Mobile Appsneed offline support to deliver the best user experience. • Design Offline-First: ○ What features or capabilities should be available offline? ○ What data do you need to store in the device database? ○ When should the data be synchronized? ○ How will you handle data in the device? • OutSystems 10 makes building Offline Apps a walk in the park: ○ Easy offline data manipulation. ○ Out-of-the-box data synchronization patterns. 10 0
  • 101.
  • 102.
  • 103.
  • 104.
  • 105.
    Links • Offline DataSynchronization Patterns samples https://goo.gl/ISDsgf • Offline Data Synchronization Patterns documentation https://goo.gl/By3xNH • Ciphered Local Storage Plugin https://goo.gl/Tj02P0 10 5
  • 106.
  • 107.