A real-time food order fulfillment system for a delivery-only kitchen, built with Java 17 and Spring Boot.
mvn clean package -DskipTests
docker build -t cloudkitchens-solution
docker run --rm cloudkitchens-solution --challenge.auth=YOUR_AUTH_TOKEN
docker run --rm cloudkitchens-solution
--challenge.auth=YOUR_AUTH_TOKEN
--rate=500000
--min=4000000
--max=8000000
--seed=12345
When an order comes in, the system cooks it instantly and tries to store it in the best place. Hot food goes to heater it holds 6 orders. Cold food goes to the cooler it holds 6 orders. If those are full, food goes to the shelf it holds 12 orders
Well the food stored at the wrong temperature goes bad twice as fast. So a hot pizza sitting on the room temperature shelf will spoil in half the time compared to being in the heater.
When a courier arrives to pick up an order, check if it's still fresh. If it has gone bad, throw it away. If it's still good,hand it over.
When the shelf is full and we need to make room for a new order, we have to throw something away. I chose to discard the order with the least freshness remaining - basically, the one closest to going bad anyway.
The challenge asks for better than O(n) time complexity for the discard logic. I use a min-heap to track orders by their expiration time, which gives O(log n) for adding, removing, and finding the order to discard.
The system is built to handle orders and pickups happening at the same time. All the storage areas use read-write locks so multiple threads can read safly, but only one can write at a time. Action log uses thread safe list that handles concurrent reads and writes. And countdown latch makes sure wait for all orders to finish before submitting results.
- Timestamps are in microseconds as the challenge server expects
- All actions print to the console so you can follow along in real time
- Everything runs in a single process with multiple threads