A microservice sample for building an e-commerce backend. Medium article write-up on this project can be found here here
- The application uses an API gateway to bind all services along a single front, acting as a proxy for the domains in which the
auth,orderandproductmicroservices are deployed on - Each microservice, the API gateway and RabbitMQ are deployed as Docker images
- Interactions between
productservice andorderservice uses AMQP protcol, using RabbitMQ which consists of two queues -ordersandproducts. This saves on resources allocated for REST calls to MongoDB. productservice publishes to the order queue which is then consumed and collated byorderserviceorderservice publishes ordered products to the product queue which is then consumed byproductto return order details
- The architecture for a microservice is inspired by Uncle Bob's Clean Architecture, which supports strong modularity, loose coupling and dependency injection
Tech Stack: Node.js, Express, MongoDB, Docker, RabbitMQ, Mocha, Chai
- Have npm and Node.js on your machine
- Have Docker installed
- Have RabbitMQ installed
- Set up your own MongoDB collection with appropriate security/credential settings
- Create a .env file following the format specified in the
/auth/env.example,order/env.exampleandproduct/env.exampledirectories, following the format specified in each microservice directory - Run
docker-compose build - Run
docker-compose up. Now you can test the APIs from localhost:3003
- Create a .env file following the format specified in the
/auth/env.example,order/env.exampleandproduct/env.exampledirectories, following the format specified in each microservice directory - Run
npm installin the/auth,/product,/orderand/api-gatewaydirectories - Run
npm starton all four directories mentioned in the step above. Now you can test the APIs from localhost:3003
-
It could be useful to use Kubernetes for container orchestration in order to bundle up this project into one cohesive unit
-
While I tried to follow a TDD approach - that is, letting test cases guide development - I eventually gave up on it in the name of speedy development. Ideally, I could have written unit tests first, and slowly increment up to integraton tests and then system tests.
-
The internal service of each microservice does not follow pure dependency injection advocated in Clean Architecture. The internal file structures and flow of dependencies are loosely based on Clean Architecture and the code does not fully utilise dependency injection principles. While I did try to minimise interdependencies, I found it a bit overkill to follow Clean Architecture fully for what is essentially a take-home project. But it is worth trying eventually.
-
I'd like to write a series of Bash scripts with various
curlcommands to automate API testing and follow them in sequence of particular use-cases (e.g. user publishes product -> another user logs in -> other user buys product -> ...) -
It could be a good exercise to deploy the databases across different platforms (e.g. Firebase, SQL, etc.) to prevent a single point of failure

