Skip to content

Policy Controller Service for the flash sales system

Notifications You must be signed in to change notification settings

weswu8/policycontroller

Repository files navigation

Flash Sale System Demo

Flash sale becomes more and more popular among the ecommerce platforms. but there are few articles/blogs addressed the system in detailed level. And hardly find the code samples. Here we are. This system contains 5 separated micro service: GateKeeper, SafeProtector, PolicyController, InventoryManager and Shopping Cart. 闪购在电商中已经越来越流行。现在很少有资料详细的介绍闪购平台的架构,也很少有源码参考。我这个闪购平台的系统包含了5个微服务:: GateKeeper, SafeProtector, PolicyController, InventoryManager and Shopping Cart. The objective of the flash sales system is to handle the massive customer requests, filter the traffic based on the business logic ,and protect the back end system. In order to get more scalability , all this micro service can deployed on Docker. 闪购平台的目标在于能够处理前端大量的请求,按照业务要求请这些请求逐级过滤,并能够很好的保护后端的系统,避免后端系统被巨量的请求压垮。

感谢马利超同学的分享,这个DEMO的许多想法源于此。

Micro Service

#####GateKeeper Service this micro service will sit front of the whole system, it will handle the massive client requests and keep the connection with those clients, and will be re-distribute the request to others micro service.

#####GSafeProtector Service this micro service will filter the request by IP and Account ID. Once the request matches the blacklisted IP and Account ID, this request will be reject. And we will analytics the traffic in near real-time period , and will update the backlist dynamically.

#####PlicyController Service this micro service will process the business logic. Currently can set the limitation of purchase unit according to the user level.

#####InventoryManager Service this micro service will manage the goods inventory. We will check the inventory information when user adding goods to the shopping cart.

#####ShoppingCart Service this micro service will manage the shopping cart of the customer, and will freeze the quantity of the specified goods when it was added to shopping cart successfully. And will release the goods based on some time periods.

#####EurekaServer Service this micro service will manage the service discovery and health mornitoring.

System Architecture

architecture

Service API

Name Path Method Request Body Response Body
doPolicyValidation /validate/sid/{sid}}/userid/{userid}}/userlv/{userlv}}/sku/{sku}/quantity/{qty} GET None {"sessionID":"sid00001","userID":"FS000001","goodsSKU":"QT3456","userLevel":5,"orderQuantity":1,"isAllowed":true,"isThrottled":false,"version":"1.0"}
addPolicy /policy/add POST {"goodsSKU":"SKU0001","userLevel":5,"quantityLimit":1} {"goodsSKU":"SKU0001","userLevel":5,"quantityLimit":1}
addUserOrders /user/add POST {"userID":"UID0000000001","goodsSKU":"SKU0001","userLevel":5,"orderQuantity":1,"isAllowed":false} {"userID":"UID0000000002","goodsSKU":"SKU0007","userLevel":5,"orderQuantity":1}
findAllItems-Policies /policy/all GET None [{"goodsSKU":"SKU0001","userLevel":3,"quantityLimit"}]
findAllItems-UserOrders /user/all GET None [{"userID":"FS00000001","goodsSKU":"QT3456","user}]
getPolicy /policy/sku/{sku} GET None {"goodsSKU":"SKU0001","userLevel":5,"quantityLimit":2}
getUserOrders /user/userid/{uid}/sku/{sku} GET None {"userID":"UID0000000001","goodsSKU":"SKU0001","userLevel":5,"orderQuantity":1}
removePolicy /policy/delete/sku/{sku} DELETE None {"goodsSKU":null,"userLevel":0,"quantityLimit":0}
removeUserOrders /user/delete/userid/{uid}/sku/{sku}} DELETE None {"goodsSKU":null,"userLevel":0,"quantityLimit":0}
updatePolicy /policy/update PUT {"goodsSKU":"SKU0001","userLevel":5,"quantityLimit":2} {"goodsSKU":"SKU0001","userLevel":5,"quantityLimit":2}
updateUserOrders /user/update PUT {"userID":"UID0000000001","goodsSKU":"SKU0001","userLevel":5,"orderQuantity":2} {"userID":"UID0000000001","goodsSKU":"SKU0001","userLevel":5,"orderQuantity":2}

Performance

To-do