Microservices è una delle buzzword del momento. Sembra quasi che un'architettura a microservices sia fondamentale. È veramente così? Faremo un tortuoso viaggio tra le buzzword del momento cercando di districarci tra cosa è bene e cosa è meno bene, ma soprattutto perché. Obiettivo è quello di comprendere quali sono i limiti di certe scelte architetturali e quali gli errori da non commettere. Il tutto nell'ottica di garantire ai nostri sistemi 'lunga vita e prosperità' (cit.)
23. @mauroservienti
Suppliers & Products & Shopping Cart
[ list-of ]
- Item ID
- CurrentPrice
- LastPrice
- Quantity
- Inventory
- Name
- Description
Shopping Cart
- Item ID
- Price
- Inventory
Products
Is item XYZ in a cart?
Swap & Insert Prices
Move to Saved for…
- Supplier ID
- Item ID
- Purchase Price
Suppliers
Update XYZ Price
Are we selling?
New Purchase Price
24. @mauroservienti
“the microservices way”
Shopping CartProducts
Is item XYZ in a cart?
Swap & Insert Prices
Move to Saved for…
Suppliers Update XYZ Price
Are we selling?
New Purchase Price
• Incoming “external” HTTP Post
• HTTP Query from Suppliers to Products
• HTTP Post from Suppliers to Products
• HTTP Query from Products to Shopping Cart
• HTTP Post from Products to Shopping Cart
25. @mauroservienti
Hops 1 2 3 4 10
Latency 100ms 200ms 300ms 400ms 1 second
“the microservices way”
Does not count any processing time!
…
36. @mauroservienti
Queries are still a thing: Add item to cart.
[ list-of ]
- Item ID
- Price
- Quantity
- Inventory
- Name
- Description
Shopping Cart
- Item ID
- Price
- Inventory
Products
copy price
copy inventory
37. @mauroservienti
Data sharing is still a thing
[ list-of ]
- Item ID
- CurrentPrice
- LastPrice
- Quantity
- Inventory
- Name
- Description
Shopping Cart
+ new price details
Business
Logic
Sell Price Changed
MovetoSavedfor…
38. @mauroservienti
We’re flooding the system…
Shopping CartProducts
Is item XYZ in a cart?
Swap & Insert Prices
Move to Saved for…
Is item XYZ in a cart?
Update XYZ inventory
Is item XYZ in a cart?
Swap & Insert Prices
Move to Saved for…
Is item XYZ in a cart?
Update XYZ inventory
Is item XYZ in a cart?
Swap & Insert Prices
Move to Saved for…
Is item XYZ in a cart?
Update XYZ inventory
Is item XYZ in a cart?
Swap & Insert Prices
Move to Saved for…
Is item XYZ in a cart?
Update XYZ inventory
Is item XYZ in a cart?
Swap & Insert Prices
Move to Saved for…
Is item XYZ in a cart?
Update XYZ inventory
Is item XYZ in a cart?
Swap & Insert Prices
Move to Saved for…
Is item XYZ in a cart?
Update XYZ inventory
Is item XYZ in a cart?
Swap & Insert Prices
Move to Saved for…
Is item XYZ in a cart?
Update XYZ inventory
Is item XYZ in a cart?
Swap & Insert Prices
Move to Saved for…
Is item XYZ in a cart?
Update XYZ inventory
Is item XYZ in a cart?
Swap & Insert Prices
Move to Saved for…
Is item XYZ in a cart?
Update XYZ inventory
Is item XYZ in a cart?
Swap & Insert Prices
Move to Saved for…
Is item XYZ in a cart?
Update XYZ inventory
Is item XYZ in a cart?
Swap & Insert Prices
Move to Saved for…
Is item XYZ in a cart?
Update XYZ inventory
Is item XYZ in a cart?
Swap & Insert Prices
Move to Saved for…
Is item XYZ in a cart?
Update XYZ inventory
Update XYZ Price
Update XYZ Inventory
Over and over, and over, and over…
41. @mauroservienti
User mental model is misleading
[ list-of ]
- Item ID
- CurrentPrice
- LastPrice
- Quantity
- Inventory
- Name
- Description
Shopping Cart
- Item ID
- Price
- Inventory
Products
- Supplier ID
- Item ID
- Purchase Price
Suppliers
42. @mauroservienti
Let’s focus on the Shopping Cart
[ list-of ]
- Item ID
- CurrentPrice
- LastPrice
- Quantity
- Inventory
- Name
- Description
- Etc…
Shopping Cart
43. @mauroservienti
Sales shopping cart
[ list-of ]
- Item ID
- Quantity
- Inventory
- Name
- Description
- Delivery Est.
Shopping Cart
- Item ID
- Price
Sales
[ list-of ]
- Item ID
- CurrentPrice
- LastPrice
- Quantity
44. @mauroservienti
- Item ID
- Price
Sales
[ list-of ]
- Item ID
- CurrentPrice
- LastPrice
- Quantity
Warehouse shopping cart
[ list-of ]
- Item ID
- Quantity
- Name
- Description
- Delivery Est.
Shopping Cart
[ list-of ]
- Cart ID
- Item ID
- Inventory
- Quantity
Warehouse
- Item ID
- Inventory
45. @mauroservienti
Shipping shopping cart
[ list-of ]
- Item ID
- Quantity
- Name
- Description
Shopping Cart
[ list-of ]
- Cart ID
- Item ID
- Quantity
- Delivery Est.
- Item ID
- Price
Sales
[ list-of ]
- Item ID
- CurrentPrice
- LastPrice
- Quantity
[ list-of ]
- Cart ID
- Item ID
- Inventory
- Quantity
Warehouse
- Item ID
- Inventory
- Item ID
- Delivery
Type
Shipping
46. @mauroservienti
Marketing tends to be stable
[ list-of ]
- Item ID
- Quantity
Shopping Cart
[ list-of ]
- Cart ID
- Item ID
- Quantity
- Delivery Est.
- Item ID
- Price
- Item ID
- Name
- Description
Marketing
Sales
[ list-of ]
- Item ID
- CurrentPrice
- LastPrice
- Quantity
[ list-of ]
- Cart ID
- Item ID
- Inventory
- Quantity
Warehouse
- Item ID
- Inventory
- Item ID
- Delivery
Type
Shipping
47. @mauroservienti
Do we need the Shopping Cart at all?
[ list-of ]
- Item ID
- Quantity
Shopping Cart
[ list-of ]
- Cart ID
- Item ID
- Quantity
- Delivery Est.
- Item ID
- Price
- Item ID
- Name
- Description
Marketing
Sales
[ list-of ]
- Item ID
- CurrentPrice
- LastPrice
- Quantity
[ list-of ]
- Cart ID
- Item ID
- Inventory
- Quantity
Warehouse
- Item ID
- Inventory
- Item ID
- Delivery
Type
Shipping
48. @mauroservienti
Can Sales be responsible for that concept?
[ list-of ]
- Cart ID
- Item ID
- Quantity
- Delivery Est.
- Item ID
- Price
- Item ID
- Name
- Description
Marketing
Sales
Cart ID
[ list-of ]
- Item ID
- CurrentPrice
- LastPrice
- Quantity
[ list-of ]
- Cart ID
- Item ID
- Inventory
- Quantity
Warehouse
- Item ID
- Inventory
- Item ID
- Delivery
Type
Shipping
49. @mauroservienti
We followed the coupling
[ list-of ]
- Cart ID
- Item ID
- Quantity
- Delivery Est.
- Item ID
- Price
- Item ID
- Name
- Description
Marketing
Sales
Cart ID
[ list-of ]
- Item ID
- CurrentPrice
- LastPrice
- Quantity
[ list-of ]
- Cart ID
- Item ID
- Inventory
- Quantity
Warehouse
- Item ID
- Inventory
- Item ID
- Delivery
Type
Shipping
50. @mauroservienti
What a (micro)service is not
• A service that has only functionality is a function:
• Like calculation, validation, etc.
• A service that has only data is a database:
• Like [create, read, update, delete] entity
• HTTP/WSDL doesn’t change logical responsibility
51. @mauroservienti
What a (micro)service is
the technical authority
for a specific business
capability
All business rules (& data) reside within the service
59. @mauroservienti
Services communication channel
MarketingSales Warehouse Shipping
behavior & data
behavior & data
behavior & databehavior & data
ViewModel Composition
ViewModel Composition ViewModel CompositionViewModel Composition
Add Item to Cart
60. @mauroservienti
Services communication channel
MarketingSales Warehouse Shipping
behavior & data
behavior & data
behavior & databehavior & data
ViewModel Composition
ViewModel Composition ViewModel CompositionViewModel Composition
Add Item to Cart
1. Set 1 week timeout
61. @mauroservienti
Services communication channel
MarketingSales Warehouse Shipping
behavior & data
behavior & data
behavior & databehavior & data
ViewModel Composition
ViewModel Composition ViewModel CompositionViewModel Composition
Add Item to Cart
1. Set 1 week timeout
2. Set 1 month timeout
62. @mauroservienti
1 week later
MarketingSales Warehouse Shipping
behavior & data
behavior & data
behavior & databehavior & data
ViewModel Composition
ViewModel Composition ViewModel CompositionViewModel Composition
Add Item to Cart
1. Set 1 week timeout
2. Set 1 month timeout
Cart Got Stale
63. @mauroservienti
1 week later
MarketingSales Warehouse Shipping
behavior & data
behavior & data
behavior & databehavior & data
ViewModel Composition
ViewModel Composition ViewModel CompositionViewModel Composition
Add Item to Cart
1. Set 1 week timeout
2. Set 1 month timeout
busCart Got Stale
64. @mauroservienti
1 week later
MarketingSales Warehouse Shipping
behavior & data
behavior & data
behavior & databehavior & data
ViewModel Composition
ViewModel Composition ViewModel CompositionViewModel Composition
Add Item to Cart
1. Set 1 week timeout
2. Set 1 month timeout
bus Cart Got Stale
65. @mauroservienti
1 week later
MarketingSales Warehouse Shipping
behavior & data
behavior & data behavior & data
behavior & data
ViewModel Composition
ViewModel Composition ViewModel Composition
ViewModel Composition
Add Item to Cart
1. Set 1 week timeout
2. Set 1 month timeout
bus
Notify User
Cart Got Stale
66. @mauroservienti
1 month later
MarketingSales Warehouse Shipping
behavior & data
behavior & data
behavior & databehavior & data
ViewModel Composition
ViewModel Composition ViewModel CompositionViewModel Composition
Add Item to Cart
1. Set 1 week timeout
2. Set 1 month timeout
bus
Cart Expired
67. @mauroservienti
busCart Expired
1 month later
MarketingSales Warehouse Shipping
behavior & data
behavior & data
behavior & databehavior & data
ViewModel Composition
ViewModel Composition ViewModel CompositionViewModel Composition
Add Item to Cart
1. Set 1 week timeout
2. Set 1 month timeout
Cart Expired
68. @mauroservienti
1 month later
MarketingSales Warehouse Shipping
behavior & data
behavior & data
behavior & databehavior & data
ViewModel Composition
ViewModel Composition ViewModel CompositionViewModel Composition
Add Item to Cart
1. Set 1 week timeout
2. Set 1 month timeout
busCart Expired Cart Expired
69. @mauroservienti
1 month later
MarketingSales Warehouse Shipping
behavior & databehavior & data
behavior & data
behavior & data
ViewModel Composition ViewModel Composition ViewModel Composition
ViewModel Composition
Add Item to Cart
1. Set 1 week timeout
2. Set 1 month timeout
bus
Wipe cart Wipe cart
Cart Expired Cart Expired
73. @mauroservienti
Takeaways
• Boundaries are key to success
• Mental model can badly influence design
• Users/Business analysts tend to think in term
of data presentation
74. @mauroservienti
Takeaways
• Boundaries are key to success
• Mental model can badly influence design
• Do not name things prematurely
• Premature names stick and drive data
aggregation
75. @mauroservienti
Takeaways
• Boundaries are key to success
• Mental model can badly influence design
• Do not name things prematurely
• Behaviors define how to aggregate data
• Group data that change together and that influence each
other
• Use anti-requirements techniques to validate data
grouping
• Follow the coupling
76. @mauroservienti
Takeaways
• Boundaries are key to success
• Mental model can badly influence design
• Do not name things prematurely
• Behaviors define how to aggregate data
• Use messaging to temporally decouple services
I’m a remote worker
We live in a small flat, thus I have a small office
I enjoy going to the office by bike
And I enjoy bananas for my breaks
Bike riding and bananas in the backpack are not a great idea, so…
How is this thing designed?
I’m a remote worker
I enjoy going to work by bike
And I enjoy bananas as lunch breaks
Bike riding and bananas in the backpack are not a great idea, so…
Price cannot unexpectedly change while an item is in the cart
Price cannot unexpectedly change while an item is in the cart
distributed monolith
Amazon found every 100ms of latency cost them 1% in sales
https://blog.gigaspaces.com/amazon-found-every-100ms-of-latency-cost-them-1-in-sales/
distributed monolith
distributed monolith
At Cart Item Add time
Deploy time
HTTP/WSDL remark : The fact that you add an HTTP or WSDL entry point into the code, doesn’t make it a service!
Again, not technical, but look at it from a business perspective. What is the responsibility of a service?
Sales conceptually own the shopping car concept
Sales conceptually own the shopping car concept
Sales conceptually own the shopping car concept
Sales conceptually own the shopping car concept
Since we have very low, if not zero, coupling across services.