Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/microservices-patterns/ftgo-application/llms.txt

Use this file to discover all available pages before exploring further.

The Order Service is the central coordinator of the FTGO application. It manages the full lifecycle of a customer order — from initial placement through approval, revision, and cancellation — and drives the distributed transactions that coordinate across Consumer, Kitchen, and Accounting services via the Saga pattern. This page covers the service’s responsibilities, domain model, REST API, messaging interactions, and database schema.

Responsibilities

  • Accept new order requests from the API Gateway and persist them as Order aggregates
  • Orchestrate the CreateOrderSaga to verify the consumer, create a kitchen ticket, and authorize payment in a single distributed transaction
  • Orchestrate the CancelOrderSaga to reverse a kitchen ticket and payment authorization when a customer cancels
  • Orchestrate the ReviseOrderSaga to adjust line-item quantities while keeping the kitchen and accounting services consistent
  • Publish domain events (OrderCreated, OrderAuthorized, OrderCancelled, OrderRejected, OrderRevised) so downstream services can react
  • Maintain a local replica of restaurant menus by consuming RestaurantCreated and RestaurantMenuRevised events

Domain Model

The core aggregate is Order, persisted to the orders table.
FieldTypeNotes
idLongAuto-generated primary key
versionLongOptimistic locking version
stateOrderStateEnum stored as VARCHAR
consumerIdLongReference to the placing consumer
restaurantIdLongReference to the target restaurant
orderLineItemsEmbeddedCollection of OrderLineItem
deliveryInformationEmbeddedDelivery time and address
paymentInformationEmbeddedPayment details
orderMinimumMoneyMinimum order total enforced on revisions

Order states

APPROVAL_PENDING → APPROVED → CANCEL_PENDING → CANCELLED
                            ↘ REVISION_PENDING → APPROVED
             ↘ REJECTED
An order starts in APPROVAL_PENDING the moment it is saved. The CreateOrderSaga moves it to either APPROVED (via noteApproved()) or REJECTED (via noteRejected()). Cancellation and revision both go through intermediate pending states to support saga compensation.
The Order aggregate enforces the order minimum on revisions — if the revised total meets or exceeds orderMinimum, an OrderMinimumNotMetException is thrown before the saga begins.

REST API

The service listens on port 8082. All endpoints are under the /orders path.
MethodPathDescription
POST/ordersCreate a new order; returns { orderId }. Kicks off CreateOrderSaga.
GET/orders/{orderId}Retrieve order state and total. Returns 404 if not found.
POST/orders/{orderId}/cancelBegin cancellation via CancelOrderSaga. Returns 404 if not found.
POST/orders/{orderId}/reviseAdjust line-item quantities via ReviseOrderSaga. Returns 404 if not found.

Create order request body

{
  "consumerId": 1,
  "restaurantId": 2,
  "deliveryTime": "2026-05-21T18:30:00",
  "deliveryAddress": {
    "street1": "9 Amazing View",
    "city": "Oakland",
    "state": "CA",
    "zip": "94612"
  },
  "lineItems": [
    { "menuItemId": "kl", "quantity": 1 }
  ]
}

Revise order request body

{
  "revisedOrderLineItems": [
    { "menuItemId": "kl", "quantity": 2 }
  ]
}

Messaging

Events published

The OrderDomainEventPublisher emits the following events on the net.chrisrichardson.ftgo.orderservice.domain.Order channel:
EventTrigger
OrderCreatedEventNew order saved; contains OrderDetails, delivery address, and restaurant name
OrderAuthorizedCreateOrderSaga completes successfully
OrderRejectedCreateOrderSaga fails (consumer or payment validation)
OrderCancelledCancelOrderSaga confirms cancellation
OrderRevisionProposedReviseOrderSaga begins; includes old and new totals
OrderRevisedReviseOrderSaga confirms revision

Events consumed

Source aggregateEventHandler
RestaurantService.RestaurantRestaurantCreatedCreates a local menu replica via OrderService.createMenu()
RestaurantService.RestaurantRestaurantMenuRevisedUpdates the local menu replica via OrderService.reviseMenu()

Saga command channels

The Order Service orchestrates sagas that send commands to:
  • consumerServiceValidateOrderByConsumer
  • kitchenServiceCreateTicket, ConfirmCreateTicket, CancelCreateTicket, BeginCancelTicketCommand, ConfirmCancelTicketCommand, BeginReviseTicketCommand, ConfirmReviseTicketCommand
  • accountingServiceAuthorizeCommand, ReverseAuthorizationCommand, ReviseAuthorization
The Order Service is the saga orchestrator. It creates saga instances via SagaInstanceFactory and drives the saga state machine, but does not handle saga commands itself — those are handled by the participant services.

Database

The Order Service uses MySQL (shared Eventuate Tram schema). Key tables:
TableDescription
ordersThe Order aggregate: state, consumer ID, restaurant ID, delivery info, payment info
order_line_items@ElementCollection embedded within the orders table (via OrderLineItems)
restaurantsLocal replica of restaurant data including menu items used for line-item validation
Saga state is stored in the Eventuate Tram saga_instances table. Transactional outbox messages are written to the message table and relayed by the CDC service (Eventuate Tram CDC).
Because orders start in APPROVAL_PENDING before the saga completes, clients should poll GET /orders/{orderId} or consume OrderAuthorized/OrderRejected events to determine the final state rather than assuming the POST /orders response reflects approval.

Build docs developers (and LLMs) love