Mongo E-commerce Application
Stack Used
- Dropwizard
- Jongo
- Dropwizard-Mongo bundle
- Lombok
Handling race conditions
I have used a "Write Then Read" approach for handling race conditions, the idea is to decrement the stock of an inventory first only if its current stock count is greater than zero. Then the number of modified documents is checked to verify if the stock actually got decremented, if no document got updated an exception is thrown.
Since updates to a document in MongoDB is atomic parallel decrements to stock is handled safely.
Prerequisites
- Java 1.8 installed
- Maven installed
- MongoDB installed and running locally at port 27017
Running The Application
sh setup.sh
- Adds some mock data to the inventories and accounts collections
- Installs dependencies
- Builds the JAR and runs the application at 8080
NOTE: The API is located in OrderRes.java
and can be the entrypoint for exploring the codebase.