can my inventory survive eventual consistency?

18
Jeff Carpenter Can My Inventory Survive Eventual Consistency?

Upload: jeffrey-carpenter

Post on 12-Apr-2017

113 views

Category:

Software


1 download

TRANSCRIPT

Page 1: Can My Inventory Survive Eventual Consistency?

Jeff Carpenter

Can My Inventory Survive Eventual Consistency?

Page 2: 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

Page 3: Can My Inventory Survive Eventual Consistency?

© DataStax, All Rights Reserved. 3

DataStax Enterprise / Cassandra Use Cases

• Customer 360• Personalization• IoT/Sensors• Security

• Inventory Management!

Page 4: Can My Inventory Survive Eventual Consistency?

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

Page 5: Can My Inventory Survive Eventual Consistency?

© DataStax, All Rights Reserved. 5

Inventory in Context

rates

temporal inventory

products

reservations

physical inventory

purchase orders

pricesRetail

Reservationand rental

Page 6: Can My Inventory Survive Eventual Consistency?

© DataStax, All Rights Reserved. 6

Why use DSE/Cassandra for inventory?

• Effortless scale• Geographic distribution• Real-time access / Low latency• Continuous availability• Consistency

Page 7: Can My Inventory Survive Eventual Consistency?

© DataStax, All Rights Reserved. 7

Design Considerations

• Systems of Record• Microservices• Tuneable Consistency• Compensating Transactions• Data Maintenance via TTL (for Temporal Inventory)

Page 8: Can My Inventory Survive Eventual Consistency?

© 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

Page 9: Can My Inventory Survive Eventual Consistency?

© 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

Page 10: Can My Inventory Survive Eventual Consistency?

© 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

Page 11: Can My Inventory Survive Eventual Consistency?

© 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)

Page 12: Can My Inventory Survive Eventual Consistency?

© 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

Page 13: Can My Inventory Survive Eventual Consistency?

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

Page 14: Can My Inventory Survive Eventual 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

Page 15: Can My Inventory Survive Eventual Consistency?

© DataStax, All Rights Reserved. 15

TTL for Temporal Inventory Cleanup

Now

Time

Yesterday’s data is ancient history

Rate + Inventory Data

Page 16: Can My Inventory Survive Eventual Consistency?

© 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

Page 17: Can My Inventory Survive Eventual Consistency?

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

Page 18: Can My Inventory Survive Eventual Consistency?

Contact

© DataStax, All Rights Reserved. 18

[email protected]

@jscarp

jeffreyscarpenter