How quangiscoding/flashsale-engine works
This is a flash-sale order service: clients submit checkout requests, the API assigns an order ID and queues each request, and a worker processes it asynchronously. The worker uses a database transaction to decrement product stock and record the order, rejecting sold-out items. A separate initializer creates and seeds the database schema. The excerpts show the API and worker connecting to RabbitMQ and the worker accessing PostgreSQL through a pool; other deployment details are not shown.
Main entry points: index.ts PostgreSQL pool · worker.ts Order worker · init.ts Schema initializer · api.ts Checkout API
Components 7
Order intake
- Checkout API
app/src/api.ts
Message queue
- RabbitMQ queue
Fulfillment and storage
- Order worker
app/src/worker.ts - PostgreSQL pool
app/src/db/index.ts - PostgreSQL
- Schema initializer
app/src/db/init.ts
Other components
- Checkout client
Connections 7
- Checkout client → Checkout API: submits checkout
app/src/api.ts - Checkout API → RabbitMQ queue: publishes order
app/src/api.ts - Order worker → RabbitMQ queue: consumes orders
app/src/worker.ts - Order worker → PostgreSQL pool: queries database
app/src/worker.ts - PostgreSQL pool → PostgreSQL: connects to
app/src/db/index.ts - Schema initializer → PostgreSQL pool: opens connection
app/src/db/init.ts - Schema initializer → PostgreSQL: creates and seeds
app/src/db/init.ts