Leonardo Mitsuo Fukuda
Work

2026 · Active

Order pipeline

An e-commerce order flow with FastAPI, NestJS, and RabbitMQ: payment and inventory progress through events, with compensation when stock is unavailable and no HTTP calls between domain services

Systems designFastAPINestJSRabbitMQPostgreSQLEvidence repositoryDocumentation

01 / Context & problem

The order pipeline is an e-commerce checkout that cannot hold the client until payment and inventory finish. Four services move forward through RabbitMQ events. Payment and stock are simulated: the repository shows the choreography, not a store.

  • POST returns 202 and status PENDING. Every event's correlation_id is the order_id.
  • Three endings: CONFIRMED, FAILED, and CANCELLED. CANCELLED includes a refund after unavailable stock.
  • No domain service calls another over HTTP.

02 / Role & scope

Order and Notification are Python. Payment and Inventory are NestJS, as supporting evidence. The repository includes the broker topology, per-service tests, and an optional end-to-end run against Compose.

  • The happy path, payment rejection, and missing stock are explicit scenarios in the order body.
  • Structured logs carry correlation_id so one order can be followed across services.
  • The spec and the decisions live under docs/ in the same repository.

03 / System architecture

The client creates the order in the Order Service. The broker publishes order.created. Payment answers approved or rejected. Inventory answers reserved or unavailable. Order closes the state and Notification writes a log.

  • Consistency is eventual. POST does not wait for payment or stock confirmation.
  • Rejected payment ends in FAILED. Unavailable stock after an approved payment requests and confirms a refund before CANCELLED.
  • Messages that fail three times go to the dead-letter queue. Replay republishes to the original queue and resets the attempt counter.

04 / Data model

The observable order state is the status and the timeline, both readable from the API. Logs are JSON with the same correlation_id. Compose publishes PostgreSQL on the host.

  • A catalog product with no stock is fixed in the README for the compensation scenario.
  • Dead-letter inspection goes through an admin endpoint on the Order Service.
  • This study does not republish the table schema. The proof of the flow is the final status and the timeline.

05 / Engineering decisions

Choreography stays in the broker, with no orchestrator in the middle. This repository stays on RabbitMQ. Kafka, Kubernetes, and the observability dashboard went to Observa, the following project.

  • /metrics exposes Prometheus text. There is no scrape and no Grafana here.
  • CI covers pytest and jest. The live run only starts if the Order Service is already up.
  • Dead-letter replay requires a development admin token. The Compose value is not a production secret.

06 / Implementation

docker compose up --build starts Order on port 8000, Notification on 8001, Payment on 3001, Inventory on 3002, and RabbitMQ management on 15672.

  • Order tests use pytest and Testcontainers, so they need Docker.
  • Payment and Inventory run npm test. Notification has its own pytest suite.
  • python -m pytest tests/e2e is the run against Compose already started, outside CI.

07 / Product experience

There is no storefront. A reviewer creates the order with a simulate block: payment approve or reject, stock reserve, unavailable, or catalog. Then they read the order and the timeline until the final state.

  • The happy path asks for approved payment and reserved stock.
  • Payment failure uses reject and ends in FAILED.
  • Compensation uses approved payment and unavailable stock, through payment.refunded and CANCELLED.

08 / Results

The three outcomes are described with payloads and with a catalog product that has no stock. The repository publishes no percentiles for this flow.

  • GET /orders/{id} and GET /orders/{id}/timeline are how the result is read.
  • The dead-letter queue can be listed and replayed through the admin endpoint.
  • The end-to-end run is not part of what CI executes on each push.

09 / Retrospective

The project shows compensation and a dead-letter queue in a local environment, with the simulation declared on the order. It does not show load, a store, or a real payment.

  • Replay returns the message to the original queue. It does not rebuild the message's original place in the flow.
  • Observa takes a similar journey to Kafka, local Kubernetes, and Grafana. This repository stays on RabbitMQ.
  • A production claim would need real payment and inventory services, and a load this Compose does not represent.