can my inventory survive eventual consistency?
TRANSCRIPT
Jeff Carpenter
Can My Inventory Survive Eventual Consistency?
Who am I?• Developer• Architect• Author• Evangelist
• Defense• Hospitality• R&D
• Distributed Systems• Large Scale• Cassandra
© DataStax, All Rights Reserved. 2
DataStax Enterprise / Cassandra Use Cases
• Customer 360• Personalization• IoT/Sensors• Security
• Inventory Management!
© DataStax, All Rights Reserved. 3
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
Inventory in Context
© DataStax, All Rights Reserved. 5
rates
temporal inventory
products
reservations
physical inventory
purchase orders
pricesRetail
Reservationand rental
Why use DSE/Cassandra for inventory?
• Effortless scale• Geographic distribution• Real-time access / Low latency• Continuous availability• Consistency
© DataStax, All Rights Reserved. 6
Design Considerations
• Systems of Record• Microservices• Tuneable Consistency• Compensating Transactions• Data Maintenance via TTL (for Temporal Inventory)
© DataStax, All Rights Reserved. 7
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
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
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
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)
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
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
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
TTL for Temporal Inventory Cleanup
© DataStax, All Rights Reserved. 15
Now
Time
Yesterday’s data is ancient history
Rate + Inventory Data
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
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