SlideShare una empresa de Scribd logo
1 de 137
Descargar para leer sin conexión
Stream Based
Data Synchronization
Klemen Verdnik
1. Introduction
1.1 Who am I, What I Do?
• low-level programming enthusiast

(audio and video DSP routines, tight loop
optimizations)
• embedded systems (graphic EQ with DSP,
fleet management, mobile payment)
• familiar with iOS SDK since 2008
• vox.io (web / mobile sip, xmpp)
• layer.com (messaging)
• obsession with synchronization protocols
2. Data Synchronization
2.1 What is Data Synchronization?
• Having data
consistency across two
or more networked
entities
2.1.1 Example
Toggle Switch App
2.1.2 How to Design the System?
• Simple server
Toggle Switch App
2.1.2 How to Design the System?
• Simple server
• Simple client
Toggle Switch App
2.1.2 How to Design the System?
• Simple server
• Simple client
• Simple data
structure
{
lightsOn: true
}
Toggle Switch App
2.1.2 How to Design the System?
2.2 Other Use Cases
• E-mail (IMAP, POP)
• Messaging (iMessages, Hangouts)
• Photo sharing (Photo Stream, Google Photos)
• File sharing (Dropbox, iCloud Drive)
• Online text editors / spreadsheet editors (Google Docs)
• Multiplayer Games (Minecraft)
2.3 Types of Data Synchronization
• File
synchronization
2.3 Types of Data Synchronization
• File
synchronization
• Text / document
synchronization
2.3 Types of Data Synchronization
• File
synchronization
• Text / document
synchronization
• Data model
synchronization
2.4 Approaches to Data
Synchronization
2.4.1 Absolute Synchronization (copying)
• Copying (wholesale transfer) is ok
when dealing with small data-sets
(e.g. refreshing weather
forecast, RSVP list ...)
2.4.1 Absolute Synchronization (copying)
• Figuring out differences between previously
fetched data-sets costs CPU and memory
O(n ⋁ m)
2.4.1 Absolute Synchronization (copying)
• Figuring out differences between previously
fetched data-sets costs CPU and memory
O(n ⋁ m)
Dan
Alex
Blake
Emily
George
Caroline
You
2.4.1 Absolute Synchronization (copying)
• Figuring out differences between previously
fetched data-sets costs CPU and memory
O(n ⋁ m)
Dan
Alex
Blake
Emily
George
Caroline
You
Dan
Alex
Emily
George
Caroline
You
≠
2.4.2 Relative Synchronization (changes)
• Getting data up-to-date with changes

instead of full data sets.
(a.k.a. deltas)
2.4 What are Deltas?
Delta encoding is a way to describe differences
between two datasets.
2.5.1 How to Encode Deltas?
insert ― adds new values to dataset
update ― updates existing values in dataset
delete ― deletes existing values from dataset
+
✔
-
• Three primitive operations
2.5.1 How to Encode Deltas?
0000000: 4749 4654 2B31 0d00 0d00 9100 00b6 6257 GIFT+1........bW
0000010: 0804 0456 2c27 e5aa 7f21 f904 0000 0000 ...V,'...!......
0000020: 002c 0000 0000 0d00 0d00 0002 318c 8f29 .,..........1..)
0000030: 3000 7986 944f 8823 260d 0feb b620 0b03 0.y..O.#&.... ..
0000040: 2e97 e1a4 0f79 920c 60a5 28e5 c452 abc6 .....y..`.(..R..
[ {
type: "update",
offset: 0x03,
values: [ 0x38, 0x39, 0x61 ]
}, {
type: "insert",
offset: 0x50,
values: [ 0xCE, 0xE1, 0x50, 0x96, 0x89, 0x48, 0x9D, 0x02, 0x43, 0x62,
0x8D, 0x98, 0x28, 0x00, 0x00, 0x3B ]
} ]
• Example on how to encode binary data changes
2.5.1 How to Encode Deltas?
0000000: 4749 4638 3961 0d00 0d00 9100 00b6 6257 GIF89a........bW
0000010: 0804 0456 2c27 e5aa 7f21 f904 0000 0000 ...V,'...!......
0000020: 002c 0000 0000 0d00 0d00 0002 318c 8f29 .,..........1..)
0000030: 3000 7986 944f 8823 260d 0feb b620 0b03 0.y..O.#&.... ..
0000040: 2e97 e1a4 0f79 920c 60a5 28e5 c452 abc6 .....y..`.(..R..
[ {
type: "update",
offset: 0x03,
values: [ 0x38, 0x39, 0x61 ]
}, {
type: "insert",
offset: 0x50,
values: [ 0xCE, 0xE1, 0x50, 0x96, 0x89, 0x48, 0x9D, 0x02, 0x43, 0x62,
0x8D, 0x98, 0x28, 0x00, 0x00, 0x3B ]
} ]
• Example on how to encode binary data changes
2.5.1 How to Encode Deltas?
0000000: 4749 4638 3961 0d00 0d00 9100 00b6 6257 GIF89a........bW
0000010: 0804 0456 2c27 e5aa 7f21 f904 0000 0000 ...V,'...!......
0000020: 002c 0000 0000 0d00 0d00 0002 318c 8f29 .,..........1..)
0000030: 3000 7986 944f 8823 260d 0feb b620 0b03 0.y..O.#&.... ..
0000040: 2e97 e1a4 0f79 920c 60a5 28e5 c452 abc6 .....y..`.(..R..
0000050: cee1 5096 8948 9d02 4362 8d98 2800 003b ..P..H..Cb..(..;
[ {
type: "update",
offset: 0x03,
values: [ 0x38, 0x39, 0x61 ]
}, {
type: "insert",
offset: 0x50,
values: [ 0xCE, 0xE1, 0x50, 0x96, 0x89, 0x48, 0x9D, 0x02, 0x43, 0x62,
0x8D, 0x98, 0x28, 0x00, 0x00, 0x3B ]
} ]
• Example on how to encode binary data changes
2.5.1 How to Encode Deltas?
• Example on how to encode text changes
83: //
84: // Toggles the private ivar `_lightSwitchState` boolean, updates the
85: // background image, plays a sound and transmits the change over network.
86: //
87: func toggleAndSendLightSwitchState() {
88: self.lightSwitchState = !self.lightSwitchState
> 89: self.lightSwitchClient.sendLightSwitchState(self.lightSwitchState)
90: }
2.5.1 How to Encode Deltas?
• Example on how to encode text changes (diff patch)
83: //
84: // Toggles the private ivar `_lightSwitchState` boolean, updates the
85: // background image, plays a sound and transmits the change over network.
86: //
87: func toggleAndSendLightSwitchState() {
88: self.lightSwitchState = !self.lightSwitchState
> 89: self.lightSwitchClient?.sendLightSwitchState(self.lightSwitchState)
90: }
--- 89: self.lightSwitchClient.sendLightSwitchState(self.lightSwitchState)
+++ 89: self.lightSwitchClient?.sendLightSwitchState(self.lightSwitchState)
2.5.1 How to Encode Deltas?
• Example on how to encode text changes (insert operation)
83: //
84: // Toggles the private ivar `_lightSwitchState` boolean, updates the
85: // background image, plays a sound and transmits the change over network.
86: //
87: func toggleAndSendLightSwitchState() {
88: self.lightSwitchState = !self.lightSwitchState
> 89: self.lightSwitchClient?.sendLightSwitchState(self.lightSwitchState)
90: }
{
type: "insert",
offset: 2781,
values: [ "?" ]
}
2.5.1 How to Encode Deltas?
• Example on how to encode custom data model changes
{
guests: [ "Alex", "Blake", "Caroline", "Dan", "Emily", "George" ]
}
2.5.1 How to Encode Deltas?
• Example on how to encode custom data model changes
{
guests: [ "Alex", "Blake", "Caroline", "Dan", "Emily", "George" ]
}
{
type: "delete",
guest: [ "Blake" ]
}
{
guests: [ "Alex", "Caroline", "Dan", "Emily", "George" ]
}
3. Stream Based Synchronization
3.1 The Motivation
• Minimum data redundancy
3.1 The Motivation
• Speed / minimum bandwidth
3.1 The Motivation
• Fast writes = good concurrency characteristics
3.1 The Motivation
• Distributability and scalability
3.1 The Motivation
• Offline support
3.2 Stream of Mutations
• Clients with an open connection receive a live
stream of events from the server
3.2 Stream of Mutations
• Clients with an open connection receive a live
stream of events from the server
3.2 Stream of Mutations
• Example "To Do" app
3.2.1 Example (To-do List App Data-model)
• Live synchronized list of
to-do tasks
public struct Todo {
public class List: NSObject {
private let tasks: Array<Task> = []
}
}
3.2.1 Example (To-do List App Data-model)
• Live synchronized list of
to-do tasks
• Task element consists of:
checkbox, label and
color public struct Todo {
public class List: NSObject {
private let tasks: Array<Task> = []
}
}
public struct Todo {
public class Task: NSObject {
public private(set) var identifier: NSUUID
public private(set) var completed: Bool
public private(set) var title: String
public private(set) var label: ColorLabel
public enum ColorLabel: UInt8 {
case None = 0, Red, Orange, Yellow, Green,
Turquoise, Blue, Purple, Pink
}
}
}
3.2.1 Example (To-do List App Data-model)
• Live synchronized list of
to-do tasks
• Task element consists of:
checkbox, label and
color
• Tasks can be added,
edited and removed
public struct Todo {
public class List: NSObject {
private let tasks: Array<Task> = []
public func create(title: String, label: Task.ColorL
public func update(identifier: NSUUID, completed: Bo
public func remove(identifier: NSUUID)
}
}
public struct Todo {
public class Task: NSObject {
public private(set) var identifier: NSUUID
public private(set) var completed: Bool
public private(set) var title: String
public private(set) var label: ColorLabel
public enum ColorLabel: UInt8 {
case None = 0, Red, Orange, Yellow, Green,
Turquoise, Blue, Purple, Pink
}
}
}
3.2.1 Example (To-do List App Data-model)
• Live synchronized list of
to-do tasks
• Task element consists of:
checkbox, label and
color
• Tasks can be added,
edited and removed
3.2.2 Example (To-do List Sync Data-model)
• Todo.List user actions
turn into events (𝚫)
3.2.2 Example (To-do List Sync Data-model)
• Todo.List user actions
turn into events (𝚫)
• Simple concrete objects
describing changes
public struct Sync {
public class Event: NSObject {
public enum Type: UInt8 {
case Insert = 0, Update, Delete
}
public private(set) var type: Type
public private(set) var identifier: NSUUID
public private(set) var completed: Bool?
public private(set) var title: String?
public private(set) var label: Int?
}
}
3.2.2 Example (To-do List Sync Data-model)
• Todo.List user actions
turn into events (𝚫)
• Simple concrete objects
describing changes
• Serializable
public struct Sync {
public class Event: NSObject, Serializable {
public enum Type: UInt8 {
case Insert = 0, Update, Delete
}
public private(set) var type: Type
public private(set) var identifier: NSUUID
public private(set) var completed: Bool?
public private(set) var title: String?
public private(set) var label: Int?
}
}
public protocol Serializable: class {
init(fromDictionary dictionary: Dictionary<String, AnyObject>)
func toDictionary() -> Dictionary<String, AnyObject>
}
3.2.2 Example (To-do List Sync Data-model)
• Todo.List user actions
turn into events (𝚫)
• Simple concrete objects
describing changes
• Serializable
3.2.2 Example (To-do List Sync Data-model)
• Creating new task
{ // serialized event structure
type: 0, // 0 = Insert
identifier: "cb55ceec-b9ae-4bd9-8783-7dbf3e9cb2cd", // client generated id
completed: false, // an incomplete task
title: "Buy Milk", // task description
label: 0 // color tag
}
3.2.2 Example (To-do List Sync Data-model)
• Editing an existing task
{ // event structure
type: 1, // 1 = Update
identifier: "cb55ceec-b9ae-4bd9-8783-7dbf3e9cb2cd", // reference to task
completed: true // new state
}
3.2.3 Example (To-do List Sync and Transport)
• Receive live serialized
Events from the
server. public protocol TransportDelegate: class {
func transport(transport: Transport, didReceiveObject object: Serializable)
func transportDidConnect(transport: Transport)
func transportDidDisconnect(transport: Transport)
}
public struct Sync {
public class Client: NSObject, TransportDelegate {
public private(set) var stream: Stream = Stream()
public private(set) var transport: Transport
public private(set) var todoList: Todo.List
public private(set) var publishedEvents: Array<Event> = []
private func publish(event: Event) -> Bool
public func transport(transport: Transport, didReceiveObject object: Serializab
}
}
3.2.3 Example (To-do List Sync and Transport)
• Receive live serialized
Events from the
server.
• Send serialized
Events to server.
public protocol TransportDelegate: class {
func transport(transport: Transport, didReceiveObject object: Serializable)
func transportDidConnect(transport: Transport)
func transportDidDisconnect(transport: Transport)
}
public struct Sync {
public class Client: NSObject, TransportDelegate {
public private(set) var stream: Stream = Stream()
public private(set) var transport: Transport
public private(set) var todoList: Todo.List
public private(set) var publishedEvents: Array<Event> = []
private func publish(event: Event) -> Bool
public func transport(transport: Transport, didReceiveObject object: Serializab
}
}
3.2.3 Example (To-do List Sync and Transport)
• Receive live serialized
Events from the
server.
• Send serialized
Events to server.
3.3 Let the Streaming Begin
• Data consistent, as long as clients remain connected
3.3 Let the Streaming Begin
• Missing out on events puts the client out-of-sync
3.3 Let the Streaming Begin
• Missing out on events puts the client out-of-sync
{ // event structure
type: 1,
identifier: "cb55ceec-b9ae-4bd9-8783-7dbf3e9cb2cd",
completed: true
}
3.3 Let the Streaming Begin
• Data consistent, as long as clients remain
connected
• Missing out on events puts the client out-of-sync
• Clients can recover from out-of-sync state
• Server's responsibility beside broadcasting should
also be preserving the events
3.4 Persistent Stream
3.4 Persistent Stream
• Think of it as a linear magnetic tape, or as a storage
with a WORM behavior
• Append only
• Immutable events
• Journal of all the events that have happened
3.4 Persistent Stream
• Always copy all the events? (too expensive)
• Integrity check by hashing events? (only detects
mismatches)
How does a client know if it's got all the events?
3.5 Event Discovery
3.5 Event Discovery
• Sequencing Events on server
3.5 Event Discovery
• Sequencing Events on server
public struct Sync {
public class Event: NSObject {
public private(set) var seq: Int?
public private(set) var type: Type
public private(set) var identifier: NSUUID?
public private(set) var completed: Bool?
public private(set) var title: String?
public private(set) var label: Int?
}
}
3.5 Event Discovery
• Sequencing Events on server
• Sequence is a linear function f(x)=x reproducible on client
3.5 Event Discovery
• Sequencing Events on server
• Sequence is a linear function f(x)=x reproducible on client
3.5 Event Discovery
• Client only needs to know the seq value of

the last event f(x<12)=x
3.5 Event Discovery
• Client only needs to know the seq value of

the last event f(x<12)=x
• Figuring out missing events by subtracting the set of seqs
3.5 Event Discovery
// Seq values pulled from all events the client has.
// [ 0, 1, 2, 10, 11, 12 ]
let seqsOfEvents: Set = events.map({ $0.seq })
// Calculated sequence ranging from 0 to 12.
// [ 0, 1, 2, 3 ... 12 ]
let seqsOfAllEvents: Set = [Int](0...12)
// Diffed set of seq values.
// [ 3, 4, 5, 6, 7, 8, 9 ]
let seqsOfMissingEvents: Set = seqOfAllEvents.subtract(seqOfEvents)
• Client only needs to know the seq value of

the last event f(x<12)=x
• Figuring out missing events by subtracting the set of seqs
4. Event and Model Reconciliation
Outbound and inbound reconciliation
4.1 Outbound Reconciliation
• Turning user actions (model changes) into Events
4.1 Outbound Reconciliation
• Turning user actions (model changes) into Events
4.1 Outbound Reconciliation
• Turning user actions (model changes) into Events
4.1 Outbound Reconciliation
• Turning user actions (model changes) into Events
4.1 Outbound Reconciliation
• Turning user actions (model changes) into Events
public class List: NSObject {
public func create(title: String, label: Task.ColorLabel) -> Sync.Event
public func update(identifier: NSUUID, completed: Bool?, title: String?, label: Task.ColorLabel?) -> Sync.Event?
public func remove(identifier: NSUUID) -> Sync.Event?
}
4.1 Outbound Reconciliation
• Turning user actions (model changes) into Events
let todoList = List()
let event = todoList.create("Buy Milk", label: Task.ColorLabel.None)
print("event: '(event)", event)
// event: {
// type: 0, // 0 = Insert
// identifier: "cb55ceec-b9ae-4bd9-8783-7dbf3e9cb2cd", // client generated id
// completed: false, // an incomplete task
// title: "Buy milk", // task description
// label: 0 // task without a label
// }
4.1 Outbound Reconciliation
• Publishing events
let todoList = List()
let event = todoList.create("Buy Milk", label: Task.ColorLabel.None)
print("event: '(event)", event)
// event: {
// type: 0, // 0 = Insert
// identifier: "cb55ceec-b9ae-4bd9-8783-7dbf3e9cb2cd", // client generated id
// completed: false, // an incomplete task
// title: "Buy milk", // task description
// label: 0 // task without a label
// }
// Sends the event to the stream over the network.
self.syncClient.publish(event)
4.2 Inbound Reconciliation
• Apply Events onto the model
4.2 Inbound Reconciliation
• Apply Events onto the model
public class List: NSObject {
private func apply(event: Sync.Event) -> Bool {
switch event.type {
case .Insert: // Task creation
let task = Task(identifier: event.identifier, completed: event.completed!, title: event.title!, label: Task.ColorL
self.tasks.append(task)
case .Update: // Task updates
let task = self.task(event.identifier)
if task == nil {
return false
}
task!.update(event.completed!, title: event.title!, label: Task.ColorLabel(rawValue: event.label!)!)
case .Delete: // Task removal
if !self.removeTask(event.identifier) {
return false
}
}
return true
}
}
4.3 Offline Support
• Events generated offline have to be published eventually
4.3 Offline Support
• Queue generated events; drain queue for publication
✔
4.3 Offline Support
• Generating redundant events while offline
✔
4.3 Offline Support
• Generating redundant events while offline
4.4 Reducing the Edit Distance
• Events describing the same mutation
4.4 Reducing the Edit Distance
• Causes stream pollution
• Increases the edit distance
4.4 Reducing the Edit Distance
1. Insert Event merges with

Update Events → single Insert Event
2. Update Event merge with

the rest of Update Events → single Update Event
3. Last Update Event defines final state.
4. Delete Event clobbers other Event types
Simple set of rules when queueing:
4.4 Reducing the Edit Distance
public struct Sync {
public class Event: NSObject, Serializable {
var mergedEvents = Array<Event>()
for oldEvent in events.reverse() {
if oldEvent.identifier != self.identifier {
// Event not mergeable, due to the identifier mismatch.
mergedEvents.append(oldEvent)
continue
} else if self.type == Type.Delete {
// Rule #4
self.reset()
self.type = Type.Delete
} else if self.type == Type.Update && (oldEvent.type == Type.Insert || oldEvent.type == Type.Update) {
// Rule #1, #2, #3
self.completed = self.completed ?? oldEvent.completed
self.title = self.title ?? oldEvent.title
self.label = self.label ?? oldEvent.label
}
}
mergedEvents.append(self)
return mergedEvents
}
}
4.5 Conflict Resolution
• Concurrent systems experience conflicts when two
or more nodes (clients) work on the same resource
at the same time.
4.5 Conflict Resolution
• Concurrent systems experience conflicts when two
or more nodes (clients) work on the same resource
at the same time.
• Example: a client deletes a Todo Task before
another client tries to mutate it.
4.5 Conflict Resolution
Possible conflict resolutions:
• Bring the deleted task back (last writer wins)
• Deleted task stays deleted (first writer wins)
• Ask the User what to do? (requires user interaction)
5. Order of Events
5. Order of Events
Event sequence dictates the order they were written to

stream this puts the Events in total order
• Task objects will be in the exact same order, defined by

the Event.seq
• Task mutations will be applied in the same manner on all
clients
5. Order of Events (total order)
• Queued events must be published in batches
5. Order of Events (total order)
• Queued events must be published in batches
5. Order of Events (total order)
• Queued events must be published in batches
5. Order of Events (total order)
• Queued events must be published in batches
5.1 Total Order (sequential writes)
• Synchronized sequential writes block other clients from
writing
5.1 Total Order (sequential writes)
• Synchronized sequential writes block other clients from
writing - violates our fast concurrent writes requirement
serial
writes
concurrent
writes
5.1 Total Order (offline support)
• Both clients online
5.1 Total Order (offline support)
• Both clients online
5.1 Total Order (offline support)
• Left client loses connection
5.1 Total Order (offline support)
• Offline client adds more To-do tasks to the list
5.1 Total Order (offline support)
• Online client also adds a Todo task to the list
5.1 Total Order (offline support)
• Left client comes back online ― events generated offline
get published and fall at the end (higher seq values)
5.2 Causal Order
Causes must precede their effects - effects come after causes,
and never before
5.2 Causal Order
Causes must precede their effects - effects come after causes,
and never before
cause
effect
5.2 Causal Order
• Generated Event is an effect caused by user taking action /
responding to the UI.
• Events should be reconciled in the same order as they were
generated by clients.
• Events should be applied onto the app model under the same
conditions as it was when author generated the events.
• Total order cannot guarantee Events will be written to stream in
the same order they were generated.
5.2.1 Order Based on Timestamps
Client B's events are
written before Client A's,
even though Client A
generated them first.
Encoding local time
with events.
5.2.1 Order Based on Timestamps
Sorting events based
on the embedded
timestamp.
5.2.1 Order Based on Timestamps
5.2.1 Order Based on Timestamps
• No guarantee
time will be the
same on all
devices
• Clock skew
• Manual override
5.2.2 Version Vectors
• Reconstructing Events' order as it was perceived by the author
based on happened-before information.
• Provides causality-tracking basic principle in some optimistic
(lazy) replication algorithms.
• Allows the client to operate independently from the server.
• When all clients eventually publish their events, it brings other online
clients into a consistent state eventual consistency.
5.2.2 Version Vectors
How to encode happened-before information?
public struct Sync {
public class Event: NSObject {
public private(set) var seq: Int?
public private(set) var type: Type
public private(set) var identifier: NSUUID?
public private(set) var completed: Bool?
public private(set) var title: String?
public private(set) var label: Int?
}
}
5.2.2 Version Vectors
1. Information of what's
the last seen event -
event.seq
How to encode happened-before information?
public struct Sync {
public class Event: NSObject {
public private(set) var seq: Int?
public private(set) var precedingSeq: Int
public private(set) var type: Type
public private(set) var identifier: NSUUID?
public private(set) var completed: Bool?
public private(set) var title: String?
public private(set) var label: Int?
}
}
5.2.2 Version Vectors
1. Information of what's
the last seen event -
event.seq
2. Keep unpublished
events in order -
event.clientSeq
How to encode happened-before information?
public struct Sync {
public class Event: NSObject {
public private(set) var seq: Int?
public private(set) var precedingSeq: Int
public private(set) var clientSeq: Int
public private(set) var type: Type
public private(set) var identifier: NSUUID?
public private(set) var completed: Bool?
public private(set) var title: String?
public private(set) var label: Int?
}
}
5.2.2 Version Vectors
1. Information of what's
the last seen event -
event.seq
2. Keep unpublished
events in order -
event.clientSeq
3. Order
How to encode happened-before information?
public struct Sync {
public class Event: NSObject {
/// Event sorting closure
static public let causalOrder = { (e1: Event, e2: Event)
if e1.precedingSeq == e2.precedingSeq {
return e1.clientSeq < e2.clientSeq
}
return e1.precedingSeq < e2.precedingSeq
}
public private(set) var seq: Int?
public private(set) var precedingSeq: Int
public private(set) var clientSeq: Int
public private(set) var type: Type
public private(set) var identifier: NSUUID?
public private(set) var completed: Bool?
public private(set) var title: String?
public private(set) var label: Int?
}
}
5.2.2 Version Vectors
5.2.2 Version Vectors
5.2.2 Version Vectors
5.2.2 Version Vectors
5.2.2 Version Vectors
5.2.2 Version Vectors
5.2.2 Version Vectors
public struct Sync {
public class Event: NSObject, Serializable {
var mergedEvents = Array<Event>()
for oldEvent in events.sort(Event.causalOrder) {
if oldEvent.identifier != self.identifier {
// etc...
public struct Todo {
public class List: NSObject, ModelReconciler {
public func apply(events: Array<Sync.Event>) -> Bool {
for event in events.sort(Sync.Event.causalOrder) {
let success = self.apply(event)
// etc...
Minor adjustment in outbound / inbound reconciliation:
5.2.2 Version Vectors
• Newly published events generated offline are ordered by
their causality.
5.2.2 Version Vectors
• Concurrent writes - no need for batched writes anymore,

due to clientSeq.
5.2.2 Version Vectors
• Concurrent writes - events can be written with undetermined
order; order can be reconstructed on clients
serial
writes
concurrent
writes
6. Advantages
6. Advantages
• Shared source - minimal redundancy
6. Advantages
• Shared source - minimal redundancy
• Lightweight data structure - fast delivery
6. Advantages
• Shared source - minimal redundancy
• Lightweight data structure - fast delivery
• Minimal server logic (low CPU)
6. Advantages
• Shared source - minimal redundancy
• Lightweight data structure - fast delivery
• Minimal server logic (low CPU)
• Short writes - high concurrency
6. Advantages
• Shared source - minimal redundancy
• Lightweight data structure - fast delivery
• Minimal server logic (low CPU)
• Short writes - high concurrency
• Scalable / distributable
6. Advantages
• Shared source - minimal redundancy
• Lightweight data structure - fast delivery
• Minimal server logic (low CPU)
• Short writes - high concurrency
• Scalable / distributable
• Offline support
7. Disadvantages
7. Disadvantages
• Server simplicity = client complexity
7. Disadvantages
• Server simplicity = client complexity
• Rogue clients = stream pollution
7. Disadvantages
• Server simplicity = client complexity
• Rogue clients = stream pollution
• Clients must read full stream
7. Disadvantages
• Server simplicity = client complexity
• Rogue clients = stream pollution
• Clients must read full stream
• Partial sync difficult to implement
END_OF_STREAM
questions?
klemen.verdnik@gmail.comgithub.com/chipxsd
@chipxsd

Más contenido relacionado

La actualidad más candente

The Ring programming language version 1.5.1 book - Part 28 of 180
The Ring programming language version 1.5.1 book - Part 28 of 180The Ring programming language version 1.5.1 book - Part 28 of 180
The Ring programming language version 1.5.1 book - Part 28 of 180Mahmoud Samir Fayed
 
R for Pirates. ESCCONF October 27, 2011
R for Pirates. ESCCONF October 27, 2011R for Pirates. ESCCONF October 27, 2011
R for Pirates. ESCCONF October 27, 2011Mandi Walls
 
From Lisp to Clojure/Incanter and RAn Introduction
From Lisp to Clojure/Incanter and RAn IntroductionFrom Lisp to Clojure/Incanter and RAn Introduction
From Lisp to Clojure/Incanter and RAn Introductionelliando dias
 
Data Love Conference - Window Functions for Database Analytics
Data Love Conference - Window Functions for Database AnalyticsData Love Conference - Window Functions for Database Analytics
Data Love Conference - Window Functions for Database AnalyticsDave Stokes
 
Big Data LDN 2017: From Zero to AI in 30 Minutes
Big Data LDN 2017: From Zero to AI in 30 MinutesBig Data LDN 2017: From Zero to AI in 30 Minutes
Big Data LDN 2017: From Zero to AI in 30 MinutesMatt Stubbs
 
[1062BPY12001] Data analysis with R / week 2
[1062BPY12001] Data analysis with R / week 2[1062BPY12001] Data analysis with R / week 2
[1062BPY12001] Data analysis with R / week 2Kevin Chun-Hsien Hsu
 
6. Vectors – Data Frames
6. Vectors – Data Frames6. Vectors – Data Frames
6. Vectors – Data FramesFAO
 
Particle Filter Tracking in Python
Particle Filter Tracking in PythonParticle Filter Tracking in Python
Particle Filter Tracking in PythonKohta Ishikawa
 
CS253: Minimum spanning Trees (2019)
CS253: Minimum spanning Trees (2019)CS253: Minimum spanning Trees (2019)
CS253: Minimum spanning Trees (2019)Jinho Choi
 
Time Series Meetup: Virtual Edition | July 2020
Time Series Meetup: Virtual Edition | July 2020Time Series Meetup: Virtual Edition | July 2020
Time Series Meetup: Virtual Edition | July 2020InfluxData
 
Multiclassification with Decision Tree in Spark MLlib 1.3
Multiclassification with Decision Tree in Spark MLlib 1.3Multiclassification with Decision Tree in Spark MLlib 1.3
Multiclassification with Decision Tree in Spark MLlib 1.3leorick lin
 
The Ring programming language version 1.4.1 book - Part 7 of 31
The Ring programming language version 1.4.1 book - Part 7 of 31The Ring programming language version 1.4.1 book - Part 7 of 31
The Ring programming language version 1.4.1 book - Part 7 of 31Mahmoud Samir Fayed
 

La actualidad más candente (13)

The Ring programming language version 1.5.1 book - Part 28 of 180
The Ring programming language version 1.5.1 book - Part 28 of 180The Ring programming language version 1.5.1 book - Part 28 of 180
The Ring programming language version 1.5.1 book - Part 28 of 180
 
R for Pirates. ESCCONF October 27, 2011
R for Pirates. ESCCONF October 27, 2011R for Pirates. ESCCONF October 27, 2011
R for Pirates. ESCCONF October 27, 2011
 
From Lisp to Clojure/Incanter and RAn Introduction
From Lisp to Clojure/Incanter and RAn IntroductionFrom Lisp to Clojure/Incanter and RAn Introduction
From Lisp to Clojure/Incanter and RAn Introduction
 
Data Love Conference - Window Functions for Database Analytics
Data Love Conference - Window Functions for Database AnalyticsData Love Conference - Window Functions for Database Analytics
Data Love Conference - Window Functions for Database Analytics
 
Apache Cassandra & Data Modeling
Apache Cassandra & Data ModelingApache Cassandra & Data Modeling
Apache Cassandra & Data Modeling
 
Big Data LDN 2017: From Zero to AI in 30 Minutes
Big Data LDN 2017: From Zero to AI in 30 MinutesBig Data LDN 2017: From Zero to AI in 30 Minutes
Big Data LDN 2017: From Zero to AI in 30 Minutes
 
[1062BPY12001] Data analysis with R / week 2
[1062BPY12001] Data analysis with R / week 2[1062BPY12001] Data analysis with R / week 2
[1062BPY12001] Data analysis with R / week 2
 
6. Vectors – Data Frames
6. Vectors – Data Frames6. Vectors – Data Frames
6. Vectors – Data Frames
 
Particle Filter Tracking in Python
Particle Filter Tracking in PythonParticle Filter Tracking in Python
Particle Filter Tracking in Python
 
CS253: Minimum spanning Trees (2019)
CS253: Minimum spanning Trees (2019)CS253: Minimum spanning Trees (2019)
CS253: Minimum spanning Trees (2019)
 
Time Series Meetup: Virtual Edition | July 2020
Time Series Meetup: Virtual Edition | July 2020Time Series Meetup: Virtual Edition | July 2020
Time Series Meetup: Virtual Edition | July 2020
 
Multiclassification with Decision Tree in Spark MLlib 1.3
Multiclassification with Decision Tree in Spark MLlib 1.3Multiclassification with Decision Tree in Spark MLlib 1.3
Multiclassification with Decision Tree in Spark MLlib 1.3
 
The Ring programming language version 1.4.1 book - Part 7 of 31
The Ring programming language version 1.4.1 book - Part 7 of 31The Ring programming language version 1.4.1 book - Part 7 of 31
The Ring programming language version 1.4.1 book - Part 7 of 31
 

Destacado

High Temperature Cabinet Oven by ACMAS Technologies Pvt Ltd.
High Temperature Cabinet Oven by ACMAS Technologies Pvt Ltd.High Temperature Cabinet Oven by ACMAS Technologies Pvt Ltd.
High Temperature Cabinet Oven by ACMAS Technologies Pvt Ltd.Acmas Technologies Pvt. Ltd.
 
匆匆数年 - 在豆瓣
匆匆数年 - 在豆瓣匆匆数年 - 在豆瓣
匆匆数年 - 在豆瓣Xupeng Yun
 
美团点评技术沙龙09 - 外卖O2O的用户画像实践
美团点评技术沙龙09 - 外卖O2O的用户画像实践美团点评技术沙龙09 - 外卖O2O的用户画像实践
美团点评技术沙龙09 - 外卖O2O的用户画像实践美团点评技术团队
 
Track A-1: Cloudera 大數據產品和技術最前沿資訊報告
Track A-1: Cloudera 大數據產品和技術最前沿資訊報告Track A-1: Cloudera 大數據產品和技術最前沿資訊報告
Track A-1: Cloudera 大數據產品和技術最前沿資訊報告Etu Solution
 
唯品会大数据实践 Sacc pub
唯品会大数据实践 Sacc pub唯品会大数据实践 Sacc pub
唯品会大数据实践 Sacc pubChao Zhu
 
豆瓣数据架构实践
豆瓣数据架构实践豆瓣数据架构实践
豆瓣数据架构实践Xupeng Yun
 
大數據運算媒體業案例分享 (Big Data Compute Case Sharing for Media Industry)
大數據運算媒體業案例分享 (Big Data Compute Case Sharing for Media Industry)大數據運算媒體業案例分享 (Big Data Compute Case Sharing for Media Industry)
大數據運算媒體業案例分享 (Big Data Compute Case Sharing for Media Industry)Amazon Web Services
 
Visual Design with Data
Visual Design with DataVisual Design with Data
Visual Design with DataSeth Familian
 

Destacado (8)

High Temperature Cabinet Oven by ACMAS Technologies Pvt Ltd.
High Temperature Cabinet Oven by ACMAS Technologies Pvt Ltd.High Temperature Cabinet Oven by ACMAS Technologies Pvt Ltd.
High Temperature Cabinet Oven by ACMAS Technologies Pvt Ltd.
 
匆匆数年 - 在豆瓣
匆匆数年 - 在豆瓣匆匆数年 - 在豆瓣
匆匆数年 - 在豆瓣
 
美团点评技术沙龙09 - 外卖O2O的用户画像实践
美团点评技术沙龙09 - 外卖O2O的用户画像实践美团点评技术沙龙09 - 外卖O2O的用户画像实践
美团点评技术沙龙09 - 外卖O2O的用户画像实践
 
Track A-1: Cloudera 大數據產品和技術最前沿資訊報告
Track A-1: Cloudera 大數據產品和技術最前沿資訊報告Track A-1: Cloudera 大數據產品和技術最前沿資訊報告
Track A-1: Cloudera 大數據產品和技術最前沿資訊報告
 
唯品会大数据实践 Sacc pub
唯品会大数据实践 Sacc pub唯品会大数据实践 Sacc pub
唯品会大数据实践 Sacc pub
 
豆瓣数据架构实践
豆瓣数据架构实践豆瓣数据架构实践
豆瓣数据架构实践
 
大數據運算媒體業案例分享 (Big Data Compute Case Sharing for Media Industry)
大數據運算媒體業案例分享 (Big Data Compute Case Sharing for Media Industry)大數據運算媒體業案例分享 (Big Data Compute Case Sharing for Media Industry)
大數據運算媒體業案例分享 (Big Data Compute Case Sharing for Media Industry)
 
Visual Design with Data
Visual Design with DataVisual Design with Data
Visual Design with Data
 

Similar a Stream-based Data Synchronization

MongoDB Solution for Internet of Things and Big Data
MongoDB Solution for Internet of Things and Big DataMongoDB Solution for Internet of Things and Big Data
MongoDB Solution for Internet of Things and Big DataStefano Dindo
 
Lab pratico per la progettazione di soluzioni MongoDB in ambito Internet of T...
Lab pratico per la progettazione di soluzioni MongoDB in ambito Internet of T...Lab pratico per la progettazione di soluzioni MongoDB in ambito Internet of T...
Lab pratico per la progettazione di soluzioni MongoDB in ambito Internet of T...festival ICT 2016
 
OrientDB - The 2nd generation of (multi-model) NoSQL
OrientDB - The 2nd generation of  (multi-model) NoSQLOrientDB - The 2nd generation of  (multi-model) NoSQL
OrientDB - The 2nd generation of (multi-model) NoSQLRoberto Franchini
 
DEVNET-1163 Data in Motion APIs
DEVNET-1163	Data in Motion APIsDEVNET-1163	Data in Motion APIs
DEVNET-1163 Data in Motion APIsCisco DevNet
 
MongoDB: Optimising for Performance, Scale & Analytics
MongoDB: Optimising for Performance, Scale & AnalyticsMongoDB: Optimising for Performance, Scale & Analytics
MongoDB: Optimising for Performance, Scale & AnalyticsServer Density
 
Ensuring High Availability for Real-time Analytics featuring Boxed Ice / Serv...
Ensuring High Availability for Real-time Analytics featuring Boxed Ice / Serv...Ensuring High Availability for Real-time Analytics featuring Boxed Ice / Serv...
Ensuring High Availability for Real-time Analytics featuring Boxed Ice / Serv...MongoDB
 
IncQuery-D: Incremental Queries in the Cloud
IncQuery-D: Incremental Queries in the CloudIncQuery-D: Incremental Queries in the Cloud
IncQuery-D: Incremental Queries in the CloudGábor Szárnyas
 
React London April- Fully functional: Central state is a great fit for React ...
React London April- Fully functional: Central state is a great fit for React ...React London April- Fully functional: Central state is a great fit for React ...
React London April- Fully functional: Central state is a great fit for React ...React London Community
 
iBeacons - the new low-powered way of location awareness
iBeacons - the new low-powered way of location awarenessiBeacons - the new low-powered way of location awareness
iBeacons - the new low-powered way of location awarenessStefano Zanetti
 
Getting started cpp full
Getting started cpp   fullGetting started cpp   full
Getting started cpp fullVõ Hòa
 
Accelerating analytics on the Sensor and IoT Data.
Accelerating analytics on the Sensor and IoT Data. Accelerating analytics on the Sensor and IoT Data.
Accelerating analytics on the Sensor and IoT Data. Keshav Murthy
 
Deep Style: Using Variational Auto-encoders for Image Generation
Deep Style: Using Variational Auto-encoders for Image GenerationDeep Style: Using Variational Auto-encoders for Image Generation
Deep Style: Using Variational Auto-encoders for Image GenerationTJ Torres
 
SQL Server Deep Dive, Denis Reznik
SQL Server Deep Dive, Denis ReznikSQL Server Deep Dive, Denis Reznik
SQL Server Deep Dive, Denis ReznikSigma Software
 
MongoDB World 2018: Overnight to 60 Seconds: An IOT ETL Performance Case Study
MongoDB World 2018: Overnight to 60 Seconds: An IOT ETL Performance Case StudyMongoDB World 2018: Overnight to 60 Seconds: An IOT ETL Performance Case Study
MongoDB World 2018: Overnight to 60 Seconds: An IOT ETL Performance Case StudyMongoDB
 
A Deep Dive into Spark SQL's Catalyst Optimizer with Yin Huai
A Deep Dive into Spark SQL's Catalyst Optimizer with Yin HuaiA Deep Dive into Spark SQL's Catalyst Optimizer with Yin Huai
A Deep Dive into Spark SQL's Catalyst Optimizer with Yin HuaiDatabricks
 
SparkSQL: A Compiler from Queries to RDDs
SparkSQL: A Compiler from Queries to RDDsSparkSQL: A Compiler from Queries to RDDs
SparkSQL: A Compiler from Queries to RDDsDatabricks
 
Beyond PHP - It's not (just) about the code
Beyond PHP - It's not (just) about the codeBeyond PHP - It's not (just) about the code
Beyond PHP - It's not (just) about the codeWim Godden
 

Similar a Stream-based Data Synchronization (20)

MongoDB Solution for Internet of Things and Big Data
MongoDB Solution for Internet of Things and Big DataMongoDB Solution for Internet of Things and Big Data
MongoDB Solution for Internet of Things and Big Data
 
Lab pratico per la progettazione di soluzioni MongoDB in ambito Internet of T...
Lab pratico per la progettazione di soluzioni MongoDB in ambito Internet of T...Lab pratico per la progettazione di soluzioni MongoDB in ambito Internet of T...
Lab pratico per la progettazione di soluzioni MongoDB in ambito Internet of T...
 
OrientDB - The 2nd generation of (multi-model) NoSQL
OrientDB - The 2nd generation of  (multi-model) NoSQLOrientDB - The 2nd generation of  (multi-model) NoSQL
OrientDB - The 2nd generation of (multi-model) NoSQL
 
DEVNET-1163 Data in Motion APIs
DEVNET-1163	Data in Motion APIsDEVNET-1163	Data in Motion APIs
DEVNET-1163 Data in Motion APIs
 
MongoDB: Optimising for Performance, Scale & Analytics
MongoDB: Optimising for Performance, Scale & AnalyticsMongoDB: Optimising for Performance, Scale & Analytics
MongoDB: Optimising for Performance, Scale & Analytics
 
NoSQL Infrastructure
NoSQL InfrastructureNoSQL Infrastructure
NoSQL Infrastructure
 
Ensuring High Availability for Real-time Analytics featuring Boxed Ice / Serv...
Ensuring High Availability for Real-time Analytics featuring Boxed Ice / Serv...Ensuring High Availability for Real-time Analytics featuring Boxed Ice / Serv...
Ensuring High Availability for Real-time Analytics featuring Boxed Ice / Serv...
 
Se2017 query-optimizer
Se2017 query-optimizerSe2017 query-optimizer
Se2017 query-optimizer
 
dfl
dfldfl
dfl
 
IncQuery-D: Incremental Queries in the Cloud
IncQuery-D: Incremental Queries in the CloudIncQuery-D: Incremental Queries in the Cloud
IncQuery-D: Incremental Queries in the Cloud
 
React London April- Fully functional: Central state is a great fit for React ...
React London April- Fully functional: Central state is a great fit for React ...React London April- Fully functional: Central state is a great fit for React ...
React London April- Fully functional: Central state is a great fit for React ...
 
iBeacons - the new low-powered way of location awareness
iBeacons - the new low-powered way of location awarenessiBeacons - the new low-powered way of location awareness
iBeacons - the new low-powered way of location awareness
 
Getting started cpp full
Getting started cpp   fullGetting started cpp   full
Getting started cpp full
 
Accelerating analytics on the Sensor and IoT Data.
Accelerating analytics on the Sensor and IoT Data. Accelerating analytics on the Sensor and IoT Data.
Accelerating analytics on the Sensor and IoT Data.
 
Deep Style: Using Variational Auto-encoders for Image Generation
Deep Style: Using Variational Auto-encoders for Image GenerationDeep Style: Using Variational Auto-encoders for Image Generation
Deep Style: Using Variational Auto-encoders for Image Generation
 
SQL Server Deep Dive, Denis Reznik
SQL Server Deep Dive, Denis ReznikSQL Server Deep Dive, Denis Reznik
SQL Server Deep Dive, Denis Reznik
 
MongoDB World 2018: Overnight to 60 Seconds: An IOT ETL Performance Case Study
MongoDB World 2018: Overnight to 60 Seconds: An IOT ETL Performance Case StudyMongoDB World 2018: Overnight to 60 Seconds: An IOT ETL Performance Case Study
MongoDB World 2018: Overnight to 60 Seconds: An IOT ETL Performance Case Study
 
A Deep Dive into Spark SQL's Catalyst Optimizer with Yin Huai
A Deep Dive into Spark SQL's Catalyst Optimizer with Yin HuaiA Deep Dive into Spark SQL's Catalyst Optimizer with Yin Huai
A Deep Dive into Spark SQL's Catalyst Optimizer with Yin Huai
 
SparkSQL: A Compiler from Queries to RDDs
SparkSQL: A Compiler from Queries to RDDsSparkSQL: A Compiler from Queries to RDDs
SparkSQL: A Compiler from Queries to RDDs
 
Beyond PHP - It's not (just) about the code
Beyond PHP - It's not (just) about the codeBeyond PHP - It's not (just) about the code
Beyond PHP - It's not (just) about the code
 

Último

Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxfenichawla
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 

Último (20)

Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
(INDIRA) Call Girl Aurangabad Call Now 8617697112 Aurangabad Escorts 24x7
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 

Stream-based Data Synchronization

  • 3. 1.1 Who am I, What I Do? • low-level programming enthusiast
 (audio and video DSP routines, tight loop optimizations) • embedded systems (graphic EQ with DSP, fleet management, mobile payment) • familiar with iOS SDK since 2008 • vox.io (web / mobile sip, xmpp) • layer.com (messaging) • obsession with synchronization protocols
  • 5. 2.1 What is Data Synchronization? • Having data consistency across two or more networked entities
  • 7. 2.1.2 How to Design the System? • Simple server Toggle Switch App
  • 8. 2.1.2 How to Design the System? • Simple server • Simple client Toggle Switch App
  • 9. 2.1.2 How to Design the System? • Simple server • Simple client • Simple data structure { lightsOn: true } Toggle Switch App
  • 10. 2.1.2 How to Design the System?
  • 11. 2.2 Other Use Cases • E-mail (IMAP, POP) • Messaging (iMessages, Hangouts) • Photo sharing (Photo Stream, Google Photos) • File sharing (Dropbox, iCloud Drive) • Online text editors / spreadsheet editors (Google Docs) • Multiplayer Games (Minecraft)
  • 12. 2.3 Types of Data Synchronization • File synchronization
  • 13. 2.3 Types of Data Synchronization • File synchronization • Text / document synchronization
  • 14. 2.3 Types of Data Synchronization • File synchronization • Text / document synchronization • Data model synchronization
  • 15. 2.4 Approaches to Data Synchronization
  • 16. 2.4.1 Absolute Synchronization (copying) • Copying (wholesale transfer) is ok when dealing with small data-sets (e.g. refreshing weather forecast, RSVP list ...)
  • 17. 2.4.1 Absolute Synchronization (copying) • Figuring out differences between previously fetched data-sets costs CPU and memory O(n ⋁ m)
  • 18. 2.4.1 Absolute Synchronization (copying) • Figuring out differences between previously fetched data-sets costs CPU and memory O(n ⋁ m) Dan Alex Blake Emily George Caroline You
  • 19. 2.4.1 Absolute Synchronization (copying) • Figuring out differences between previously fetched data-sets costs CPU and memory O(n ⋁ m) Dan Alex Blake Emily George Caroline You Dan Alex Emily George Caroline You ≠
  • 20. 2.4.2 Relative Synchronization (changes) • Getting data up-to-date with changes
 instead of full data sets. (a.k.a. deltas)
  • 21. 2.4 What are Deltas? Delta encoding is a way to describe differences between two datasets.
  • 22. 2.5.1 How to Encode Deltas? insert ― adds new values to dataset update ― updates existing values in dataset delete ― deletes existing values from dataset + ✔ - • Three primitive operations
  • 23. 2.5.1 How to Encode Deltas? 0000000: 4749 4654 2B31 0d00 0d00 9100 00b6 6257 GIFT+1........bW 0000010: 0804 0456 2c27 e5aa 7f21 f904 0000 0000 ...V,'...!...... 0000020: 002c 0000 0000 0d00 0d00 0002 318c 8f29 .,..........1..) 0000030: 3000 7986 944f 8823 260d 0feb b620 0b03 0.y..O.#&.... .. 0000040: 2e97 e1a4 0f79 920c 60a5 28e5 c452 abc6 .....y..`.(..R.. [ { type: "update", offset: 0x03, values: [ 0x38, 0x39, 0x61 ] }, { type: "insert", offset: 0x50, values: [ 0xCE, 0xE1, 0x50, 0x96, 0x89, 0x48, 0x9D, 0x02, 0x43, 0x62, 0x8D, 0x98, 0x28, 0x00, 0x00, 0x3B ] } ] • Example on how to encode binary data changes
  • 24. 2.5.1 How to Encode Deltas? 0000000: 4749 4638 3961 0d00 0d00 9100 00b6 6257 GIF89a........bW 0000010: 0804 0456 2c27 e5aa 7f21 f904 0000 0000 ...V,'...!...... 0000020: 002c 0000 0000 0d00 0d00 0002 318c 8f29 .,..........1..) 0000030: 3000 7986 944f 8823 260d 0feb b620 0b03 0.y..O.#&.... .. 0000040: 2e97 e1a4 0f79 920c 60a5 28e5 c452 abc6 .....y..`.(..R.. [ { type: "update", offset: 0x03, values: [ 0x38, 0x39, 0x61 ] }, { type: "insert", offset: 0x50, values: [ 0xCE, 0xE1, 0x50, 0x96, 0x89, 0x48, 0x9D, 0x02, 0x43, 0x62, 0x8D, 0x98, 0x28, 0x00, 0x00, 0x3B ] } ] • Example on how to encode binary data changes
  • 25. 2.5.1 How to Encode Deltas? 0000000: 4749 4638 3961 0d00 0d00 9100 00b6 6257 GIF89a........bW 0000010: 0804 0456 2c27 e5aa 7f21 f904 0000 0000 ...V,'...!...... 0000020: 002c 0000 0000 0d00 0d00 0002 318c 8f29 .,..........1..) 0000030: 3000 7986 944f 8823 260d 0feb b620 0b03 0.y..O.#&.... .. 0000040: 2e97 e1a4 0f79 920c 60a5 28e5 c452 abc6 .....y..`.(..R.. 0000050: cee1 5096 8948 9d02 4362 8d98 2800 003b ..P..H..Cb..(..; [ { type: "update", offset: 0x03, values: [ 0x38, 0x39, 0x61 ] }, { type: "insert", offset: 0x50, values: [ 0xCE, 0xE1, 0x50, 0x96, 0x89, 0x48, 0x9D, 0x02, 0x43, 0x62, 0x8D, 0x98, 0x28, 0x00, 0x00, 0x3B ] } ] • Example on how to encode binary data changes
  • 26. 2.5.1 How to Encode Deltas? • Example on how to encode text changes 83: // 84: // Toggles the private ivar `_lightSwitchState` boolean, updates the 85: // background image, plays a sound and transmits the change over network. 86: // 87: func toggleAndSendLightSwitchState() { 88: self.lightSwitchState = !self.lightSwitchState > 89: self.lightSwitchClient.sendLightSwitchState(self.lightSwitchState) 90: }
  • 27. 2.5.1 How to Encode Deltas? • Example on how to encode text changes (diff patch) 83: // 84: // Toggles the private ivar `_lightSwitchState` boolean, updates the 85: // background image, plays a sound and transmits the change over network. 86: // 87: func toggleAndSendLightSwitchState() { 88: self.lightSwitchState = !self.lightSwitchState > 89: self.lightSwitchClient?.sendLightSwitchState(self.lightSwitchState) 90: } --- 89: self.lightSwitchClient.sendLightSwitchState(self.lightSwitchState) +++ 89: self.lightSwitchClient?.sendLightSwitchState(self.lightSwitchState)
  • 28. 2.5.1 How to Encode Deltas? • Example on how to encode text changes (insert operation) 83: // 84: // Toggles the private ivar `_lightSwitchState` boolean, updates the 85: // background image, plays a sound and transmits the change over network. 86: // 87: func toggleAndSendLightSwitchState() { 88: self.lightSwitchState = !self.lightSwitchState > 89: self.lightSwitchClient?.sendLightSwitchState(self.lightSwitchState) 90: } { type: "insert", offset: 2781, values: [ "?" ] }
  • 29. 2.5.1 How to Encode Deltas? • Example on how to encode custom data model changes { guests: [ "Alex", "Blake", "Caroline", "Dan", "Emily", "George" ] }
  • 30. 2.5.1 How to Encode Deltas? • Example on how to encode custom data model changes { guests: [ "Alex", "Blake", "Caroline", "Dan", "Emily", "George" ] } { type: "delete", guest: [ "Blake" ] } { guests: [ "Alex", "Caroline", "Dan", "Emily", "George" ] }
  • 31. 3. Stream Based Synchronization
  • 32. 3.1 The Motivation • Minimum data redundancy
  • 33. 3.1 The Motivation • Speed / minimum bandwidth
  • 34. 3.1 The Motivation • Fast writes = good concurrency characteristics
  • 35. 3.1 The Motivation • Distributability and scalability
  • 36. 3.1 The Motivation • Offline support
  • 37. 3.2 Stream of Mutations • Clients with an open connection receive a live stream of events from the server
  • 38. 3.2 Stream of Mutations • Clients with an open connection receive a live stream of events from the server
  • 39. 3.2 Stream of Mutations • Example "To Do" app
  • 40. 3.2.1 Example (To-do List App Data-model) • Live synchronized list of to-do tasks public struct Todo { public class List: NSObject { private let tasks: Array<Task> = [] } }
  • 41. 3.2.1 Example (To-do List App Data-model) • Live synchronized list of to-do tasks • Task element consists of: checkbox, label and color public struct Todo { public class List: NSObject { private let tasks: Array<Task> = [] } } public struct Todo { public class Task: NSObject { public private(set) var identifier: NSUUID public private(set) var completed: Bool public private(set) var title: String public private(set) var label: ColorLabel public enum ColorLabel: UInt8 { case None = 0, Red, Orange, Yellow, Green, Turquoise, Blue, Purple, Pink } } }
  • 42. 3.2.1 Example (To-do List App Data-model) • Live synchronized list of to-do tasks • Task element consists of: checkbox, label and color • Tasks can be added, edited and removed public struct Todo { public class List: NSObject { private let tasks: Array<Task> = [] public func create(title: String, label: Task.ColorL public func update(identifier: NSUUID, completed: Bo public func remove(identifier: NSUUID) } } public struct Todo { public class Task: NSObject { public private(set) var identifier: NSUUID public private(set) var completed: Bool public private(set) var title: String public private(set) var label: ColorLabel public enum ColorLabel: UInt8 { case None = 0, Red, Orange, Yellow, Green, Turquoise, Blue, Purple, Pink } } }
  • 43. 3.2.1 Example (To-do List App Data-model) • Live synchronized list of to-do tasks • Task element consists of: checkbox, label and color • Tasks can be added, edited and removed
  • 44. 3.2.2 Example (To-do List Sync Data-model) • Todo.List user actions turn into events (𝚫)
  • 45. 3.2.2 Example (To-do List Sync Data-model) • Todo.List user actions turn into events (𝚫) • Simple concrete objects describing changes public struct Sync { public class Event: NSObject { public enum Type: UInt8 { case Insert = 0, Update, Delete } public private(set) var type: Type public private(set) var identifier: NSUUID public private(set) var completed: Bool? public private(set) var title: String? public private(set) var label: Int? } }
  • 46. 3.2.2 Example (To-do List Sync Data-model) • Todo.List user actions turn into events (𝚫) • Simple concrete objects describing changes • Serializable public struct Sync { public class Event: NSObject, Serializable { public enum Type: UInt8 { case Insert = 0, Update, Delete } public private(set) var type: Type public private(set) var identifier: NSUUID public private(set) var completed: Bool? public private(set) var title: String? public private(set) var label: Int? } } public protocol Serializable: class { init(fromDictionary dictionary: Dictionary<String, AnyObject>) func toDictionary() -> Dictionary<String, AnyObject> }
  • 47. 3.2.2 Example (To-do List Sync Data-model) • Todo.List user actions turn into events (𝚫) • Simple concrete objects describing changes • Serializable
  • 48. 3.2.2 Example (To-do List Sync Data-model) • Creating new task { // serialized event structure type: 0, // 0 = Insert identifier: "cb55ceec-b9ae-4bd9-8783-7dbf3e9cb2cd", // client generated id completed: false, // an incomplete task title: "Buy Milk", // task description label: 0 // color tag }
  • 49. 3.2.2 Example (To-do List Sync Data-model) • Editing an existing task { // event structure type: 1, // 1 = Update identifier: "cb55ceec-b9ae-4bd9-8783-7dbf3e9cb2cd", // reference to task completed: true // new state }
  • 50. 3.2.3 Example (To-do List Sync and Transport) • Receive live serialized Events from the server. public protocol TransportDelegate: class { func transport(transport: Transport, didReceiveObject object: Serializable) func transportDidConnect(transport: Transport) func transportDidDisconnect(transport: Transport) } public struct Sync { public class Client: NSObject, TransportDelegate { public private(set) var stream: Stream = Stream() public private(set) var transport: Transport public private(set) var todoList: Todo.List public private(set) var publishedEvents: Array<Event> = [] private func publish(event: Event) -> Bool public func transport(transport: Transport, didReceiveObject object: Serializab } }
  • 51. 3.2.3 Example (To-do List Sync and Transport) • Receive live serialized Events from the server. • Send serialized Events to server. public protocol TransportDelegate: class { func transport(transport: Transport, didReceiveObject object: Serializable) func transportDidConnect(transport: Transport) func transportDidDisconnect(transport: Transport) } public struct Sync { public class Client: NSObject, TransportDelegate { public private(set) var stream: Stream = Stream() public private(set) var transport: Transport public private(set) var todoList: Todo.List public private(set) var publishedEvents: Array<Event> = [] private func publish(event: Event) -> Bool public func transport(transport: Transport, didReceiveObject object: Serializab } }
  • 52. 3.2.3 Example (To-do List Sync and Transport) • Receive live serialized Events from the server. • Send serialized Events to server.
  • 53. 3.3 Let the Streaming Begin • Data consistent, as long as clients remain connected
  • 54. 3.3 Let the Streaming Begin • Missing out on events puts the client out-of-sync
  • 55. 3.3 Let the Streaming Begin • Missing out on events puts the client out-of-sync { // event structure type: 1, identifier: "cb55ceec-b9ae-4bd9-8783-7dbf3e9cb2cd", completed: true }
  • 56. 3.3 Let the Streaming Begin • Data consistent, as long as clients remain connected • Missing out on events puts the client out-of-sync • Clients can recover from out-of-sync state • Server's responsibility beside broadcasting should also be preserving the events
  • 58. 3.4 Persistent Stream • Think of it as a linear magnetic tape, or as a storage with a WORM behavior • Append only • Immutable events • Journal of all the events that have happened
  • 59. 3.4 Persistent Stream • Always copy all the events? (too expensive) • Integrity check by hashing events? (only detects mismatches) How does a client know if it's got all the events?
  • 61. 3.5 Event Discovery • Sequencing Events on server
  • 62. 3.5 Event Discovery • Sequencing Events on server public struct Sync { public class Event: NSObject { public private(set) var seq: Int? public private(set) var type: Type public private(set) var identifier: NSUUID? public private(set) var completed: Bool? public private(set) var title: String? public private(set) var label: Int? } }
  • 63. 3.5 Event Discovery • Sequencing Events on server • Sequence is a linear function f(x)=x reproducible on client
  • 64. 3.5 Event Discovery • Sequencing Events on server • Sequence is a linear function f(x)=x reproducible on client
  • 65. 3.5 Event Discovery • Client only needs to know the seq value of
 the last event f(x<12)=x
  • 66. 3.5 Event Discovery • Client only needs to know the seq value of
 the last event f(x<12)=x • Figuring out missing events by subtracting the set of seqs
  • 67. 3.5 Event Discovery // Seq values pulled from all events the client has. // [ 0, 1, 2, 10, 11, 12 ] let seqsOfEvents: Set = events.map({ $0.seq }) // Calculated sequence ranging from 0 to 12. // [ 0, 1, 2, 3 ... 12 ] let seqsOfAllEvents: Set = [Int](0...12) // Diffed set of seq values. // [ 3, 4, 5, 6, 7, 8, 9 ] let seqsOfMissingEvents: Set = seqOfAllEvents.subtract(seqOfEvents) • Client only needs to know the seq value of
 the last event f(x<12)=x • Figuring out missing events by subtracting the set of seqs
  • 68. 4. Event and Model Reconciliation Outbound and inbound reconciliation
  • 69. 4.1 Outbound Reconciliation • Turning user actions (model changes) into Events
  • 70. 4.1 Outbound Reconciliation • Turning user actions (model changes) into Events
  • 71. 4.1 Outbound Reconciliation • Turning user actions (model changes) into Events
  • 72. 4.1 Outbound Reconciliation • Turning user actions (model changes) into Events
  • 73. 4.1 Outbound Reconciliation • Turning user actions (model changes) into Events public class List: NSObject { public func create(title: String, label: Task.ColorLabel) -> Sync.Event public func update(identifier: NSUUID, completed: Bool?, title: String?, label: Task.ColorLabel?) -> Sync.Event? public func remove(identifier: NSUUID) -> Sync.Event? }
  • 74. 4.1 Outbound Reconciliation • Turning user actions (model changes) into Events let todoList = List() let event = todoList.create("Buy Milk", label: Task.ColorLabel.None) print("event: '(event)", event) // event: { // type: 0, // 0 = Insert // identifier: "cb55ceec-b9ae-4bd9-8783-7dbf3e9cb2cd", // client generated id // completed: false, // an incomplete task // title: "Buy milk", // task description // label: 0 // task without a label // }
  • 75. 4.1 Outbound Reconciliation • Publishing events let todoList = List() let event = todoList.create("Buy Milk", label: Task.ColorLabel.None) print("event: '(event)", event) // event: { // type: 0, // 0 = Insert // identifier: "cb55ceec-b9ae-4bd9-8783-7dbf3e9cb2cd", // client generated id // completed: false, // an incomplete task // title: "Buy milk", // task description // label: 0 // task without a label // } // Sends the event to the stream over the network. self.syncClient.publish(event)
  • 76. 4.2 Inbound Reconciliation • Apply Events onto the model
  • 77. 4.2 Inbound Reconciliation • Apply Events onto the model public class List: NSObject { private func apply(event: Sync.Event) -> Bool { switch event.type { case .Insert: // Task creation let task = Task(identifier: event.identifier, completed: event.completed!, title: event.title!, label: Task.ColorL self.tasks.append(task) case .Update: // Task updates let task = self.task(event.identifier) if task == nil { return false } task!.update(event.completed!, title: event.title!, label: Task.ColorLabel(rawValue: event.label!)!) case .Delete: // Task removal if !self.removeTask(event.identifier) { return false } } return true } }
  • 78. 4.3 Offline Support • Events generated offline have to be published eventually
  • 79. 4.3 Offline Support • Queue generated events; drain queue for publication
  • 80. ✔ 4.3 Offline Support • Generating redundant events while offline
  • 81. ✔ 4.3 Offline Support • Generating redundant events while offline
  • 82. 4.4 Reducing the Edit Distance • Events describing the same mutation
  • 83. 4.4 Reducing the Edit Distance • Causes stream pollution • Increases the edit distance
  • 84. 4.4 Reducing the Edit Distance 1. Insert Event merges with
 Update Events → single Insert Event 2. Update Event merge with
 the rest of Update Events → single Update Event 3. Last Update Event defines final state. 4. Delete Event clobbers other Event types Simple set of rules when queueing:
  • 85. 4.4 Reducing the Edit Distance public struct Sync { public class Event: NSObject, Serializable { var mergedEvents = Array<Event>() for oldEvent in events.reverse() { if oldEvent.identifier != self.identifier { // Event not mergeable, due to the identifier mismatch. mergedEvents.append(oldEvent) continue } else if self.type == Type.Delete { // Rule #4 self.reset() self.type = Type.Delete } else if self.type == Type.Update && (oldEvent.type == Type.Insert || oldEvent.type == Type.Update) { // Rule #1, #2, #3 self.completed = self.completed ?? oldEvent.completed self.title = self.title ?? oldEvent.title self.label = self.label ?? oldEvent.label } } mergedEvents.append(self) return mergedEvents } }
  • 86. 4.5 Conflict Resolution • Concurrent systems experience conflicts when two or more nodes (clients) work on the same resource at the same time.
  • 87. 4.5 Conflict Resolution • Concurrent systems experience conflicts when two or more nodes (clients) work on the same resource at the same time. • Example: a client deletes a Todo Task before another client tries to mutate it.
  • 88. 4.5 Conflict Resolution Possible conflict resolutions: • Bring the deleted task back (last writer wins) • Deleted task stays deleted (first writer wins) • Ask the User what to do? (requires user interaction)
  • 89. 5. Order of Events
  • 90. 5. Order of Events Event sequence dictates the order they were written to
 stream this puts the Events in total order • Task objects will be in the exact same order, defined by
 the Event.seq • Task mutations will be applied in the same manner on all clients
  • 91. 5. Order of Events (total order) • Queued events must be published in batches
  • 92. 5. Order of Events (total order) • Queued events must be published in batches
  • 93. 5. Order of Events (total order) • Queued events must be published in batches
  • 94. 5. Order of Events (total order) • Queued events must be published in batches
  • 95. 5.1 Total Order (sequential writes) • Synchronized sequential writes block other clients from writing
  • 96. 5.1 Total Order (sequential writes) • Synchronized sequential writes block other clients from writing - violates our fast concurrent writes requirement serial writes concurrent writes
  • 97. 5.1 Total Order (offline support) • Both clients online
  • 98. 5.1 Total Order (offline support) • Both clients online
  • 99. 5.1 Total Order (offline support) • Left client loses connection
  • 100. 5.1 Total Order (offline support) • Offline client adds more To-do tasks to the list
  • 101. 5.1 Total Order (offline support) • Online client also adds a Todo task to the list
  • 102. 5.1 Total Order (offline support) • Left client comes back online ― events generated offline get published and fall at the end (higher seq values)
  • 103. 5.2 Causal Order Causes must precede their effects - effects come after causes, and never before
  • 104. 5.2 Causal Order Causes must precede their effects - effects come after causes, and never before cause effect
  • 105. 5.2 Causal Order • Generated Event is an effect caused by user taking action / responding to the UI. • Events should be reconciled in the same order as they were generated by clients. • Events should be applied onto the app model under the same conditions as it was when author generated the events. • Total order cannot guarantee Events will be written to stream in the same order they were generated.
  • 106. 5.2.1 Order Based on Timestamps Client B's events are written before Client A's, even though Client A generated them first.
  • 107. Encoding local time with events. 5.2.1 Order Based on Timestamps
  • 108. Sorting events based on the embedded timestamp. 5.2.1 Order Based on Timestamps
  • 109. 5.2.1 Order Based on Timestamps • No guarantee time will be the same on all devices • Clock skew • Manual override
  • 110. 5.2.2 Version Vectors • Reconstructing Events' order as it was perceived by the author based on happened-before information. • Provides causality-tracking basic principle in some optimistic (lazy) replication algorithms. • Allows the client to operate independently from the server. • When all clients eventually publish their events, it brings other online clients into a consistent state eventual consistency.
  • 111. 5.2.2 Version Vectors How to encode happened-before information? public struct Sync { public class Event: NSObject { public private(set) var seq: Int? public private(set) var type: Type public private(set) var identifier: NSUUID? public private(set) var completed: Bool? public private(set) var title: String? public private(set) var label: Int? } }
  • 112. 5.2.2 Version Vectors 1. Information of what's the last seen event - event.seq How to encode happened-before information? public struct Sync { public class Event: NSObject { public private(set) var seq: Int? public private(set) var precedingSeq: Int public private(set) var type: Type public private(set) var identifier: NSUUID? public private(set) var completed: Bool? public private(set) var title: String? public private(set) var label: Int? } }
  • 113. 5.2.2 Version Vectors 1. Information of what's the last seen event - event.seq 2. Keep unpublished events in order - event.clientSeq How to encode happened-before information? public struct Sync { public class Event: NSObject { public private(set) var seq: Int? public private(set) var precedingSeq: Int public private(set) var clientSeq: Int public private(set) var type: Type public private(set) var identifier: NSUUID? public private(set) var completed: Bool? public private(set) var title: String? public private(set) var label: Int? } }
  • 114. 5.2.2 Version Vectors 1. Information of what's the last seen event - event.seq 2. Keep unpublished events in order - event.clientSeq 3. Order How to encode happened-before information? public struct Sync { public class Event: NSObject { /// Event sorting closure static public let causalOrder = { (e1: Event, e2: Event) if e1.precedingSeq == e2.precedingSeq { return e1.clientSeq < e2.clientSeq } return e1.precedingSeq < e2.precedingSeq } public private(set) var seq: Int? public private(set) var precedingSeq: Int public private(set) var clientSeq: Int public private(set) var type: Type public private(set) var identifier: NSUUID? public private(set) var completed: Bool? public private(set) var title: String? public private(set) var label: Int? } }
  • 121. 5.2.2 Version Vectors public struct Sync { public class Event: NSObject, Serializable { var mergedEvents = Array<Event>() for oldEvent in events.sort(Event.causalOrder) { if oldEvent.identifier != self.identifier { // etc... public struct Todo { public class List: NSObject, ModelReconciler { public func apply(events: Array<Sync.Event>) -> Bool { for event in events.sort(Sync.Event.causalOrder) { let success = self.apply(event) // etc... Minor adjustment in outbound / inbound reconciliation:
  • 122. 5.2.2 Version Vectors • Newly published events generated offline are ordered by their causality.
  • 123. 5.2.2 Version Vectors • Concurrent writes - no need for batched writes anymore,
 due to clientSeq.
  • 124. 5.2.2 Version Vectors • Concurrent writes - events can be written with undetermined order; order can be reconstructed on clients serial writes concurrent writes
  • 126. 6. Advantages • Shared source - minimal redundancy
  • 127. 6. Advantages • Shared source - minimal redundancy • Lightweight data structure - fast delivery
  • 128. 6. Advantages • Shared source - minimal redundancy • Lightweight data structure - fast delivery • Minimal server logic (low CPU)
  • 129. 6. Advantages • Shared source - minimal redundancy • Lightweight data structure - fast delivery • Minimal server logic (low CPU) • Short writes - high concurrency
  • 130. 6. Advantages • Shared source - minimal redundancy • Lightweight data structure - fast delivery • Minimal server logic (low CPU) • Short writes - high concurrency • Scalable / distributable
  • 131. 6. Advantages • Shared source - minimal redundancy • Lightweight data structure - fast delivery • Minimal server logic (low CPU) • Short writes - high concurrency • Scalable / distributable • Offline support
  • 133. 7. Disadvantages • Server simplicity = client complexity
  • 134. 7. Disadvantages • Server simplicity = client complexity • Rogue clients = stream pollution
  • 135. 7. Disadvantages • Server simplicity = client complexity • Rogue clients = stream pollution • Clients must read full stream
  • 136. 7. Disadvantages • Server simplicity = client complexity • Rogue clients = stream pollution • Clients must read full stream • Partial sync difficult to implement