MultiSource Inventory CQRS and Event Sourcing in Magento































- Slides: 31
Multi-Source Inventory CQRS and Event Sourcing in Magento 2 © 2017 Magento, Inc. Page | 1
Valeriy Nayda Magento Developer, Multi Source Inventory Community Engineering Team © 2017 Magento, Inc. Page | 2
Community Engineering Team Main goal is to build a bridge between Magento Core and Community • Git. Hub activities: working with Pull requests and Issues • • Working with our solution partners (rewards programs and so on) Special Development © 2017 Magento, Inc. Page | 3
Multi-Source Inventory (MSI) MSI is designed to enable stock management in multiple locations so that merchants can properly reflect their physical warehouses in Magento system without external extensions or customization © 2017 Magento, Inc. Page | 4
Split the inventory between the sources within one Magento installation One Magento Installation © 2017 Magento, Inc. Page | 5
MSI Architecture
Base concepts © 2017 Magento, Inc. Page | 7
Source > Stock > Sales Channels relation © 2017 Magento, Inc. Page | 8
Replace current Inventory with MSI © 2017 Magento, Inc. Page | 9
Checkout Action Points/Goals • • • Unload the process of placing an order as much as possible Remove unnecessary locks (get rid of race condition between concurrent transactions) Improve the scalability of the checkout (shipping algorithms) © 2017 Magento, Inc. Page | 10
Command/Query Responsibility Segregation (CQRS)
CQRS © 2017 Magento, Inc. Page | 12
CQRS in MSI © 2017 Magento, Inc. Page | 13
Quantity Calculation during Checkout
Reservation mechanism Reservation - the entity is used when the order is placed and we need to reserve some product quantity in stock. Reservations are append only operations and help us to prevent blocking operations and race conditions at the time of checkout. © 2017 Magento, Inc. Page | 15
Order Placement – Step 1 Raw data Index Reservations France Warehouse SKU-1: 5 qty EU Stock SKU-1: 15 qty Italy Warehouse SKU-1: 10 qty Available Qty: 15 qty (data from index, empty reservations) © 2017 Magento, Inc. Page | 16 No records
Order Placement – Step 2 Action: Customer buys 5 products on frontend © 2017 Magento, Inc. Page | 17
Order Placement – Step 3 Raw data Index Data is NOT changed Reservations Reservation has been added France Warehouse SKU-1: 5 qty EU Stock SKU-1: 15 qty SKU-1: -5 Italy Warehouse SKU-1: 10 qty Available Qty: 10 qty (data from index 15, apply reservations -5) © 2017 Magento, Inc. Page | 18
Order Placement – Step 4 Action: Admin cancels 3 products from 5 © 2017 Magento, Inc. Page | 19
Order Placement – Step 5 Raw data Index Data is NOT changed Reservations Reservation has been added France Warehouse SKU-1: 5 qty EU Stock SKU-1: 15 qty Italy Warehouse SKU-1: -5 SKU-1: +3 SKU-1: 10 qty Available Qty: 13 qty (data from index 15, apply reservations -5+3) © 2017 Magento, Inc. Page | 20
Order Placement – Step 6 Action: Admin completes order. Re-index was run. © 2017 Magento, Inc. Page | 21
Order Placement – Step 7 Raw data Index Data is CHANGED Reservations Reservation has been added France Warehouse SKU-1: 3 qty EU Stock SKU-1: 13 qty Italy Warehouse SKU-1: 10 qty SKU-1: -5 SKU-1: +3 SKU-1: +2 Available Qty: 13 qty (data from index 13, apply reservations -5+3+2=0) © 2017 Magento, Inc. Page | 22
Order Placement – Step 8 Action: Reservation cleaning Looping through these reservations we could find reservations which in sum gives 0 (Zero) and remove them. © 2017 Magento, Inc. Page | 23
Order Placement – Step 9 (like Step 1) Raw data Index Data is NOT changed Reservations Reservation has been removed France Warehouse SKU-1: 3 qty EU Stock SKU-1: 13 qty Italy Warehouse SKU-1: 10 qty Available Qty: 13 qty (data from index, empty reservations) © 2017 Magento, Inc. Page | 24 No records
More information on Wiki page • New Indexer for Stock Items https: //github. com/magento-engcom/msi/wiki/New-Indexer-for-Stock. Items • Reservations https: //github. com/magento-engcom/msi/wiki/Reservations © 2017 Magento, Inc. Page | 25
Community Collaboration
Kanban board and Wiki are on the Git. Hub. © 2017 Magento, Inc. Page | 27
Slack Channel to Exchange ideas (#MSI) © 2017 Magento, Inc. Page | 28
Special Development In Special development direction we have started to work with Community • • • Benefit for Magento is creating new important feature Benefit for Community is increasing knowledge about Magento 2 Provide a set of best practices how to work with Magento 2 (some cookbook) © 2017 Magento, Inc. Page | 29
Related Links • Documentation https: //github. com/magento-engcom/msi/wiki • Roadmap https: //github. com/magento-engcom/msi/wiki/MSI-Roadmap • Dashboard https: //github. com/magento-engcom/msi/projects/1 • Weekly Demos https: //www. youtube. com/watch? v=Zt. BNIE 8 Fbj. I&list=PLr. Q 5 FBCRs. Eb. WK K 6 U_3 Awe 7 X-n. G 7 KY 0 WPW © 2017 Magento, Inc. Page | 30
Thank y’all! How to join us? Send an email to engcom@magento. com @_naydav