Workflow of a sale
How a purchase travels through Kafka between sales, inventory, order, payment and delivery, and how Spark summarizes the payments at the end.
The journey of a sale
The five “microservices” are classes inside a single Spring Boot application that only talk through Kafka. Each one consumes a topic and publishes the next. Spark is a separate container that reads payment.processed at the end.
payment.processed has two readers: EntregaService during the simulation and Spark once the simulation has finished.How Inventory decides
It is the only place where the sale can stop. The reservation is all or nothing.
The sample purchase
| Product | SKU | Quantity | Subtotal | 16% VAT | Total |
|---|---|---|---|---|---|
| Blue t-shirt (Playera azul) | PLY-AZUL-M | 2 × $50.00 | $100.00 | $16.00 | $116.00 |
| Blue Levi's 502 jeans | LEV-502-AZUL | 1 × $600.00 | $600.00 | $96.00 | $696.00 |
| Whole sale | 3 | $700.00 | $112.00 | $812.00 |
$812.00charged in a single payment · final stock: 8 t-shirts and 4 jeans
The four scenarios
| Scenario | What happens | Topics published | Outcome |
|---|---|---|---|
| A · Successful saledefault purchase | the sale goes through all five services | 5 of 5 | delivery scheduled |
| B · Out of stock6 jeans, 5 in stock | Inventory rejects and no one else receives events | 1 of 5 | timeout |
| C · Spark analyticsafter the simulation | Spark reads the payments and groups by product | reads 1 | console table |
| D · Startup with start.sh./start.sh | cleanup, build, healthy Kafka, simulation and analytics | — | Kafka stays up |
Sequence diagram per scenario
Each scenario step by step, with every message between services and Kafka.