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, All Rights Reserved. 3
DataStax Enterprise / Cassandra Use Cases
• Customer 360• Personalization• IoT/Sensors• Security
• Inventory Management!
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 time Hotel 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
© DataStax, All Rights Reserved. 5
Inventory in Context
rates
temporal inventory
products
reservations
physical inventory
purchase orders
pricesRetail
Reservationand rental
© DataStax, All Rights Reserved. 6
Why use DSE/Cassandra for inventory?
• Effortless scale• Geographic distribution• Real-time access / Low latency• Continuous availability• Consistency
© DataStax, All Rights Reserved. 7
Design Considerations
• Systems of Record• Microservices• Tuneable Consistency• Compensating Transactions• Data Maintenance via TTL (for Temporal Inventory)
© DataStax, All Rights Reserved. 8
Systems of Record
• Are there other systems that track this inventory data?• What is the level of uncertainty in my system vs. external
systems?
Property Management
System
Reservation Systeminventory
synchronization
Walk-in customer Online
customerProperty manager
© DataStax, All Rights Reserved. 9
Notional Microservice Architecture – Temporal Inventory
Product Service
Booking Service
Rates Service
Shopping Service
Data Maintenance Apps
Inventory Service
Reservation Service
Inventory keyspace
Rates keyspace
Product keyspace
Reservations keyspace
© DataStax, All Rights Reserved. 10
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. 11
Inventory Service Instance 1
Strong Consistency via Quorum on Read/Write
C*
node
node
node
node
Inventory keyspaceReplication Factor = 3
Inventory Service Instance 2
Write @ QUORUM(2 nodes)
Read @ QUORUM(2 nodes)
© DataStax, All Rights Reserved. 12
Distributed Transaction?
Consistencies Across Data Types
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 denormalized tables Data Tier
Retrying failed calls Data synchronization, reservation processing Service
Compensating processes Verifying reservation processing System
Eventual consistency
Strong consistency
© DataStax, All Rights Reserved. 14
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…
Development and operations cost
Customer satisfaction and retention cost
© DataStax, All Rights Reserved. 15
TTL for Temporal Inventory Cleanup
Now
Time
Yesterday’s data is ancient history
Rate + Inventory Data
© DataStax, All Rights Reserved. 16
Tomorrow’s Inventory Management System
• Leverage DSE Search / Analytics / Graph for value added real-time use cases
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
Contact
© DataStax, All Rights Reserved. 18
@jscarp
jeffreyscarpenter