SlideShare a Scribd company logo
THE STORY OF ADI
Meet
Adi Awanta.
He has a dream.
Adi is fashionable
• Event sourcing is
the future, they say
• Event sourcing is
the shit, he agrees
Adi is fashionable
• Event sourcing is
the future, they say
• Event sourcing is
the shit, he agrees
• … and designs an
event model
Created
Modified
Published
Archived
Restored
Column Type Key Null
site_id binary(16)
event_time timestamp
event_type enum(…)
payload mediumblob
Adi is fashionable
HEY, KIDS
Can you guess what happens next?
Adi is confused
• Bad shit happens
• Event streams exhibit:
– Out of order events
– Conflicting events
– Impossible states
How shit works:
Time
Tomer Gabel
Wix Engineering Conference
May 2017
Image: Vera Kratochvil (public domain)
Time (noun)
“… the system of those sequential
relations that any event has to any other,
as past, present, or future; indefinite and
continuous duration regarded as that in
which events succeed one another.”
-- dictionary.com
Time (noun)
“… the system of those sequential
relations that any event has to any other,
as past, present, or future; indefinite and
continuous duration regarded as that in
which events succeed one another.”
-- dictionary.com
Modeling time
• Encoding
– Resolution
– Epoch
“Real” time
Epoch
Resolution
T1 T2 T3 … Tn
Modeling time
• Encoding
– Resolution
– Epoch
T3
Instant
(or “event”)
Modeling time
• Encoding
– Resolution
– Epoch
T3
A
B
Conflicting
events
Modeling time
• Encoding
– Resolution
– Epoch
• Bootstrapping
– Manual
– Battery-backed
– NTP
Epoch
???
Modeling time
• Encoding
– Resolution
– Epoch
• Bootstrapping
– Manual
– Battery-backed
– NTP
• Updating
T1 T2
Modeling time
• Encoding
– Resolution
– Epoch
• Bootstrapping
– Manual
– Battery-backed
– NTP
• Updating T = T+1
T1 T2
W
hen?
System Clock (RTC)
Modeling time
• Encoding
– Resolution
– Epoch
• Bootstrapping
– Manual
– Battery-backed
– NTP
• Updating
Image: Jeremy Saglimbeni on Vimeo (CC BY-SA 3.0)
RTC isn’t perfect
• Alas, clocks drift
• Subtle causes
– Temperature
– Power supply
– General relativity
– Cosmic radiation
– Alien gamma rays
Image showing ~220µs clock drift by Luke Bigum
Distributed time
Host A
Host C
Host B
Host D
RTC RTC
RTC RTC
Event Stream Event
Store
RTC
event_time = ?
Time source: Application
Host A
Host C
Host B
Host D
RTC RTC
RTC RTC
Event Stream Event
Store
RTC
1
2
3
4
Time source: Application
Host A
Host C
Host B
Host D
RTC RTC
RTC RTC
Event Stream Event
Store
RTC
1
2
3
4
Clocks must be
synchronized!
What about NTP?
Host A
Host C
Host B
Host D
RTC RTC
RTC RTC
Event
Store
RTC
NTP
What about NTP?
Host A
Host C
Host B
Host D
RTC RTC
RTC RTC
Event
Store
RTC
NTP
Accurate within
~10ms
Fig. 1, “Characterizing Quality of Time and Topology in a Time Synchronization Network”, Murta et al
DEALING WITH TIME IS HARD
TL;DR
Reframing the problem
• When reading events
– Do we need wall time?
– We don’t care about it
– It’s just metadata
• We only care about
ordering events
Created
(2017-05-03 10:15)
Updated
(2017-05-03 10:27)
Archived
(2017-05-03 10:55)
Reprise: Time (noun)
“… the system of those sequential
relations that any event has to any other,
as past, present, or future; indefinite and
continuous duration regarded as that in
which events succeed one another.”
-- dictionary.com
Reprise: Time (noun)
“… the system of those sequential
relations that any event has to any other,
as past, present, or future; indefinite and
continuous duration regarded as that in
which events succeed one another.”
-- dictionary.com
Causality
• Take any two events
• What relationship can
they have?
Created
Updated Updated
Archived
Causality
• Take any two events
• What relationship can
they have?
– Happens before: A→B
A. Created
B. Updated Updated
Archived
Causality
• Take any two events
• What relationship can
they have?
– Happens before: A→B
– Concurrent: A↛B and
B↛A
Created
A. Updated B. Updated
Archived
Lamport timestamps
• Provides partial
ordering of events
• Advantages:
– Respects causality
– Low overhead
– Simple to implement
Event
Store
Host
A
Host
C
Host
B
“Time, Clocks, and the Ordering of Events in a Distributed System”, Leslie Lamport, 1978
Event
Store
Host
A
Host
C
Host
B
Lamport timestamps
• Each host maintains
local logical clock
• Start with T=0
T=0
T=0T=0
Event
Store
Host
A
Host
C
Host
B
Lamport timestamps
• Each host maintains
local logical clock
• Start with T=0
• On send (i.e. write):
– Increment local clock
– Attach to message
T=0
T=0T=0
T=1
Lamport timestamps
• On receive (i.e. read):
– Process event if T < Tin
Event
Store
Host
A
Host
C
Host
B
T=0
Tin=1
Lamport timestamps
• On receive (i.e. read):
– Process event if T < Tin
– Update clock past the
latest event:
T = max(T, Tin) + 1
• All done!
Event
Store
Host
A
Host
C
Host
B
T=0
Tin=1
T=2
… well, almost
• This is a partial order
• Causality is dealt with
– A→B ⇒ T(A) < T(B)
• What about concurrency?
– A↛B and B↛A ⇒ ?
Final touches
• We want total ordering
– Must be stable
– Need not correspond to
real time
Created
Updated Updated
Archived
T=1
T=5
T=2T=2
Final touches
• We want total ordering
– Must be stable
– Need not correspond to
real time
• Breaking the tie:
– Use any consistent key
– Host name, MAC, IP…
Created
Updated Updated
Archived
T=1
T=5
T=2T=2
What did we gain?
• We can assign versions that…
– Respect causality
– Are totally ordered
– Don’t rely on the RTC
• We’ve enabled serializability!
MAKE ADI
GREAT AGAIN!
Enough theory. Let’s
Versioning
• Our versioning
mechanism must:
– Respect causality
– Detect conflicting
writes
– Not rely on wall time
• We’re almost there!
Relax
• It’s fairly simple
in practice
• First, the schema
Column Type Key Null
site_id binary(16)
event_time timestamp
event_type enum(…)
payload mediumblob
Relax
• It’s fairly simple
in practice
• First, the schema
– Don’t key on
timestamp
Column Type Key Null
site_id binary(16)
event_time timestamp
event_type enum(…)
payload mediumblob
Relax
• It’s fairly simple
in practice
• First, the schema
– Don’t key on
timestamp
– Add explicit
version
Column Type Key Null
site_id binary(16)
version mediumint
event_time timestamp
event_type enum(…)
payload mediumblob
Finishing touches
• On writes:
MySQL
Server
Client
C1-Cn
Finishing touches
• On writes:
– Read latest version V0
MySQL
Server
Client
C1-Cn
V0
Finishing touches
• On writes:
– Read latest version V0
– Generate events V1...Vn
– Write atomically
MySQL
Server
Client
C1-Cn
V1-Vn
Finishing touches
• On writes:
– Read latest version V0
– Generate events V1...Vn
– Write atomically
• Success!
– Return new version
MySQL
Server
Client
C1-Cn
V1-Vn
Vn
Finishing touches
• On writes:
– Read latest version V0
– Generate events V1...Vn
– Write atomically
• Duplicate primary key?
– Optimistic lock failure!
– Retry, propagate, resolve
MySQL
Server
Client
C1-Cn
V1-Vn
Error
PK violation
GREAT
SUCCESS!
KFIR ‘ADI’ BLOCH
A round of applause
for our special guest:
... and for the terrific
camera work I butchered:
VAIDAS PILKAUSKAS
QUESTIONS?
Thank you for listening
tomer@tomergabel.com
@tomerg
http://engineering.wix.com
On GitHub:
https://github.com/holograph
This work is licensed under a Creative
Commons Attribution-ShareAlike 4.0
International License.

More Related Content

Similar to How shit works: Time

Chapter 6-Synchronozation2.ppt
Chapter 6-Synchronozation2.pptChapter 6-Synchronozation2.ppt
Chapter 6-Synchronozation2.ppt
MeymunaMohammed1
 
Time and ordering in streaming distributed systems
Time and ordering in streaming distributed systemsTime and ordering in streaming distributed systems
Time and ordering in streaming distributed systems
Zhenzhong Xu
 
Puniani, Arjan Singh | Candidate Time-Delayed Decryption Protocols for Deploy...
Puniani, Arjan Singh | Candidate Time-Delayed Decryption Protocols for Deploy...Puniani, Arjan Singh | Candidate Time-Delayed Decryption Protocols for Deploy...
Puniani, Arjan Singh | Candidate Time-Delayed Decryption Protocols for Deploy...
Arjan
 
Lifting the hood on spark streaming - StampedeCon 2015
Lifting the hood on spark streaming - StampedeCon 2015Lifting the hood on spark streaming - StampedeCon 2015
Lifting the hood on spark streaming - StampedeCon 2015
StampedeCon
 
The maths behind microscaling
The maths behind microscalingThe maths behind microscaling
The maths behind microscaling
Liz Rice
 
slides.06.pptx
slides.06.pptxslides.06.pptx
slides.06.pptx
balewayalew
 
Realtime Analytics
Realtime AnalyticsRealtime Analytics
Realtime Analytics
eXascale Infolab
 
Corbett osdi12 slides (1)
Corbett osdi12 slides (1)Corbett osdi12 slides (1)
Corbett osdi12 slides (1)
Aksh54
 
Spanner (may 19)
Spanner (may 19)Spanner (may 19)
Spanner (may 19)
Sultan Ahmed
 
Storm: a distributed ,fault tolerant ,real time computation
Storm: a distributed ,fault tolerant ,real time computationStorm: a distributed ,fault tolerant ,real time computation
Storm: a distributed ,fault tolerant ,real time computation
Nitin Guleria
 
L12.FA20.ppt
L12.FA20.pptL12.FA20.ppt
L12.FA20.ppt
MAliHaider4
 
Is this normal?
Is this normal?Is this normal?
Is this normal?
Theo Schlossnagle
 
Actors for Behavioural Simulation
Actors for Behavioural SimulationActors for Behavioural Simulation
Actors for Behavioural Simulation
ClarkTony
 
Eventually, time will kill your data pipeline
Eventually, time will kill your data pipelineEventually, time will kill your data pipeline
Eventually, time will kill your data pipeline
Lars Albertsson
 
Spanner osdi2012
Spanner osdi2012Spanner osdi2012
Spanner osdi2012
Jose Maria Fuster
 
Principles in Data Stream Processing | Matthias J Sax, Confluent
Principles in Data Stream Processing | Matthias J Sax, ConfluentPrinciples in Data Stream Processing | Matthias J Sax, Confluent
Principles in Data Stream Processing | Matthias J Sax, Confluent
HostedbyConfluent
 
Functional Programming with Immutable Data Structures
Functional Programming with Immutable Data StructuresFunctional Programming with Immutable Data Structures
Functional Programming with Immutable Data Structures
elliando dias
 
Computer network (8)
Computer network (8)Computer network (8)
Computer network (8)
NYversity
 
Extracting City Traffic Events from Social Streams
 Extracting City Traffic Events from Social Streams Extracting City Traffic Events from Social Streams
Extracting City Traffic Events from Social Streams
Pramod Anantharam
 

Similar to How shit works: Time (20)

Chapter 6-Synchronozation2.ppt
Chapter 6-Synchronozation2.pptChapter 6-Synchronozation2.ppt
Chapter 6-Synchronozation2.ppt
 
Time and ordering in streaming distributed systems
Time and ordering in streaming distributed systemsTime and ordering in streaming distributed systems
Time and ordering in streaming distributed systems
 
Puniani, Arjan Singh | Candidate Time-Delayed Decryption Protocols for Deploy...
Puniani, Arjan Singh | Candidate Time-Delayed Decryption Protocols for Deploy...Puniani, Arjan Singh | Candidate Time-Delayed Decryption Protocols for Deploy...
Puniani, Arjan Singh | Candidate Time-Delayed Decryption Protocols for Deploy...
 
Lifting the hood on spark streaming - StampedeCon 2015
Lifting the hood on spark streaming - StampedeCon 2015Lifting the hood on spark streaming - StampedeCon 2015
Lifting the hood on spark streaming - StampedeCon 2015
 
Chapter 10
Chapter 10Chapter 10
Chapter 10
 
The maths behind microscaling
The maths behind microscalingThe maths behind microscaling
The maths behind microscaling
 
slides.06.pptx
slides.06.pptxslides.06.pptx
slides.06.pptx
 
Realtime Analytics
Realtime AnalyticsRealtime Analytics
Realtime Analytics
 
Corbett osdi12 slides (1)
Corbett osdi12 slides (1)Corbett osdi12 slides (1)
Corbett osdi12 slides (1)
 
Spanner (may 19)
Spanner (may 19)Spanner (may 19)
Spanner (may 19)
 
Storm: a distributed ,fault tolerant ,real time computation
Storm: a distributed ,fault tolerant ,real time computationStorm: a distributed ,fault tolerant ,real time computation
Storm: a distributed ,fault tolerant ,real time computation
 
L12.FA20.ppt
L12.FA20.pptL12.FA20.ppt
L12.FA20.ppt
 
Is this normal?
Is this normal?Is this normal?
Is this normal?
 
Actors for Behavioural Simulation
Actors for Behavioural SimulationActors for Behavioural Simulation
Actors for Behavioural Simulation
 
Eventually, time will kill your data pipeline
Eventually, time will kill your data pipelineEventually, time will kill your data pipeline
Eventually, time will kill your data pipeline
 
Spanner osdi2012
Spanner osdi2012Spanner osdi2012
Spanner osdi2012
 
Principles in Data Stream Processing | Matthias J Sax, Confluent
Principles in Data Stream Processing | Matthias J Sax, ConfluentPrinciples in Data Stream Processing | Matthias J Sax, Confluent
Principles in Data Stream Processing | Matthias J Sax, Confluent
 
Functional Programming with Immutable Data Structures
Functional Programming with Immutable Data StructuresFunctional Programming with Immutable Data Structures
Functional Programming with Immutable Data Structures
 
Computer network (8)
Computer network (8)Computer network (8)
Computer network (8)
 
Extracting City Traffic Events from Social Streams
 Extracting City Traffic Events from Social Streams Extracting City Traffic Events from Social Streams
Extracting City Traffic Events from Social Streams
 

More from Tomer Gabel

Nondeterministic Software for the Rest of Us
Nondeterministic Software for the Rest of UsNondeterministic Software for the Rest of Us
Nondeterministic Software for the Rest of Us
Tomer Gabel
 
Slaying Sacred Cows: Deconstructing Dependency Injection
Slaying Sacred Cows: Deconstructing Dependency InjectionSlaying Sacred Cows: Deconstructing Dependency Injection
Slaying Sacred Cows: Deconstructing Dependency Injection
Tomer Gabel
 
An Abridged Guide to Event Sourcing
An Abridged Guide to Event SourcingAn Abridged Guide to Event Sourcing
An Abridged Guide to Event Sourcing
Tomer Gabel
 
How shit works: the CPU
How shit works: the CPUHow shit works: the CPU
How shit works: the CPU
Tomer Gabel
 
How Shit Works: Storage
How Shit Works: StorageHow Shit Works: Storage
How Shit Works: Storage
Tomer Gabel
 
Java 8 and Beyond, a Scala Story
Java 8 and Beyond, a Scala StoryJava 8 and Beyond, a Scala Story
Java 8 and Beyond, a Scala Story
Tomer Gabel
 
The Wix Microservice Stack
The Wix Microservice StackThe Wix Microservice Stack
The Wix Microservice Stack
Tomer Gabel
 
Scala Refactoring for Fun and Profit (Japanese subtitles)
Scala Refactoring for Fun and Profit (Japanese subtitles)Scala Refactoring for Fun and Profit (Japanese subtitles)
Scala Refactoring for Fun and Profit (Japanese subtitles)
Tomer Gabel
 
Scala Refactoring for Fun and Profit
Scala Refactoring for Fun and ProfitScala Refactoring for Fun and Profit
Scala Refactoring for Fun and Profit
Tomer Gabel
 
Onboarding at Scale
Onboarding at ScaleOnboarding at Scale
Onboarding at Scale
Tomer Gabel
 
Scala in the Wild
Scala in the WildScala in the Wild
Scala in the Wild
Tomer Gabel
 
Speaking Scala: Refactoring for Fun and Profit (Workshop)
Speaking Scala: Refactoring for Fun and Profit (Workshop)Speaking Scala: Refactoring for Fun and Profit (Workshop)
Speaking Scala: Refactoring for Fun and Profit (Workshop)
Tomer Gabel
 
Put Your Thinking CAP On
Put Your Thinking CAP OnPut Your Thinking CAP On
Put Your Thinking CAP On
Tomer Gabel
 
Leveraging Scala Macros for Better Validation
Leveraging Scala Macros for Better ValidationLeveraging Scala Macros for Better Validation
Leveraging Scala Macros for Better Validation
Tomer Gabel
 
A Field Guide to DSL Design in Scala
A Field Guide to DSL Design in ScalaA Field Guide to DSL Design in Scala
A Field Guide to DSL Design in Scala
Tomer Gabel
 
Functional Leap of Faith (Keynote at JDay Lviv 2014)
Functional Leap of Faith (Keynote at JDay Lviv 2014)Functional Leap of Faith (Keynote at JDay Lviv 2014)
Functional Leap of Faith (Keynote at JDay Lviv 2014)
Tomer Gabel
 
Scala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesScala Back to Basics: Type Classes
Scala Back to Basics: Type Classes
Tomer Gabel
 
5 Bullets to Scala Adoption
5 Bullets to Scala Adoption5 Bullets to Scala Adoption
5 Bullets to Scala Adoption
Tomer Gabel
 
Nashorn: JavaScript that doesn’t suck (ILJUG)
Nashorn: JavaScript that doesn’t suck (ILJUG)Nashorn: JavaScript that doesn’t suck (ILJUG)
Nashorn: JavaScript that doesn’t suck (ILJUG)
Tomer Gabel
 
Ponies and Unicorns With Scala
Ponies and Unicorns With ScalaPonies and Unicorns With Scala
Ponies and Unicorns With Scala
Tomer Gabel
 

More from Tomer Gabel (20)

Nondeterministic Software for the Rest of Us
Nondeterministic Software for the Rest of UsNondeterministic Software for the Rest of Us
Nondeterministic Software for the Rest of Us
 
Slaying Sacred Cows: Deconstructing Dependency Injection
Slaying Sacred Cows: Deconstructing Dependency InjectionSlaying Sacred Cows: Deconstructing Dependency Injection
Slaying Sacred Cows: Deconstructing Dependency Injection
 
An Abridged Guide to Event Sourcing
An Abridged Guide to Event SourcingAn Abridged Guide to Event Sourcing
An Abridged Guide to Event Sourcing
 
How shit works: the CPU
How shit works: the CPUHow shit works: the CPU
How shit works: the CPU
 
How Shit Works: Storage
How Shit Works: StorageHow Shit Works: Storage
How Shit Works: Storage
 
Java 8 and Beyond, a Scala Story
Java 8 and Beyond, a Scala StoryJava 8 and Beyond, a Scala Story
Java 8 and Beyond, a Scala Story
 
The Wix Microservice Stack
The Wix Microservice StackThe Wix Microservice Stack
The Wix Microservice Stack
 
Scala Refactoring for Fun and Profit (Japanese subtitles)
Scala Refactoring for Fun and Profit (Japanese subtitles)Scala Refactoring for Fun and Profit (Japanese subtitles)
Scala Refactoring for Fun and Profit (Japanese subtitles)
 
Scala Refactoring for Fun and Profit
Scala Refactoring for Fun and ProfitScala Refactoring for Fun and Profit
Scala Refactoring for Fun and Profit
 
Onboarding at Scale
Onboarding at ScaleOnboarding at Scale
Onboarding at Scale
 
Scala in the Wild
Scala in the WildScala in the Wild
Scala in the Wild
 
Speaking Scala: Refactoring for Fun and Profit (Workshop)
Speaking Scala: Refactoring for Fun and Profit (Workshop)Speaking Scala: Refactoring for Fun and Profit (Workshop)
Speaking Scala: Refactoring for Fun and Profit (Workshop)
 
Put Your Thinking CAP On
Put Your Thinking CAP OnPut Your Thinking CAP On
Put Your Thinking CAP On
 
Leveraging Scala Macros for Better Validation
Leveraging Scala Macros for Better ValidationLeveraging Scala Macros for Better Validation
Leveraging Scala Macros for Better Validation
 
A Field Guide to DSL Design in Scala
A Field Guide to DSL Design in ScalaA Field Guide to DSL Design in Scala
A Field Guide to DSL Design in Scala
 
Functional Leap of Faith (Keynote at JDay Lviv 2014)
Functional Leap of Faith (Keynote at JDay Lviv 2014)Functional Leap of Faith (Keynote at JDay Lviv 2014)
Functional Leap of Faith (Keynote at JDay Lviv 2014)
 
Scala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesScala Back to Basics: Type Classes
Scala Back to Basics: Type Classes
 
5 Bullets to Scala Adoption
5 Bullets to Scala Adoption5 Bullets to Scala Adoption
5 Bullets to Scala Adoption
 
Nashorn: JavaScript that doesn’t suck (ILJUG)
Nashorn: JavaScript that doesn’t suck (ILJUG)Nashorn: JavaScript that doesn’t suck (ILJUG)
Nashorn: JavaScript that doesn’t suck (ILJUG)
 
Ponies and Unicorns With Scala
Ponies and Unicorns With ScalaPonies and Unicorns With Scala
Ponies and Unicorns With Scala
 

Recently uploaded

Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
zwunae
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
Divya Somashekar
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
Kamal Acharya
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
VENKATESHvenky89705
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
fxintegritypublishin
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 
ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
Vijay Dialani, PhD
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
AafreenAbuthahir2
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
Jayaprasanna4
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
Pratik Pawar
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
BrazilAccount1
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
BrazilAccount1
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
TeeVichai
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
Kerry Sado
 

Recently uploaded (20)

Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
一比一原版(IIT毕业证)伊利诺伊理工大学毕业证成绩单专业办理
 
block diagram and signal flow graph representation
block diagram and signal flow graph representationblock diagram and signal flow graph representation
block diagram and signal flow graph representation
 
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
 
road safety engineering r s e unit 3.pdf
road safety engineering  r s e unit 3.pdfroad safety engineering  r s e unit 3.pdf
road safety engineering r s e unit 3.pdf
 
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdfHybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
Hybrid optimization of pumped hydro system and solar- Engr. Abdul-Azeez.pdf
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 
ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
 
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
H.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdfH.Seo,  ICLR 2024, MLILAB,  KAIST AI.pdf
H.Seo, ICLR 2024, MLILAB, KAIST AI.pdf
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
 
ethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.pptethical hacking-mobile hacking methods.ppt
ethical hacking-mobile hacking methods.ppt
 
weather web application report.pdf
weather web application report.pdfweather web application report.pdf
weather web application report.pdf
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
 
English lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdfEnglish lab ppt no titlespecENG PPTt.pdf
English lab ppt no titlespecENG PPTt.pdf
 
Railway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdfRailway Signalling Principles Edition 3.pdf
Railway Signalling Principles Edition 3.pdf
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
 

How shit works: Time

  • 3. He has a dream.
  • 4. Adi is fashionable • Event sourcing is the future, they say • Event sourcing is the shit, he agrees
  • 5. Adi is fashionable • Event sourcing is the future, they say • Event sourcing is the shit, he agrees • … and designs an event model Created Modified Published Archived Restored
  • 6. Column Type Key Null site_id binary(16) event_time timestamp event_type enum(…) payload mediumblob Adi is fashionable
  • 7. HEY, KIDS Can you guess what happens next?
  • 8. Adi is confused • Bad shit happens • Event streams exhibit: – Out of order events – Conflicting events – Impossible states
  • 9. How shit works: Time Tomer Gabel Wix Engineering Conference May 2017 Image: Vera Kratochvil (public domain)
  • 10. Time (noun) “… the system of those sequential relations that any event has to any other, as past, present, or future; indefinite and continuous duration regarded as that in which events succeed one another.” -- dictionary.com
  • 11. Time (noun) “… the system of those sequential relations that any event has to any other, as past, present, or future; indefinite and continuous duration regarded as that in which events succeed one another.” -- dictionary.com
  • 12. Modeling time • Encoding – Resolution – Epoch “Real” time Epoch Resolution T1 T2 T3 … Tn
  • 13. Modeling time • Encoding – Resolution – Epoch T3 Instant (or “event”)
  • 14. Modeling time • Encoding – Resolution – Epoch T3 A B Conflicting events
  • 15. Modeling time • Encoding – Resolution – Epoch • Bootstrapping – Manual – Battery-backed – NTP Epoch ???
  • 16. Modeling time • Encoding – Resolution – Epoch • Bootstrapping – Manual – Battery-backed – NTP • Updating T1 T2
  • 17. Modeling time • Encoding – Resolution – Epoch • Bootstrapping – Manual – Battery-backed – NTP • Updating T = T+1 T1 T2 W hen?
  • 18. System Clock (RTC) Modeling time • Encoding – Resolution – Epoch • Bootstrapping – Manual – Battery-backed – NTP • Updating Image: Jeremy Saglimbeni on Vimeo (CC BY-SA 3.0)
  • 19. RTC isn’t perfect • Alas, clocks drift • Subtle causes – Temperature – Power supply – General relativity – Cosmic radiation – Alien gamma rays Image showing ~220µs clock drift by Luke Bigum
  • 20. Distributed time Host A Host C Host B Host D RTC RTC RTC RTC Event Stream Event Store RTC event_time = ?
  • 21. Time source: Application Host A Host C Host B Host D RTC RTC RTC RTC Event Stream Event Store RTC 1 2 3 4
  • 22. Time source: Application Host A Host C Host B Host D RTC RTC RTC RTC Event Stream Event Store RTC 1 2 3 4 Clocks must be synchronized!
  • 23. What about NTP? Host A Host C Host B Host D RTC RTC RTC RTC Event Store RTC NTP
  • 24. What about NTP? Host A Host C Host B Host D RTC RTC RTC RTC Event Store RTC NTP Accurate within ~10ms Fig. 1, “Characterizing Quality of Time and Topology in a Time Synchronization Network”, Murta et al
  • 25. DEALING WITH TIME IS HARD TL;DR
  • 26. Reframing the problem • When reading events – Do we need wall time? – We don’t care about it – It’s just metadata • We only care about ordering events Created (2017-05-03 10:15) Updated (2017-05-03 10:27) Archived (2017-05-03 10:55)
  • 27. Reprise: Time (noun) “… the system of those sequential relations that any event has to any other, as past, present, or future; indefinite and continuous duration regarded as that in which events succeed one another.” -- dictionary.com
  • 28. Reprise: Time (noun) “… the system of those sequential relations that any event has to any other, as past, present, or future; indefinite and continuous duration regarded as that in which events succeed one another.” -- dictionary.com
  • 29. Causality • Take any two events • What relationship can they have? Created Updated Updated Archived
  • 30. Causality • Take any two events • What relationship can they have? – Happens before: A→B A. Created B. Updated Updated Archived
  • 31. Causality • Take any two events • What relationship can they have? – Happens before: A→B – Concurrent: A↛B and B↛A Created A. Updated B. Updated Archived
  • 32. Lamport timestamps • Provides partial ordering of events • Advantages: – Respects causality – Low overhead – Simple to implement Event Store Host A Host C Host B “Time, Clocks, and the Ordering of Events in a Distributed System”, Leslie Lamport, 1978
  • 33. Event Store Host A Host C Host B Lamport timestamps • Each host maintains local logical clock • Start with T=0 T=0 T=0T=0
  • 34. Event Store Host A Host C Host B Lamport timestamps • Each host maintains local logical clock • Start with T=0 • On send (i.e. write): – Increment local clock – Attach to message T=0 T=0T=0 T=1
  • 35. Lamport timestamps • On receive (i.e. read): – Process event if T < Tin Event Store Host A Host C Host B T=0 Tin=1
  • 36. Lamport timestamps • On receive (i.e. read): – Process event if T < Tin – Update clock past the latest event: T = max(T, Tin) + 1 • All done! Event Store Host A Host C Host B T=0 Tin=1 T=2
  • 37. … well, almost • This is a partial order • Causality is dealt with – A→B ⇒ T(A) < T(B) • What about concurrency? – A↛B and B↛A ⇒ ?
  • 38. Final touches • We want total ordering – Must be stable – Need not correspond to real time Created Updated Updated Archived T=1 T=5 T=2T=2
  • 39. Final touches • We want total ordering – Must be stable – Need not correspond to real time • Breaking the tie: – Use any consistent key – Host name, MAC, IP… Created Updated Updated Archived T=1 T=5 T=2T=2
  • 40. What did we gain? • We can assign versions that… – Respect causality – Are totally ordered – Don’t rely on the RTC • We’ve enabled serializability!
  • 41. MAKE ADI GREAT AGAIN! Enough theory. Let’s
  • 42. Versioning • Our versioning mechanism must: – Respect causality – Detect conflicting writes – Not rely on wall time • We’re almost there!
  • 43. Relax • It’s fairly simple in practice • First, the schema Column Type Key Null site_id binary(16) event_time timestamp event_type enum(…) payload mediumblob
  • 44. Relax • It’s fairly simple in practice • First, the schema – Don’t key on timestamp Column Type Key Null site_id binary(16) event_time timestamp event_type enum(…) payload mediumblob
  • 45. Relax • It’s fairly simple in practice • First, the schema – Don’t key on timestamp – Add explicit version Column Type Key Null site_id binary(16) version mediumint event_time timestamp event_type enum(…) payload mediumblob
  • 46. Finishing touches • On writes: MySQL Server Client C1-Cn
  • 47. Finishing touches • On writes: – Read latest version V0 MySQL Server Client C1-Cn V0
  • 48. Finishing touches • On writes: – Read latest version V0 – Generate events V1...Vn – Write atomically MySQL Server Client C1-Cn V1-Vn
  • 49. Finishing touches • On writes: – Read latest version V0 – Generate events V1...Vn – Write atomically • Success! – Return new version MySQL Server Client C1-Cn V1-Vn Vn
  • 50. Finishing touches • On writes: – Read latest version V0 – Generate events V1...Vn – Write atomically • Duplicate primary key? – Optimistic lock failure! – Retry, propagate, resolve MySQL Server Client C1-Cn V1-Vn Error PK violation
  • 52. KFIR ‘ADI’ BLOCH A round of applause for our special guest: ... and for the terrific camera work I butchered: VAIDAS PILKAUSKAS
  • 53. QUESTIONS? Thank you for listening tomer@tomergabel.com @tomerg http://engineering.wix.com On GitHub: https://github.com/holograph This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.