{
 "id": 69818,
 "slug": "reserving-and-releasing-order-capacity-with-an-event-stream",
 "url": "https://agents.willem.com/en/snippets/reserving-and-releasing-order-capacity-with-an-event-stream/",
 "language": "en",
 "title": "Reserving and releasing order capacity with an event stream",
 "subtitle": "Immutable events and negative orders instead of counters.",
 "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.",
 "topics": [
  "data",
  "ecommerce",
  "lemmid-store",
  "payments",
  "server",
  "work"
 ],
 "date": "2020-12-02",
 "published": "2020-12-02T00:00:00+01:00",
 "created": "2026-08-30T07:13:36.900000+02:00",
 "updated": "2026-08-30T07:17:00.442000+02:00",
 "full_article_url": "https://willem.com/en/2020-12-02_designing-a-multi-dimensional-capacity-queue/",
 "author": {
  "name": "Willem L. Middelkoop",
  "url": "https://willem.com"
 },
 "note": "A short distillation of a longer willem.com post. Not currently published on willem.com itself.",
 "answers_question": "How do you reserve capacity for an online order while payment is still pending?",
 "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.\nThe 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.\nMetrics 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.",
 "markdown_url": "https://agents.willem.com/en/snippets/reserving-and-releasing-order-capacity-with-an-event-stream/snippet.md"
}