This sort of thing gets tricky when it comes to distributed systems. We use eventual consistency heavily in the API to guarantee speed & availability. Your solution will also fall down if multiple orders are placed at the same time.

The simplest solution I can think of that will guarantee the numbers are sequential is to use a database to store each order ID against an auto incremented ID (checkout, insert order id, get auto incremented ID back, PUT to order). That way the database will handle the complexity for you.

@James This adds complexity by adding a new external system into the equation. You can imagine what happens if that DB is unavailable for some reason Also, to have an external DB just for the auto-incrementation of the order number - sounds a bit extreme.

Since orders cannot be deleted or even pampered with, would it be possible that the Moltin API would expose a new property on orders that would handle that automatically? I imagine we’re not the only ones with such a use case. Sequential order numbers are quite popular between different tax authorities