Async task processing

Integrated PostgreSQL and RabbitMQ for task queues. Improved reliability and speed of the internal delivery service.

Async task processing

Challenge

Sushi-Love's internal order service processed everything synchronously - availability check, price calculation, kitchen notification, database write. Each request took 2-3 seconds. During peak hours, load spiked 5-8x and requests started timing out. Orders were getting lost.

Technical details

Solution

I split it into two stages: fast acceptance and background processing. The API now just validates the order, writes to PostgreSQL with "accepted" status, and publishes to RabbitMQ - 100-200ms, customer gets instant confirmation. Workers pick up messages and do the heavy work: price recalculation, inventory check, kitchen dispatch. Each worker runs in a PostgreSQL transaction - if it fails, the message goes back to the queue. Set up a dead letter queue for orders that fail after 3 attempts - separate queue for manual review.

Result

Zero order loss - RabbitMQ buffers the spikes. API response time dropped from 2-3 seconds to 150-200ms. During Friday peaks the service handles 200+ orders per hour without issues.

218 views