Order and payment platform
An order and payment flow across two Spring Boot services and Kafka, with Stripe, built to survive failures.
Commercial project under NDA
Engineering work
Engineering of event-driven ordering and payments, with idempotency and recovery scenarios.
- Industry
- E-commerce · Payments
- Technologies and integrations
- Java 21
- Spring Boot
- Apache Kafka
- PostgreSQL
- Keycloak
- Stripe
- Next.js
- Testcontainers
Overview
The order and payment flow of an online shop, with separate customer, admin and operations roles.
Challenge
Taking a payment crosses systems that fail halfway: a webhook arrives twice or out of order, Kafka goes down, a process crashes. The flow had to avoid charging or refunding twice, and an order had to reflect the truth about its payment.
Key areas of work
The order and payment flow was implemented as two Spring Boot services that communicate through Kafka, without direct calls between them. The work covered six areas.
- 01
Order service
A catalog, a cart, orders with a status history and cancellation. An order stays PENDING_PAYMENT until a PaymentSucceeded event arrives from Kafka.
- 02
Payment service
Payments with Stripe: PaymentIntents, 3-D Secure, declines and retries, full refunds and disputes. Stripe is called only by background workers, never inside a database transaction.
- 03
Event-driven saga
A choreography saga over Kafka, with a transactional outbox and inbox so that no event is lost or handled twice.
- 04
Idempotency and recovery
Idempotency at every boundary, including an HTTP Idempotency-Key. Duplicate requests, repeated or out-of-order webhooks, a crash or a Kafka outage mid-payment do not charge or refund twice, and a late payment on a cancelled order is refunded automatically.
- 05
Back office and operations
Admins see every order with filters and refund it; operations staff work with dead letters and reconciliation against Stripe.
- 06
Access and testing
Sign-in through Keycloak (OIDC, JWT, PKCE) with the services as Spring Security resource servers. Unit, architecture and integration tests, plus end-to-end scenarios and chaos tests, none of which needs a Stripe account.
Architecture and implementation details
Architecture
- 01
Web interface
A Next.js app for the shop, the order page, the back office and operations, with Stripe Elements for card entry.
- 02
Keycloak
Sign-in through OIDC with PKCE; both services check the JWT as Spring Security resource servers.
- 03
Order service
Orders, the catalog and the saga participant; an order waits in PENDING_PAYMENT for the payment event.
- 04
Kafka
The only way the two services talk: events through a transactional outbox and inbox.
- 05
Payment service
Payments, refunds, the Stripe gateway, webhooks and reconciliation; Stripe is called by background workers, outside transactions.
- 06
PostgreSQL
State, outbox and inbox live in PostgreSQL, migrated with Flyway.
Outcome
Six scenarios run end to end: a successful payment, a decline followed by a retry, 3-D Secure, a late payment that is refunded automatically, an admin refund and a dispute that flags the order.
Related service: Custom software development
Working on something similar?
Describe your system and the outcome you need, and we will suggest the next step.