Use cases
Define the APIs expected from the system. This is your chance to analyze and define the read and write paths so that you can come up with the high-level design...
a) API Gateway: Acts as the front end for all the API services. Handles rate limiting and authentication through IAM. Forwards the request to either caching service, user details & history service, search service, product catalog service, inventory management service, cast service
URL: Root/api/v1/*
b) Search service API: Acts as an API for the users to search for products on the mobile app. Returns the relevant search items to the user mobile app. This API is trigerred by user mobile app
URL: GET: Root/api/v1/search?query={searchword}
c) Order service API: Acts as an API to create and fetch order. This API is trigerred by user mobile app
URL: GET: Root/api/v1/orders (or)
GET: Root /api/v1/orders?userId=U1&page=0&limit=10
URL: POST: Root/api/v1/orders
URL: GET: Root/api/v1/orders/{order_id}
d) User details service API: Acts as an API for the user to add or edit his details on the system. This API is trigerred by user mobile app
URL: GET: Root/api/v1/users
URL: PUT: Root/api/v1/users
e) Product Catalog service API: Acts as an API to display the product catalog to the user on his mobile app. This API is trigerred by user mobile app
URL: GET: Root/api/v1/productcatalog/
f) Inventory Management Service API: Acts as an API to update the inventory balance based on the transactions executed at the vending machine. This API is trigerred by the vendor machine
URL:PUT: Root/api/v1/im
g) Product Dispatch Service API: Acts as an API to the service the triggers request to vending machine to dispatch the product. This API is trigerred by the payment service. Returns dispatch status and details
URL:PUT: Root/api/v1/pds
h) Cart service API: Acts as an API to for the cart service.
URL:GET: Root/v1/cartservice
PUT: Root/v1/cartservice
POST: Root/v1/cartservice
Delete: Root/v1/cartservice
i) Payment service API: Acts as an API to handle payments. This API is trigerred by the order service. Returns payment status and transaction details
URL: POST: Root/v1/paymentservice
GET: Root/v1/paymentservice
j) Logging&Monitoring API: Acts as an API for the vending machine to send logs and machine diagnostics periodically. This API is for API gateway, from which the diagnostics
URL: POST:Root/v1/logNmontservice/machineID=abc
h) Notification service: API to send notification from the vending machine in case the inventory of a product falls below the threshold
URL: POST: Root/v1/notify/
and partitioned on
a. Created date in orders table
b. Created date in conversations table for faster data retrieval
Deep dive into 2-3 key components. Explain how they work, how they scale, discuss tradeoffs, capacity, and any relevant algorithms or data structures.
a) Database : 20 GB for primary and secondary database each, considering 100000 users annually with an average of 100 orders and 3 items per order and 300 vending machines and 5000 total products available in the catalogue, with SDD state storage, 4 CPU cores and 16GB RAM
b) IAM : Cloud native (Azure or AWS)
c) Load Balancer: Standard and cloud native. Scale up = >70% CPU for 10 min or memory > 75% for 10 min
Scale down = <40% CPU for 20 min or memory< 40% for 20 min
d) Event & Queuing_Broker: Standard tier (Azure service bus)
e) All the services will be container hosted with a RAM of 4 GB and CPU of 2 cores. These services will be behind a load balancer and a auto scaler
Network architecture:
Authentication:
The below is my authentication design: