Index / Snippets / Reserving and releasing order capacity w

Reserving and releasing order capacity with an event stream

Immutable events and negative orders instead of counters.

Answers
How do you reserve capacity for an online order while payment is still pending?
Topics
data · ecommerce · lemmid-store · payments · server · work
Full article on willem.com
https://willem.com/en/2020-12-02_designing-a-multi-dimensional-capacity-queue/

Summary

Store every order as an immutable timestamped event and reserve capacity the moment the order is placed. If payment fails or the order is abandoned, append a negative order with the same dispatch time to release the capacity.

Full text

I built this for my food ordering app, where three capacity dimensions interact: kitchen, pickup and delivery, each with its own timespan granularity, say 10 dishes per 15 minutes against 3 deliveries per 30 minutes. The design follows the Lambda Architecture: an append-only stream of immutable, timestamped events processed by a realtime speed layer and a batch precomputation layer. Every order is an event; cancelling an order of three pizzas appends a negative order of minus three pizzas with the same dispatch timestamp, which releases the reserved capacity without ever mutating a record. Metrics are computed from the real stream data in RAM. The first query initialises a model from historic data in batch, realtime updates keep it current while it is in demand, and answers arrive within milliseconds.

Machine formats of this page