GET /products?keyword=x&category=y&price=z&limit=20&cursor=
GET /users/{userId}/cart
POST /users/{userId}/cart/items
req - {
productId,
quantity,
}
Placing order api
POST /order
req - {
userId,
items[] :
{ id,
quantity
},
shippingAddress,
paymentMethodId
}
GET /users/{userId}/orders?fromDate=x&toDate=X&limit=20&cursor
POST /order/status
req - {
orderId,
status -> SHIPPED, OUT FOR DELIVERY, CANCELLED, DELIVERED
}
POST /users -> user creation
PUT /users/{userId} -> user updates
POST /auth -> user login
Acts as the entry point for all client requests.
Responsibilities:
Distributes traffic across multiple instances of all services to improve scalability and availability.
Responsbilities
Responsiblities
Responsibilites
Payment Service
User servuce
Responsiblities
Cart servuce
Respsonsiblies
Order Status Updates Webhook
Responsibilities
Payment Provider
CDN
Object storage
kafka
We will use SQL DB i.e. PostreSQL for our major tables. We need to ensure:
Hence, SQL fits best
Order
id
userId (partiton key)
status
totalPrice
paymentId
shippingAddressId
createdAt
UpdatedAt
OrderItem
id
orderId (partiton key)
productId
quantity
PriceAtPurchase
CartItems
id
userId (partiton key)
productId
quantity
price
User
id
name
country (partiton key)
primaryShippingAddressId
primaryPaymentMethodId
ShippingAddress
id
streeName
StreetAdd
City
PostalCode
Provice/State
Country
PaymentMethod
id
paymentProvider
refNo
Product
Id
Name
Title
Description
Price
ProductInventory
Id
ProductId
AvailableItems
LastUpdated
ProductMedia
Id
ProductId
Url -> CDN signed url
Also hot product details are cached in Redis for faster fetch
Now we will deep dive into these topics
Problem: Theres 1 stock left for an item, 2 users places order for the same item simultaneously for the same item. Without proper solutioning, this could result in both orders going rhought even tho theres not enought inventory
Solution: Use Single ACID transaction with row locking
Select * from ProductInventory
where ID = 123
FOR UPDATE
Payment Pending
Order Confirmed/ Payment Failed/ Cancelled
Order Shipped
Out for deliver/delivered
Problem -> User clicks pay and completes payment but during payment processing network timeout happens before our service gets response back, user then clicks pay again,user is charged twice without proper solutioning
Solution -> Use an idempotency key.
-> Use idemptoent Key