SlideShare ist ein Scribd-Unternehmen logo
1 von 69
Downloaden Sie, um offline zu lesen
Dennis van der Stelt
Dealing with
Dennis van der Stelt
distributed systems addict
http://dennis.bloggingabout.net/
http://compilesoftware.nl/
Eventual Consistency
@dvdstelt
Dennis van der Stelt2
Dennis van der Stelt
Dennis van der Stelt
Dennis van der Stelt
https://www.pathe.nl/film/22678/game-of-thrones-finale
Dennis van der Stelt
Dennis van der Stelt
Dennis van der Stelt
Dennis van der Stelt
let’s check history
how did we get to
those issues?
Dennis van der Stelt
SELLING TICKETS
And when we are too successful for our own good
Hi, how can I help you?
I’d like to order tickets to the
finale of Game of Thrones.
Sure, no problem. How
many would you like?
I have no friends, so I’ll be
alone. Just one ticket, please.
Dennis van der Stelt
WHEN BUSINESS IS BOOMING
We need to scale out
Hi, how can I help you?
Hi, how can I help you?
Game of Thrones finale,
3 tickets. You’ve got them.
Game of Thrones finale,
4 tickets. You’ve got them.
Dennis van der Stelt
and then…
the internet happened
Dennis van der Stelt
DIGITIZING COMMERCE
The birth of eCommerce https://movies.com/
Dennis van der Stelt
DEALING WITH STRONG CONSISTENCY
begin transaction
var quantity = select Quantity from Movies
where Id = @MovieId
if (quantity >= amountOfTicketsCustomerWants)
update Movies
set Quantity = quantity – amountOfTicketsCustomerWants
where Id = @MovieId
commit transaction
Id Name TheaterId Price Quantity
42 Star Wars Rise of Skywalker 1 $ 15.00 400
1337 Game of Thrones 2 $ 0.00 100
Movies table
How every solutionstarts as a very, very small problem
Dennis van der Stelt
DEALING WITH STRONG CONSISTENCY
Id Name TheaterId Price Quantity
42 Star Wars Rise of Skywalker 1 $ 15.00 400
1337 Game of Thrones 2 $ 0.00 100
Movies table
How every solutionstarts as a very, very small problem
SINGLE ITEM CONGESTION
Dennis van der Stelt
DIGITIZING COMMERCE
The birth of eCommerce
Dennis van der Stelt
Dennis van der Stelt
Dennis van der Stelt
table index table index table index
Relational Database
ALTERNATIVE SOLUTIONS
Dennis van der Stelt
table index table index table index
Relational Database
Document Database
ALTERNATIVE SOLUTIONS
Dennis van der Stelt
table index table index table index
Relational Database
Document Database
Datacenters
North America Europe
data travels only at the speed of light
ALTERNATIVE SOLUTIONS
Dennis van der Stelt
Datacenters
North America Europe
data travels only at the speed of light
Dennis van der Stelt
ALTERNATIVE SOLUTIONS
Dennis van der Stelt
Datacenters
North America Europe
data travels only at the speed of light
Messaging
ALTERNATIVE SOLUTIONS
Searching for data that might not be there yet.
Dennis van der Stelt
asynchronous
communication
Dennis van der Stelt
DEALING WITH EVENTUAL CONSISTENCY
What is the problem?
Get a subscription
Enter your details
Full Name:
https://movies.com/subscription/edit/
Dennis van der Stelt
Address:
Van Zandvlietplein 1
City:
Rotterdam
Country:
The Netherlands
Get subscription
Home Movies Theaters
Subscription
Your subscription details
Full Name
https://movies.com/subscription/details/
Address
City
Country
Edit subscription
Home Movies Theaters
Subscription type:
Premium
Payment type:
Monthly
Subscription type
Payment type
: Dennis van der Stelt
: Van Zandvlietplein 1
: Rotterdam
: The Netherlands
Premium
Monthly payment
Dennis van der Stelt
Dennis van der Stelt
How to deal with it?
Do we really need strong consistency?
Dennis van der Stelt
READING
WRITING
what you are
Dennis van der Stelt
DEALING WITH EVENTUAL CONSISTENCY
When you’re not reading your own writes…
Add a new movie
Name:
https://movies.com/admin/movies/add
Zombieland: Double tap
Description:
they face off against evolved zombies,
Rating:
Rated R
Classification:
Add movie
Home Movies Theaters
Now running
https://movies.com/
Home Movies Theaters
Price:
$ 10
Hall
Main hall
Action
Comedy
Horror
x
x
x
Dennis van der Stelt
DEALING WITH EVENTUAL CONSISTENCY
When you’re not reading your own writes…
Register for an account
Name:
https://movies.com/users/registration
Dennis van der Stelt
Email:
dennis@bloggingabout.net
Password:
Register
Home Movies Theaters
https://movies.com/users/thanks
Home Movies Theaters
Password again:
Check the email we’ve sent you to verify your email address.
Dennis van der Stelt
DEALING WITH EVENTUAL CONSISTENCY
When you are reading your own writes
Get a subscription
Enter your details
Full Name:
https://movies.com/subscription/edit/
Dennis van der Stelt
Address:
Van Zandvlietplein 1
City:
Rotterdam
Country:
The Netherlands
Get subscription
Home Movies Theaters
Subscription
Your subscription details
Full Name
https://movies.com/subscription/details/
Address
City
Country
Edit subscription
Home Movies Theaters
Subscription type:
Premium
Payment type:
Monthly
Subscription type
Payment type
: Dennis van der Stelt
: Van Zandvlietplein 1
: Rotterdam
: The Netherlands
Premium
Monthly payment
Dennis van der Stelt
DEALING WITH EVENTUAL CONSISTENCY
Reading your own writes – the simplest solution
Get a subscription
Enter your details
Full Name:
https://movies.com/subscription/edit/
Dennis van der Stelt
Address:
Van Zandvlietplein 1
City:
Rotterdam
Country:
The Netherlands
Get subscription
Home Movies Theaters
Subscription type:
Premium
Payment type:
Monthly
https://movies.com/subscription/thanks
Home Movies Theaters
Thanks for submitting your details
take me back to movies
We are reviewing your changes. This can take a few minutes.
Dennis van der Stelt
Get a subscription
Enter your details
Full Name:
https://movies.com/subscription/edit/
Address:
City:
Country:
Get subscription
Home Movies Theaters
Subscription type:
<make a selection>
Payment type:
<make a selection>
DEALING WITH EVENTUAL CONSISTENCY
Reading your own writes – anothersimple solution
Get a subscription
Enter your details
Full Name:
https://movies.com/subscription/edit/
Dennis van der Stelt
Address:
Van Zandvlietplein 1
City:
Rotterdam
Country:
The Netherlands
Get subscription
Home Movies Theaters
Subscription type:
Premium
Payment type:
Monthly
Thanks for submitting your details
Dennis van der Stelt
DEALING WITH EVENTUAL CONSISTENCY
Reading your own writes – providing the best user experience, but for who?
<div class="visible">
<textarea name="comment" />
<button type="submit">
Add comment
</button>
</div>
<div class="invisible">
<span class="comment-copy"></div>
<a href="/users/1337">Name</a>
</div>
Dennis van der Stelt
DEALING WITH EVENTUAL CONSISTENCY
Reading your own writes – providing the best user experience, but for who?
var comments = repository.GetComments();
foreach (var comment in comments)
{
// display comments
}
var comments = localStorage.GetItem("com
foreach (var comment in comments)
{
if (!commentWasDisplayedAlready)
// display localStorage comment
}
Dennis van der Stelt
Demo
Using LocalStorage to mimic fast response times.
Dennis van der Stelt
$('#submitReviewButton').click(function(e) {
var comment = $('#comment').val();
var newReview = {
Identifier: guid,
ReviewedAt: new Date(),
Description: comment
};
localStorage.setItem('popcornStoredReviews', JSON.stringify(newReview));
$('#comment').val('');
$('#reviews').append('<li>').append(
$('<div>').attr('class', 'comment').text(comment)
);
});
Dennis van der Stelt
DEALING WITH EVENTUAL CONSISTENCY
Reading your own writes – providing the best user experience, but for who?
browser
SessionStorage LocalStorage IndexedDB
(web)server
Cache Redis Database
BENEFITS
onserver
Dennis van der Stelt
DEALING WITH EVENTUAL CONSISTENCY
Reading your own writes – providing the best user experience, but for who?
(web)server
browser
SessionStorage LocalStorage IndexedDB
database
Cache Redis Database
Dennis van der Stelt
DEALING WITH EVENTUAL CONSISTENCY
Another simple solution – waiting for something happening in the background
https://movies.com/subscription/details/
Home Movies Theaters
Dennis van der Stelt
DEALING WITH EVENTUAL CONSISTENCY
Another simple solution – waiting for something happening in the background
Dennis van der Stelt
ASYNCHRONOUS EXECUTION
Keeps a callback thread open on the client and frequently polls the server
Get a subscription
Enter your details
Full Name:
https://movies.com/subscription/edit/
Dennis van der Stelt
Address:
Van Zandvlietplein 1
City:
Rotterdam
Country:
The Netherlands
Get subscription
Home Movies Theaters
Subscriptiontype:
VIP
Payment type:
Monthly
https://movies.com/subscription/thanks/
Home Movies Theaters
Dennis van der Stelt
ASYNCHRONOUS COMMUNICATION
Using asynchronous messaging and SignalR
Get a subscription
Enter your details
Full Name:
https://movies.com/subscription/edit/
Dennis van der Stelt
Address:
Van Zandvlietplein 1
City:
Rotterdam
Country:
The Netherlands
Get subscription
Home Movies Theaters
Subscriptiontype:
VIP
Payment type:
Monthly
Thanks for applying for a VIP subscription.
You can already order movie tickets for free.*
After we’ve received the first payment, your snacks in our
theater will also be free. The payment will be fully automatic.
All you need to do is sit back and enjoy your favorite movies!
SignalR
SubmitOrder
OrderSubmission
Dennis van der Stelt
Demo
Ordering movie tickets using NServiceBus & SignalR
Dennis van der Stelt
$('#submit_button').click(function (e) {
var connection = new
signalR.HubConnectionBuilder().withUrl('/ticketHub').build();
connection.on('OrderSubmission', function (message) {
$('#ackonwledgement').html(message);
});
var order = $('#ticketOrderingForm').serialize();
connection.invoke("SubmitOrder", order);
});
ASYNCHRONOUSLY SUBMITTING A FORM
Set up a SignalR connection and submit the form to the backend
Dennis van der Stelt
public class TicketHub : Hub
{
IMessageSession messageSession;
public TicketHub(IMessageSession messageSession) {
this.messageSession = messageSession;
}
public Task SubmitOrder(var order)
{
return messageSession.Send(new SubmitOrder(order));
}
}
ASYNCHRONOUSLY SUBMITTING A FORM
Accept SignalR message and use NServiceBus to send message to queue
Dennis van der Stelt
public class SubmitOrderHandler : IHandleMessages<SubmitOrder>
{
public async Task Handle(SubmitOrder message, IMessageHandlerContext context)
{
var result = await RegisterOrder(message);
return await context.Reply(new OrderSubmission(result));
}
}
ASYNCHRONOUSLY SUBMITTING A FORM
NServiceBus handler processing message and replying with answer.
Dennis van der Stelt
public class OrderSubmissionHandler : IHandleMessages<OrderSubmission>
{
IHubContext<TicketHub> ticketHubContext;
public OrderSubmissionHandler(IHubContext<TicketHub> ticketHubContext) {
this.ticketHubContext = ticketHubContext;
}
public Task Handle(OrderSubmission message, IMessageHandlerContext context)
{
return ticketHubContext.Clients.User(user).SendAsync("OrderSubmission",
screenMessage);
}
}
ASYNCHRONOUSLY SUBMITTING A FORM
NServiceBus handler in website using SignalR to reply to browser
Dennis van der Stelt
LET’S DISCUSS THE DESIGN
So is this the way to approach this, Dennis?
Dennis van der Stelt
DEALING WITH EVENTUAL CONSISTENCY
Reading from multiple datastores
Add a new movie
Name:
https://movies.com/admin/movies/add
Zombieland: Double tap
Description:
they face off against evolved zombies,
Rating:
Rated R
Classification:
Add movie
Home Movies Theaters
Now running
https://movies.com/
Home Movies Theaters
Price:
$ 10
Hall
Main hall
Action
Comedy
Horror
x
x
x
Movie prices
Movie description
remember this slide?
Dennis van der Stelt
MULTI-PAGE CHECKOUT PROCESS
How to trickthe user into thinking everything is immediately processed
Shopping Cart
https://www.amazon.com/peaa-martin/
Patterns of Enterprise
Application Architecture
by Martin Fowler
Proceed to checkout
Subtotal: $42.00
QuantityItem Price
$42.00 1
This list contains a gift.
or
Sign in for 1 click ordering.
1
start
checkout
Dennis van der Stelt
Where should we deliver your order?
Enter a shipping address
Full Name:
https://www.amazon.com/buy/shippingaddress/
Dennis van der Stelt
AddressLine 1:
Van Zandvlietplein 1
City:
Rotterdam
Country:
The Netherlands
Ship to this Address
MULTI-PAGE CHECKOUT PROCESS
How to trickthe user into thinking everything is immediately processed
2
shipping
address
Dennis van der Stelt
Select a payment option
Your credit and debit cards
https://www.amazon.com/buy/payment/
Amazon accepts all major credit and debit cards
> Add a card
Continue
MasterCard ending in 2464 Dennis van der Stelt 09/2026
More payment options
Please tell us the currency of your card
My card is in US Dollar
My card is in a different currency: select a currency
MULTI-PAGE CHECKOUT PROCESS
How to trickthe user into thinking everything is immediately processed
4
payment
method
Dennis van der Stelt
Review your order
https://www.amazon.com/buy/payment/
Shipping address
Dennis van der Stelt
Van Zandvlietplein 1
Rotterdam, The Netherlands
Payment method
ending in 2464
Billing Address
Same as shipping address
Estimated delivery: Aug 17, 2018 – Aug 21, 2018
Patterns of Enterprise
Application Architecture
by Martin Fowler
$42.00 - Quantity: 1
change change
change
Place your order
Order Summary
Items:
Shipping:
Total before tax:
Estimated tax:
Order Total
$42.00
$7.98
$49.98
$0.00
$49.98
MULTI-PAGE CHECKOUT PROCESS
How to trickthe user into thinking everything is immediately processed
5
summary
Dennis van der Stelt
MULTI-PAGE CHECKOUT PROCESS
How to trickthe user into thinking everything is immediately processed
Dennis van der Stelt
What about the business?
Dealing with eventual consistency in the business
Dennis van der Stelt
Id Name Price Quantity
42 i can has cheezburger? $ 15.00 10
1337 The Winds of Winter $ 25.00 1000
HOW THE BUSINESS DEALS WITH EVENTUAL CONSISTENCY
Inventory table
Eventual consistency is baked into the business
ProductId Delta Timestamp
1337 -5 09:03:22 17-1-2016
1337 -3 09:03:24 17-1-2016
1337 -4 09:03:25 17-1-2016
1337 -1 09:03:27 17-1-2016
1337 +250 09:03:28 17-1-2016
1337 -4 09:03:30 17-1-2016
Inventory table
EventSourcing done simple
No locking, append only
Inventory is eventually consistent
No transactional lock to discover the current inventory left
Dennis van der Stelt
STEAM
CONTROLLER
Dennis van der Stelt
HOW THE BUSINESS DEALS WITH EVENTUAL CONSISTENCY
Fake consistency in the user interface
Patterns of Enterprise Application Architecture
42 customer reviews
Add to cart
$42.00
save $13.37
Kindle Hardcover
This item ships to Rotterdam, The Netherlands
Others
with more on the way
https://www.amazon.com/peaa-martin/
how important is it
that all numbers
are 100% accurate?
Dennis van der Stelt
HOW THE BUSINESS DEALS WITH EVENTUAL CONSISTENCY
When you’re faking it, please do it well…
Dennis van der Stelt
HOW THE BUSINESS DEALS WITH EVENTUAL CONSISTENCY
When you’re faking it, please do it well…
Dennis van der Stelt
HOW THE BUSINESS DEALS WITH EVENTUAL CONSISTENCY
When you’re faking it, please do it well…
Dennis van der Stelt
Dennis van der Stelt
HOW THE BUSINESS DEALS WITH EVENTUAL CONSISTENCY
A hybrid solution, optimized for customer satisfaction and consistency
Dennis van der Stelt
HOW THE BUSINESS DEALS WITH EVENTUAL CONSISTENCY
Putting good user experience before occasional money loss
Tom Cruise, 57
DETAILS
https://happypancake.com/profile/tom_cruise/
Location
BeverlyHills,California,USA
Searching for
Women,45-55
Favorite activity
Base-jumpingfrombuildings
Tom Cruise, 37
DETAILS
https://happypancake.com/profile/tom_cruise/
Location
BeverlyHills,California,USA
Searching for
Women,25-35
Favorite activity
Base-jumpingfrombuildings
strong consistency VS user experience
Dennis van der Stelt
Dennis van der Stelt
https://www.pathe.nl/film/22678/game-of-thrones-finale
Dennis van der Stelt
WHAT PROBLEM ARE WE SOLVING?
Strive for high customer satisfaction
Dennis van der Stelt
Dennis van der Stelt
dennis@bloggingabout.net
dennis.bloggingabout.net
@dvdstelt
linkedin.com/in/dvdstelt/
http://bit.ly/eventualconsistency
Solution Architect at Particular Software, makers of NServiceBus

Weitere ähnliche Inhalte

Mehr von Dennis van der Stelt

Mehr von Dennis van der Stelt (10)

Distributed Systems Principles
Distributed Systems PrinciplesDistributed Systems Principles
Distributed Systems Principles
 
Distributed Systems principles
Distributed Systems principlesDistributed Systems principles
Distributed Systems principles
 
Een andere kijk op Microservices
Een andere kijk op MicroservicesEen andere kijk op Microservices
Een andere kijk op Microservices
 
Duplicating data or replicating data in Micro Services
Duplicating data or replicating data in Micro ServicesDuplicating data or replicating data in Micro Services
Duplicating data or replicating data in Micro Services
 
Silverlight & WCF RIA
Silverlight & WCF RIASilverlight & WCF RIA
Silverlight & WCF RIA
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
AppFabric Velocity
AppFabric VelocityAppFabric Velocity
AppFabric Velocity
 
Continuous integration
Continuous integrationContinuous integration
Continuous integration
 
App fabric introduction
App fabric introductionApp fabric introduction
App fabric introduction
 
SOLID Principles part 1
SOLID Principles part 1SOLID Principles part 1
SOLID Principles part 1
 

Kürzlich hochgeladen

Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...RajaP95
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
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
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
(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
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
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
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
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
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
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
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 

Kürzlich hochgeladen (20)

Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
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
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
(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...
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
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...
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
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, ...
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
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
 
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 

Dealing with eventual consistency

  • 1. Dennis van der Stelt Dealing with Dennis van der Stelt distributed systems addict http://dennis.bloggingabout.net/ http://compilesoftware.nl/ Eventual Consistency @dvdstelt
  • 2. Dennis van der Stelt2
  • 5. Dennis van der Stelt https://www.pathe.nl/film/22678/game-of-thrones-finale
  • 9. Dennis van der Stelt let’s check history how did we get to those issues?
  • 10. Dennis van der Stelt SELLING TICKETS And when we are too successful for our own good Hi, how can I help you? I’d like to order tickets to the finale of Game of Thrones. Sure, no problem. How many would you like? I have no friends, so I’ll be alone. Just one ticket, please.
  • 11. Dennis van der Stelt WHEN BUSINESS IS BOOMING We need to scale out Hi, how can I help you? Hi, how can I help you? Game of Thrones finale, 3 tickets. You’ve got them. Game of Thrones finale, 4 tickets. You’ve got them.
  • 12. Dennis van der Stelt and then… the internet happened
  • 13. Dennis van der Stelt DIGITIZING COMMERCE The birth of eCommerce https://movies.com/
  • 14. Dennis van der Stelt DEALING WITH STRONG CONSISTENCY begin transaction var quantity = select Quantity from Movies where Id = @MovieId if (quantity >= amountOfTicketsCustomerWants) update Movies set Quantity = quantity – amountOfTicketsCustomerWants where Id = @MovieId commit transaction Id Name TheaterId Price Quantity 42 Star Wars Rise of Skywalker 1 $ 15.00 400 1337 Game of Thrones 2 $ 0.00 100 Movies table How every solutionstarts as a very, very small problem
  • 15. Dennis van der Stelt DEALING WITH STRONG CONSISTENCY Id Name TheaterId Price Quantity 42 Star Wars Rise of Skywalker 1 $ 15.00 400 1337 Game of Thrones 2 $ 0.00 100 Movies table How every solutionstarts as a very, very small problem SINGLE ITEM CONGESTION
  • 16. Dennis van der Stelt DIGITIZING COMMERCE The birth of eCommerce
  • 17. Dennis van der Stelt
  • 18. Dennis van der Stelt
  • 19. Dennis van der Stelt table index table index table index Relational Database ALTERNATIVE SOLUTIONS
  • 20. Dennis van der Stelt table index table index table index Relational Database Document Database ALTERNATIVE SOLUTIONS
  • 21. Dennis van der Stelt table index table index table index Relational Database Document Database Datacenters North America Europe data travels only at the speed of light ALTERNATIVE SOLUTIONS
  • 22. Dennis van der Stelt Datacenters North America Europe data travels only at the speed of light Dennis van der Stelt ALTERNATIVE SOLUTIONS
  • 23. Dennis van der Stelt Datacenters North America Europe data travels only at the speed of light Messaging ALTERNATIVE SOLUTIONS Searching for data that might not be there yet.
  • 24. Dennis van der Stelt asynchronous communication
  • 25. Dennis van der Stelt DEALING WITH EVENTUAL CONSISTENCY What is the problem? Get a subscription Enter your details Full Name: https://movies.com/subscription/edit/ Dennis van der Stelt Address: Van Zandvlietplein 1 City: Rotterdam Country: The Netherlands Get subscription Home Movies Theaters Subscription Your subscription details Full Name https://movies.com/subscription/details/ Address City Country Edit subscription Home Movies Theaters Subscription type: Premium Payment type: Monthly Subscription type Payment type : Dennis van der Stelt : Van Zandvlietplein 1 : Rotterdam : The Netherlands Premium Monthly payment
  • 26. Dennis van der Stelt
  • 27. Dennis van der Stelt How to deal with it? Do we really need strong consistency?
  • 28. Dennis van der Stelt READING WRITING what you are
  • 29. Dennis van der Stelt DEALING WITH EVENTUAL CONSISTENCY When you’re not reading your own writes… Add a new movie Name: https://movies.com/admin/movies/add Zombieland: Double tap Description: they face off against evolved zombies, Rating: Rated R Classification: Add movie Home Movies Theaters Now running https://movies.com/ Home Movies Theaters Price: $ 10 Hall Main hall Action Comedy Horror x x x
  • 30. Dennis van der Stelt DEALING WITH EVENTUAL CONSISTENCY When you’re not reading your own writes… Register for an account Name: https://movies.com/users/registration Dennis van der Stelt Email: dennis@bloggingabout.net Password: Register Home Movies Theaters https://movies.com/users/thanks Home Movies Theaters Password again: Check the email we’ve sent you to verify your email address.
  • 31. Dennis van der Stelt DEALING WITH EVENTUAL CONSISTENCY When you are reading your own writes Get a subscription Enter your details Full Name: https://movies.com/subscription/edit/ Dennis van der Stelt Address: Van Zandvlietplein 1 City: Rotterdam Country: The Netherlands Get subscription Home Movies Theaters Subscription Your subscription details Full Name https://movies.com/subscription/details/ Address City Country Edit subscription Home Movies Theaters Subscription type: Premium Payment type: Monthly Subscription type Payment type : Dennis van der Stelt : Van Zandvlietplein 1 : Rotterdam : The Netherlands Premium Monthly payment
  • 32. Dennis van der Stelt DEALING WITH EVENTUAL CONSISTENCY Reading your own writes – the simplest solution Get a subscription Enter your details Full Name: https://movies.com/subscription/edit/ Dennis van der Stelt Address: Van Zandvlietplein 1 City: Rotterdam Country: The Netherlands Get subscription Home Movies Theaters Subscription type: Premium Payment type: Monthly https://movies.com/subscription/thanks Home Movies Theaters Thanks for submitting your details take me back to movies We are reviewing your changes. This can take a few minutes.
  • 33. Dennis van der Stelt Get a subscription Enter your details Full Name: https://movies.com/subscription/edit/ Address: City: Country: Get subscription Home Movies Theaters Subscription type: <make a selection> Payment type: <make a selection> DEALING WITH EVENTUAL CONSISTENCY Reading your own writes – anothersimple solution Get a subscription Enter your details Full Name: https://movies.com/subscription/edit/ Dennis van der Stelt Address: Van Zandvlietplein 1 City: Rotterdam Country: The Netherlands Get subscription Home Movies Theaters Subscription type: Premium Payment type: Monthly Thanks for submitting your details
  • 34. Dennis van der Stelt DEALING WITH EVENTUAL CONSISTENCY Reading your own writes – providing the best user experience, but for who? <div class="visible"> <textarea name="comment" /> <button type="submit"> Add comment </button> </div> <div class="invisible"> <span class="comment-copy"></div> <a href="/users/1337">Name</a> </div>
  • 35. Dennis van der Stelt DEALING WITH EVENTUAL CONSISTENCY Reading your own writes – providing the best user experience, but for who? var comments = repository.GetComments(); foreach (var comment in comments) { // display comments } var comments = localStorage.GetItem("com foreach (var comment in comments) { if (!commentWasDisplayedAlready) // display localStorage comment }
  • 36. Dennis van der Stelt Demo Using LocalStorage to mimic fast response times.
  • 37. Dennis van der Stelt $('#submitReviewButton').click(function(e) { var comment = $('#comment').val(); var newReview = { Identifier: guid, ReviewedAt: new Date(), Description: comment }; localStorage.setItem('popcornStoredReviews', JSON.stringify(newReview)); $('#comment').val(''); $('#reviews').append('<li>').append( $('<div>').attr('class', 'comment').text(comment) ); });
  • 38. Dennis van der Stelt DEALING WITH EVENTUAL CONSISTENCY Reading your own writes – providing the best user experience, but for who? browser SessionStorage LocalStorage IndexedDB (web)server Cache Redis Database BENEFITS onserver
  • 39. Dennis van der Stelt DEALING WITH EVENTUAL CONSISTENCY Reading your own writes – providing the best user experience, but for who? (web)server browser SessionStorage LocalStorage IndexedDB database Cache Redis Database
  • 40. Dennis van der Stelt DEALING WITH EVENTUAL CONSISTENCY Another simple solution – waiting for something happening in the background https://movies.com/subscription/details/ Home Movies Theaters
  • 41. Dennis van der Stelt DEALING WITH EVENTUAL CONSISTENCY Another simple solution – waiting for something happening in the background
  • 42. Dennis van der Stelt ASYNCHRONOUS EXECUTION Keeps a callback thread open on the client and frequently polls the server Get a subscription Enter your details Full Name: https://movies.com/subscription/edit/ Dennis van der Stelt Address: Van Zandvlietplein 1 City: Rotterdam Country: The Netherlands Get subscription Home Movies Theaters Subscriptiontype: VIP Payment type: Monthly https://movies.com/subscription/thanks/ Home Movies Theaters
  • 43. Dennis van der Stelt ASYNCHRONOUS COMMUNICATION Using asynchronous messaging and SignalR Get a subscription Enter your details Full Name: https://movies.com/subscription/edit/ Dennis van der Stelt Address: Van Zandvlietplein 1 City: Rotterdam Country: The Netherlands Get subscription Home Movies Theaters Subscriptiontype: VIP Payment type: Monthly Thanks for applying for a VIP subscription. You can already order movie tickets for free.* After we’ve received the first payment, your snacks in our theater will also be free. The payment will be fully automatic. All you need to do is sit back and enjoy your favorite movies! SignalR SubmitOrder OrderSubmission
  • 44. Dennis van der Stelt Demo Ordering movie tickets using NServiceBus & SignalR
  • 45. Dennis van der Stelt $('#submit_button').click(function (e) { var connection = new signalR.HubConnectionBuilder().withUrl('/ticketHub').build(); connection.on('OrderSubmission', function (message) { $('#ackonwledgement').html(message); }); var order = $('#ticketOrderingForm').serialize(); connection.invoke("SubmitOrder", order); }); ASYNCHRONOUSLY SUBMITTING A FORM Set up a SignalR connection and submit the form to the backend
  • 46. Dennis van der Stelt public class TicketHub : Hub { IMessageSession messageSession; public TicketHub(IMessageSession messageSession) { this.messageSession = messageSession; } public Task SubmitOrder(var order) { return messageSession.Send(new SubmitOrder(order)); } } ASYNCHRONOUSLY SUBMITTING A FORM Accept SignalR message and use NServiceBus to send message to queue
  • 47. Dennis van der Stelt public class SubmitOrderHandler : IHandleMessages<SubmitOrder> { public async Task Handle(SubmitOrder message, IMessageHandlerContext context) { var result = await RegisterOrder(message); return await context.Reply(new OrderSubmission(result)); } } ASYNCHRONOUSLY SUBMITTING A FORM NServiceBus handler processing message and replying with answer.
  • 48. Dennis van der Stelt public class OrderSubmissionHandler : IHandleMessages<OrderSubmission> { IHubContext<TicketHub> ticketHubContext; public OrderSubmissionHandler(IHubContext<TicketHub> ticketHubContext) { this.ticketHubContext = ticketHubContext; } public Task Handle(OrderSubmission message, IMessageHandlerContext context) { return ticketHubContext.Clients.User(user).SendAsync("OrderSubmission", screenMessage); } } ASYNCHRONOUSLY SUBMITTING A FORM NServiceBus handler in website using SignalR to reply to browser
  • 49. Dennis van der Stelt LET’S DISCUSS THE DESIGN So is this the way to approach this, Dennis?
  • 50. Dennis van der Stelt DEALING WITH EVENTUAL CONSISTENCY Reading from multiple datastores Add a new movie Name: https://movies.com/admin/movies/add Zombieland: Double tap Description: they face off against evolved zombies, Rating: Rated R Classification: Add movie Home Movies Theaters Now running https://movies.com/ Home Movies Theaters Price: $ 10 Hall Main hall Action Comedy Horror x x x Movie prices Movie description remember this slide?
  • 51. Dennis van der Stelt MULTI-PAGE CHECKOUT PROCESS How to trickthe user into thinking everything is immediately processed Shopping Cart https://www.amazon.com/peaa-martin/ Patterns of Enterprise Application Architecture by Martin Fowler Proceed to checkout Subtotal: $42.00 QuantityItem Price $42.00 1 This list contains a gift. or Sign in for 1 click ordering. 1 start checkout
  • 52. Dennis van der Stelt Where should we deliver your order? Enter a shipping address Full Name: https://www.amazon.com/buy/shippingaddress/ Dennis van der Stelt AddressLine 1: Van Zandvlietplein 1 City: Rotterdam Country: The Netherlands Ship to this Address MULTI-PAGE CHECKOUT PROCESS How to trickthe user into thinking everything is immediately processed 2 shipping address
  • 53. Dennis van der Stelt Select a payment option Your credit and debit cards https://www.amazon.com/buy/payment/ Amazon accepts all major credit and debit cards > Add a card Continue MasterCard ending in 2464 Dennis van der Stelt 09/2026 More payment options Please tell us the currency of your card My card is in US Dollar My card is in a different currency: select a currency MULTI-PAGE CHECKOUT PROCESS How to trickthe user into thinking everything is immediately processed 4 payment method
  • 54. Dennis van der Stelt Review your order https://www.amazon.com/buy/payment/ Shipping address Dennis van der Stelt Van Zandvlietplein 1 Rotterdam, The Netherlands Payment method ending in 2464 Billing Address Same as shipping address Estimated delivery: Aug 17, 2018 – Aug 21, 2018 Patterns of Enterprise Application Architecture by Martin Fowler $42.00 - Quantity: 1 change change change Place your order Order Summary Items: Shipping: Total before tax: Estimated tax: Order Total $42.00 $7.98 $49.98 $0.00 $49.98 MULTI-PAGE CHECKOUT PROCESS How to trickthe user into thinking everything is immediately processed 5 summary
  • 55. Dennis van der Stelt MULTI-PAGE CHECKOUT PROCESS How to trickthe user into thinking everything is immediately processed
  • 56. Dennis van der Stelt What about the business? Dealing with eventual consistency in the business
  • 57. Dennis van der Stelt Id Name Price Quantity 42 i can has cheezburger? $ 15.00 10 1337 The Winds of Winter $ 25.00 1000 HOW THE BUSINESS DEALS WITH EVENTUAL CONSISTENCY Inventory table Eventual consistency is baked into the business ProductId Delta Timestamp 1337 -5 09:03:22 17-1-2016 1337 -3 09:03:24 17-1-2016 1337 -4 09:03:25 17-1-2016 1337 -1 09:03:27 17-1-2016 1337 +250 09:03:28 17-1-2016 1337 -4 09:03:30 17-1-2016 Inventory table EventSourcing done simple No locking, append only Inventory is eventually consistent No transactional lock to discover the current inventory left
  • 58. Dennis van der Stelt STEAM CONTROLLER
  • 59. Dennis van der Stelt HOW THE BUSINESS DEALS WITH EVENTUAL CONSISTENCY Fake consistency in the user interface Patterns of Enterprise Application Architecture 42 customer reviews Add to cart $42.00 save $13.37 Kindle Hardcover This item ships to Rotterdam, The Netherlands Others with more on the way https://www.amazon.com/peaa-martin/ how important is it that all numbers are 100% accurate?
  • 60. Dennis van der Stelt HOW THE BUSINESS DEALS WITH EVENTUAL CONSISTENCY When you’re faking it, please do it well…
  • 61. Dennis van der Stelt HOW THE BUSINESS DEALS WITH EVENTUAL CONSISTENCY When you’re faking it, please do it well…
  • 62. Dennis van der Stelt HOW THE BUSINESS DEALS WITH EVENTUAL CONSISTENCY When you’re faking it, please do it well…
  • 63. Dennis van der Stelt
  • 64. Dennis van der Stelt HOW THE BUSINESS DEALS WITH EVENTUAL CONSISTENCY A hybrid solution, optimized for customer satisfaction and consistency
  • 65. Dennis van der Stelt HOW THE BUSINESS DEALS WITH EVENTUAL CONSISTENCY Putting good user experience before occasional money loss Tom Cruise, 57 DETAILS https://happypancake.com/profile/tom_cruise/ Location BeverlyHills,California,USA Searching for Women,45-55 Favorite activity Base-jumpingfrombuildings Tom Cruise, 37 DETAILS https://happypancake.com/profile/tom_cruise/ Location BeverlyHills,California,USA Searching for Women,25-35 Favorite activity Base-jumpingfrombuildings strong consistency VS user experience
  • 66. Dennis van der Stelt
  • 67. Dennis van der Stelt https://www.pathe.nl/film/22678/game-of-thrones-finale
  • 68. Dennis van der Stelt WHAT PROBLEM ARE WE SOLVING? Strive for high customer satisfaction
  • 69. Dennis van der Stelt Dennis van der Stelt dennis@bloggingabout.net dennis.bloggingabout.net @dvdstelt linkedin.com/in/dvdstelt/ http://bit.ly/eventualconsistency Solution Architect at Particular Software, makers of NServiceBus