can my inventory survive eventual consistency?

18
Jeff Carpenter Can My Inventory Survive Eventual Consistency?

Upload: datastax

Post on 14-Feb-2017

82 views

Category:

Technology


0 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 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?

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?

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?

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?

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?

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?

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?

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?

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?

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?

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?

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?

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?

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?

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