Can My Inventory Survive Eventual Consistency?
-
Upload
datastax -
Category
Technology
-
view
82 -
download
0
Transcript of Can My Inventory Survive Eventual Consistency?
![Page 1: Can My Inventory Survive Eventual Consistency?](https://reader031.fdocuments.net/reader031/viewer/2022021506/58a29ba21a28ab36508b786b/html5/thumbnails/1.jpg)
Jeff Carpenter
Can My Inventory Survive Eventual Consistency?
![Page 2: Can My Inventory Survive Eventual Consistency?](https://reader031.fdocuments.net/reader031/viewer/2022021506/58a29ba21a28ab36508b786b/html5/thumbnails/2.jpg)
Who am I?• Developer• Architect• Author• Evangelist
• Defense• Hospitality• R&D
• Distributed Systems• Large Scale• Cassandra
© DataStax, All Rights Reserved. 2
![Page 3: Can My Inventory Survive Eventual Consistency?](https://reader031.fdocuments.net/reader031/viewer/2022021506/58a29ba21a28ab36508b786b/html5/thumbnails/3.jpg)
DataStax Enterprise / Cassandra Use Cases
• Customer 360• Personalization• IoT/Sensors• Security
• Inventory Management!
© DataStax, All Rights Reserved. 3
![Page 4: Can My Inventory Survive Eventual Consistency?](https://reader031.fdocuments.net/reader031/viewer/2022021506/58a29ba21a28ab36508b786b/html5/thumbnails/4.jpg)
What Is Inventory?A tangible object that can be sold…
Shirt, Clif Bar, Used Car
CREATE TABLE physical_inventory(product_id uuid PRIMARY KEY, int amount_available,int amount_consumed);
A space that can be used for some timeHotel Room, My house, Restaurant table
CREATE TABLE temporal_inventory(product_id uuid, date date,int amount_available,int amount_consumed,PRIMARY KEY ((product_id), date));
© DataStax, All Rights Reserved. 4
![Page 5: Can My Inventory Survive Eventual Consistency?](https://reader031.fdocuments.net/reader031/viewer/2022021506/58a29ba21a28ab36508b786b/html5/thumbnails/5.jpg)
Inventory in Context
© DataStax, All Rights Reserved. 5
rates
temporal inventory
products
reservations
physical inventory
purchase orders
pricesRetail
Reservationand rental
![Page 6: Can My Inventory Survive Eventual Consistency?](https://reader031.fdocuments.net/reader031/viewer/2022021506/58a29ba21a28ab36508b786b/html5/thumbnails/6.jpg)
Why use DSE/Cassandra for inventory?
• Effortless scale• Geographic distribution• Real-time access / Low latency• Continuous availability• Consistency
© DataStax, All Rights Reserved. 6
![Page 7: Can My Inventory Survive Eventual Consistency?](https://reader031.fdocuments.net/reader031/viewer/2022021506/58a29ba21a28ab36508b786b/html5/thumbnails/7.jpg)
Design Considerations
• Systems of Record• Microservices• Tuneable Consistency• Compensating Transactions• Data Maintenance via TTL (for Temporal Inventory)
© DataStax, All Rights Reserved. 7
![Page 8: Can My Inventory Survive Eventual Consistency?](https://reader031.fdocuments.net/reader031/viewer/2022021506/58a29ba21a28ab36508b786b/html5/thumbnails/8.jpg)
Systems of Record
• Are there other systems that track this inventory data?• What is the level of uncertainty in my system vs. external
systems?
© DataStax, All Rights Reserved. 8
Property Management
System
Reservation Systeminventory
synchronization
Walk-in customer Online
customerProperty manager
![Page 9: Can My Inventory Survive Eventual Consistency?](https://reader031.fdocuments.net/reader031/viewer/2022021506/58a29ba21a28ab36508b786b/html5/thumbnails/9.jpg)
Notional Microservice Architecture –Temporal Inventory
© DataStax, All Rights Reserved. 9
Product Service
Booking Service
Rates Service
Shopping Service
Data Maintenance Apps
Inventory Service
Reservation Service
Inventory keyspace
Rates keyspace
Product keyspace
Reservations keyspace
![Page 10: Can My Inventory Survive Eventual Consistency?](https://reader031.fdocuments.net/reader031/viewer/2022021506/58a29ba21a28ab36508b786b/html5/thumbnails/10.jpg)
Consistency Error Cases
• Undercounting sold inventory– Reservations – Overbooking
• Bumping, walking– Retail
• Back order, cancel order• Overcounting sold inventory
– Lost opportunity to sell, wasted resource• Inconsistencies across data types
– Booked reservation without decrementing inventory
© DataStax, All Rights Reserved. 10
![Page 11: Can My Inventory Survive Eventual Consistency?](https://reader031.fdocuments.net/reader031/viewer/2022021506/58a29ba21a28ab36508b786b/html5/thumbnails/11.jpg)
Inventory Service Instance 1
Strong Consistency via Quorum on Read/Write
© DataStax, All Rights Reserved. 11
C*
node
node
node
node
Inventory keyspaceReplication Factor = 3
Inventory Service Instance 2
Write @ QUORUM(2 nodes)
Read @ QUORUM(2 nodes)
![Page 12: Can My Inventory Survive Eventual Consistency?](https://reader031.fdocuments.net/reader031/viewer/2022021506/58a29ba21a28ab36508b786b/html5/thumbnails/12.jpg)
Distributed Transaction?
Consistencies Across Data Types
© DataStax, All Rights Reserved. 12
Commit thecontract
Reservethe inventory
Booking Service
Inventory Service
Reservation Service
inventoryreservations
Monolithic Reservation System
![Page 13: Can My Inventory Survive Eventual Consistency?](https://reader031.fdocuments.net/reader031/viewer/2022021506/58a29ba21a28ab36508b786b/html5/thumbnails/13.jpg)
Tuneable Consistency Revisited
© DataStax, All Rights Reserved. 13
Approach Example Scope
Lightweight Transaction Updating inventory counts Data Tier
Logged Batch Writing to multiple denormalizedtables Data Tier
Retrying failed calls Data synchronization, reservation processing Service
Compensating processes Verifying reservation processing System
Eventual consistency
Strong consistency
![Page 14: Can My Inventory Survive Eventual Consistency?](https://reader031.fdocuments.net/reader031/viewer/2022021506/58a29ba21a28ab36508b786b/html5/thumbnails/14.jpg)
Compensating Transactions
• Technical– Run repairs more frequently– Consistency checking apps
• Business Processes– Reservation: reschedule, “walk”– Retail: back order, refund
It’s all about the tradeoffs…
© DataStax, All Rights Reserved. 14
Development and operations cost
Customer satisfaction and retention cost
![Page 15: Can My Inventory Survive Eventual Consistency?](https://reader031.fdocuments.net/reader031/viewer/2022021506/58a29ba21a28ab36508b786b/html5/thumbnails/15.jpg)
TTL for Temporal Inventory Cleanup
© DataStax, All Rights Reserved. 15
Now
Time
Yesterday’s data is ancient history
Rate + Inventory Data
![Page 16: Can My Inventory Survive Eventual Consistency?](https://reader031.fdocuments.net/reader031/viewer/2022021506/58a29ba21a28ab36508b786b/html5/thumbnails/16.jpg)
Tomorrow’s Inventory Management System
• Leverage DSE Search / Analytics / Graph for value added real-time use cases
© DataStax, All Rights Reserved. 16
Identify undersold product
Personalize shopping
experience Upsell popular products
Offer discount
![Page 17: Can My Inventory Survive Eventual Consistency?](https://reader031.fdocuments.net/reader031/viewer/2022021506/58a29ba21a28ab36508b786b/html5/thumbnails/17.jpg)
Plug
© DataStax, All Rights Reserved. 17
Cassandra: The Definitive Guide, 2nd EditionCompletely reworked for Cassandra 3.X:• Data modeling in CQL• SASI indexes
• Materialized views• Lightweight Transactions• DataStax drivers• New chapters on security, deployment, and integration