The basic requirement is for the system to be able to provide a website and all associated services like product management, inventory management, order processing and tracking and payment integration for every merchant that registers with the system.
Merchant Store Management Service
POST/api/v2/createStore
PATCH/api/v2/updateStore?id=x;
Product Management Service.
POST/api/v2/store/createProduct
PATCH/api/v2/store/updateProduct?productid=x;
API to view Products- GET/api/v2/product?id=x;
API to search products GET api/v2/products/search
Order Management Service
API to place an order with the system.
POST/api/v2/createOrder
Customer Management Service
API to add, update, delete customers from the Merchant's store
POST/API/v2/createCustomer.
Inventory Management Service
API to fetch merchant's inventory for a specific store
GET api/v2/store/id/inventory
API to add details to merchants's inventory for a specific store
PUT api/v2/store/inventory/createInventory
Merchant Service
Allowing for new merchants to be registered to the system
POST api/v2/createMerchant
Every new merchant registered with the system will be allocated with resources, and web application components and databases for their own isolated management.
The main goal of this system will be to enable customers to place orders on the merchant's store's website. We need strong consistency and accuracy around the data, because this will involve, modifying item's inventory and making payments. We will choose a Relational Database for this design.
The merchant's data and the related metadata can also be stored in a relational database, for the system.
1) Merchant Database - merchant_id, merchant_metadata_id, date_Created.
2) Merchant_metadata_id - merchant_metadata_id, merchant_name, merchant_num_stores, merchant_location, merchan_Additional_info, merchant_preferred_payment etc.
For every merchant, they will have the below database design
1) Customer - customer_id, customer_name, customer_email, date_created.
2) Item- item_id, item_name, item_date_created, inventory_id
3) Inventory- inventory_id, inventory_num
4) Orders - order_id, date_Created, order_amount, order_Status, payment_id etc.
5) Payment - payment_id, payment_status, payment_method_info, date_created.
Merchant Orchestrator - Since we need all merchants to be isloated from each other, we can use a container orchestration platform like Kubernetes for this. When a merchant registers itself with the system, the system triggers an automated deployment to spin up a merchant pod for the merchant. This process will involve creating containers for the services required by the merchant pod to exist like database, web application components and web servers.
Kubernetes provides a host of services like monitoring and maintaining the health of these pods, load balancing and allocation of resources etc.
This way, we can have a seamless way of spinning up merchant pods for different merchants and keep them isolated too.
For the database, we are using MySQL or PostGres SQL - This will ensure strong consistency for the data. We can optimise by directing reads from read replicas, and writing to master node.
For search functionality on the merchant's store, we can use inverted indexes for product search . that will help deliver faster results.
MySQL vs NoSQL - MySQL is chosen because we need a more consistency and accuracy of data here. More than the amount of data, since we are making payments, and updating order inventory, we make use of the ACID properties of MySQL.
Microservices based architecture - Because we have a lot of different tasks involved, microservices are best suited to localise the functionalities and deal with failures/issues with different services at an isolated level.