This application build in top of laravel 9 and dockerized by sail
- If not already done, install Docker Compose.
- Run
./vendor/bin/sail upto state the contender. - Use the collection to test the API.
- The main challenge here is every order may have multiple products that already have many ingredients which are shared between multiple products, and with concurrent orders, the ingredients will be updated from different orders at the same time
- The first solution we can do is to use DB transaction to guarantee the consistency of the ingredients but this solution will have some challenges and the main one is the high probability of facing a DeadLock Issue because overlap between orders
- My proposed solution is to add every update ingredient in a separate transaction to avoid any DeadLock issues but will increase the proccessing time
- The other part is notify when the stock reach limits and that will be done by worker will run every 5m to check if the current stock < init stock, and it was not notified before(by key in db) will send the email.
\App\Http\Controllers\Order\CreateControllerwill call the Command.\Foodics\Order\Command\CreateCommand:-
- will create the order with
pendingstatus.
- will create the order with
-
- Then will call the Service to add the products into the order
\Foodics\Order\Service\NewOrder\AddProductToOrder.
- Then will call the Service to add the products into the order
-
-
- Add ProductOrder Row then:
-
-
-
- start transaction and select the ingredient then deduct the quantity from it
-
-
-
- update ingredient and insert row for ProductOrderIngredient then close the transaction
-
-
- change order status to
placed.
- change order status to
- return
order_idwith201http status
- The first one is
FailedOrdersCleanerit responsible to check any order that create from5mand the status stillpending, so the worker will return the ingredients to stock again and change order status tocanceled. - The other one is
StockChangeNotifierit will check (current_stock+ uncompleted orders stock) < (init_stock/2) andnotifyflag is not flagged then will send email to admin and updatenotifyto be flagged
