Amirali YaghoutiSenior Software Engineer

webapp Case study

Back-to-back API Sales System

Selling stock you do not hold means every order is a bet that the supplier's price and availability are still what they were when the page was rendered. This flow removes the bet by reconfirming both at the moment of commitment.

The business problem

Back-to-back trading fails in a specific way: the customer buys at a price that was accurate when the catalogue was cached, the supplier price has moved, and the business is committed to a loss it discovers at fulfilment. Caching supplier prices is unavoidable for a usable catalogue, so the correctness has to be enforced at the point of commitment rather than at the point of display.

What I delivered

  • An API-driven order flow that reconfirms price and availability with the supplier before the order is committed.
  • Margin rules evaluated at that same point, so an order that no longer clears the margin threshold is stopped rather than fulfilled at a loss.
  • A review step for orders that fall outside the rules, so an edge case becomes a decision instead of an automatic rejection or an automatic loss.
  • A clear separation between the displayed price, which may be cached, and the committed price, which never is.

Technical approach

  • Display and commitment are treated as different guarantees. The catalogue can be fast and approximate; the commitment has to be current and exact.
  • The margin rule is checked at commitment because that is the only moment at which all the inputs are actually known.
  • Orders outside the rules are routed for review rather than rejected, since a rule that silently loses business is as expensive as one that loses money.
  • The supplier confirmation is part of the order path rather than a background reconciliation, so a problem is caught before the business is committed rather than after.

Result and evidence

Orders commit at a price and availability confirmed with the supplier at that moment, and orders that would breach the margin rule stop for a decision instead of proceeding.

Commercial value

In back-to-back trading the margin is thin enough that a stale price is not a rounding error, it is the profit. Enforcing it at commitment is where that gets protected.

implementation-brief.readme

Readable implementation brief

implementation_brief {
  project: "Back-to-back API Sales System"
  model: "sell inventory held by the supplier, not by us"
  display_price: "may be cached; fast and approximate"
  committed_price: "reconfirmed with the supplier, never cached"
  margin_rule: "evaluated at commitment, when inputs are known"
  exceptions: "routed to review, not auto-rejected"
  placement: "confirmation is in the order path, not a
              background reconciliation"
}

What this project shows

Separating the displayed price from the committed price is the core idea and it generalises well beyond this project. Most systems that get burned by stale data have conflated the two.

Sending exceptions to review rather than rejecting them is a commercial judgement as much as a technical one. Rules that only ever say no get switched off.