IMPs
The purpose of this application, without going into too much detail, was to allow manufacturers to advertise and sell their dead inventory. Many manufacturers don't have an easy way to get rid of dead inventory in a profitable way. This application solved that problem. Our first client sold almost $1 million worth of dead inventory over a couple of months.
The hardest part of this project was writing transaction-like code for a database that didn't support transactions (MongoDB). We needed transactions because we kept track of inventory and purchases. Why not use a database like MySQL you ask? We had to use MongoDB because we were using a lot of our infrastructure and data from the Citywise App.
Did I say this feature was hard? Well, as it turned out, it was quite simple once I figured out a way to do it. Here’s how it can be done:
- Create an order with status “pending” (the order has an array of items and quantity ordered).
- Deduct the ordered quantity from inventory.
- If it fails (not enough inventory, for example), set status to “failed."
- Roll back the order.
- If it succeeds, set status to “completed.”
If the system ever goes down during this process, on startup, scan for orders that aren't completed and finish the steps it tried doing before. You’ll know which steps it needs to complete based on the order status.