English | Bahasa Indonesia
A coffee order is created unpaid: no queue number yet. After payment, Instance X assigns #1, #2, #3… Many customers can pay at the same time. Two different orders must never share the same number.
How this project solves it: pay enqueues a job. A worker calls Redis INCR for the next number, then saves it on the order in MySQL. Duplicate pay for the same order is ignored (idempotency). UNIQUE(store, day, number) is the safety net.
Fundamentals: async worker + Redis counter + MySQL orders. Not a payment gateway demo.
Behavior and race tests: scenarios.md
cp .env.example .env
make up migrate
npm install
npm run dev # API
npm run worker # Instance X (separate terminal)curl -X POST http://localhost:8081/orders -H 'Content-Type: application/json' -d '{"store_id":1}'
curl -X POST http://localhost:8081/orders/1/pay -H 'Content-Type: application/json' -d '{"payment_id":"pay-001"}'
curl http://localhost:8081/orders/1npm test
npm run test:integration
npm run test:concurrency