Inventory Reservations
Inventory reservations are stored on a per-FulfillmentGroupItem
level and each FulfillmentGroupItem
can have multiple reservations representing different quantities fulfilled at different locations. Inventory Reservations are persisted at checkout in order to store which location inventory was decremented from. This allows you to see exactly where your order should be fulfilled from on the backend.
Reservation Strategies
In order to customize how inventory reservations are distributed within a FulfillmentGroup, there is a common interface called the InventoryReservationStrategy
. The out of the box strategies are:
Name | System Property Value |
---|---|
Single location per group | SINGLE_PER_GROUP |
Single location per item | SINGLE_PER_ITEM |
Multiple locations per item | MULTIPLE_PER_ITEM |
To select between them, override the advanced-inventory.item.reservation.strategy
system property with one of the above values:
advanced-inventory.item.reservation.strategy=SINGLE_PER_GROUP
The default strategy is SINGLE_PER_GROUP
Each of these strategies is documented in more detail below.
Customizing Reservation Strategies
A few steps to create your brand new reservation strategy:
- Create a Spring bean that implements this InventoryReservationStrategy interface
Create a subclass of
InventoryReservationStrategyType
to add your own custom typeFor instance:
public class MyReservationStrategyType extends InventoryReservationStrategyType { public static InventoryReservationStrategyType LOCATION_BASED = new InventoryReservationStrategyType("LOCATION_BASED", "Location Based"); }
Change the
advanced-inventory.item.reservation.strategy
system property to the value of your newInventoryReservationStrategyType
Following the above example that would be:
advanced-inventory.item.reservation.strategy=LOCATION_BASED
This component will then be automatically injected and used by the AdvancedInventoryServiceExtensionHandler
.
Further Reading
InventoryReservation
InventoryReservationStrategy.java
SingleLocationPerGroupReservationStrategy.java
SingleLocationPerItemReservationStrategy.java
MultipleReservationPerItemReservationStrategy.java
Out of the Box Strategies
Consider the following data scenario:
Location 1
SKU_ID | Quantity |
---|---|
1 | 3 |
2 | 3 |
Location 2
SKU_ID | Quantity |
---|---|
1 | 1 |
2 | 1 |
Location 3
SKU_ID | Quantity |
---|---|
2 | 10 |
Single Location Per Group
This strategy is designed to ensure that for an entire Fulfillment Group must be fulfilled from the same location. In the example data above, this translates to the following:
- Sku ID 1 can have a maximum quantity of 3 items within a fulfillment group
- Sku ID 2 can sell a maximum of 10 items within a fulfillment group
So, the following order will succeed:
O_ID | FG_ID | FGI_ID | SKU_ID | Quantity |
---|---|---|---|---|
1 | 1 | 1 | 1 | 2 |
1 | 1 | 2 | 2 | 1 |
And would create the following inventory reservations:
FGI_ID | FL_ID | Quantity |
---|---|---|
1 | 1 | 3 |
2 | 1 | 1 |
But the this order would not suceed:
O_ID | FG_ID | FGI_ID | SKU_ID | Quantity |
---|---|---|---|---|
1 | 1 | 1 | 1 | 2 |
1 | 1 | 2 | 2 | 5 |
Even though Location3
has enough inventory to handle buying 5 of Sku2, it does not have any inventory for Sku1. This would put different items in a single fulfillment group in different locations and thus fail.
Single Location per Item
This strategy is slightly more flexible than the original, and allows for different items within a Fulfillment Group to be fulfilled from different locations. However, each location must have enough inventory to handle the quantity for that Sku. So the previously failed order would now succeed:
O_ID | FG_ID | FGI_ID | SKU_ID | Quantity |
---|---|---|---|---|
1 | 1 | 1 | 1 | 2 |
1 | 1 | 2 | 2 | 5 |
And create the following inventory reservations (notice the different locations for the fulfillment group items):
FGI_ID | FL_ID | Quantity |
---|---|---|
1 | 1 | 2 |
2 | 3 | 5 |
But this strategy would still fail given this order:
O_ID | FG_ID | FGI_ID | SKU_ID | Quantity |
---|---|---|---|---|
1 | 1 | 1 | 1 | 4 |
While the combination of Location1
and Location2
have a total quantity of 4 for Sku1, there is not enough for the entire quantity of the item to be fulfilled at a single location. We would have to split the fulfillment across multiple locations for a single item.
Multiple Locations per Item
This is the most flexible strategy and allows for a single item with multiple quantities to be fulfilled across different locations. The above scenario would now succeed:
O_ID | FG_ID | FGI_ID | SKU_ID | Quantity |
---|---|---|---|---|
1 | 1 | 1 | 1 | 4 |
And create the following inventory reservations:
FGI_ID | FL_ID | Quantity |
---|---|---|
1 | 1 | 3 |
1 | 2 | 1 |
Other Considerations
- All of the out of the box
InventoryReservationStrategy
implementations prioritize inventory by either minimum or maximum quantity at a Fulfillment Location. You can easily customize this prioritization specifically with theadvanced-inventory.prioritize.higher.quantity
andadvanced-inventory.prioritize.lower.quantity
. If both of these system properties are false, inventory will not be prioritized - If you are using either the single location per group or single location per item, in order to retrieve the quantity available for a Sku the system uses the maximum quantity avilable at a single Fulfillment Location rather than sum up all the quantities for the Sku across all Fulfillment Locations. If you need to further customize this, subclass the
AdvancedInventoryServiceExtensionHandler
and override theblAdvancedInventoryServiceExtensionHandler
bean. - The out of the box strategies can be somewhat non-deterministic if inventory counts are the same within each Fulfillment Location for an individual Sku