Design a Brokerage Order Processing Domain
Model a stock-broker order lifecycle with retry-safe client commands, recoverable venue interaction, execution reports, cancellation, and extensible policies.
Design the low-level domain and collaboration contracts for a stock broker's order-processing flow. For this exercise, assume the following authored product contract. An authenticated client may submit, inspect, and cancel orders only for an authorized account.
Submit must not reveal whether an unauthorized account exists; inspect and cancel must not distinguish an unauthorized order from a missing one.
A submitted order has an account-scoped clientOrderId, instrumentId, buy or sell side, market or limit type, positive integral quantity, and a positive integer-minor-unit limit price only for a limit order. At acceptance, an instrument listing fixes settlement currency and price scale.
Accepted economic terms are immutable. The broker validates an order, chooses one eligible execution venue through replaceable policies, and submits it. A venue accepts a stable client-generated request ID, may time out after receiving a request, and eventually associates an accepted request with venueOrderId.
Venue cancellation requires that venueOrderId and a stable cancelRequestId. Processes may crash and callers may retry. Exact command retries must not create duplicate venue side effects; conflicting reuse of an ID is rejected. At most one distinct cancellation may be pending.
Authenticated venue events can be duplicated or arrive out of order. Each has venueId, venueOrderId, eventId, a contiguous per-order sequence, kind, cumulativeFilledQuantity, and cumulativeNotionalMinor.
Kinds are FILL, ORDER_REJECTED, CANCEL_CONFIRMED, and CANCEL_REJECTED; cancellation events identify the related cancel request. A partial fill leaves the order open, a full fill yields FILLED, and rejection before any fill yields REJECTED.
A matching cancel confirmation on an open order yields CANCELLED; rejection clears the pending cancellation. Full fill or order rejection supersedes a pending cancellation, and a later cancellation outcome cannot overwrite that terminal state. A limit execution may not be worse than its limit.
Submission uncertainty, missing event sequences, and an accepted or ambiguous cancellation with no outcome event must each have a finite automatic-recovery budget and an operator-visible reconciliation outcome. Business terminal states come only from authenticated venue events.
A definitive known-not-accepted submission becomes an operator-visible delivery failure and any repaired retry reuses its request ID; a definitive known-not-accepted cancel delivery may clear pending cancellation without changing execution state.
Choose the object boundaries, persistence model, concurrency control, and crash-recovery mechanism. Explain the public and dependency interfaces, state transitions, one end-to-end journey, and how a new validation rule or routing strategy is added.
Market-data ingestion, venue matching internals, portfolio valuation, settlement, payments, and regulatory reporting are outside scope. No implementation code is required.