dimanche 17 février 2019

Refractor monolithic code with based on multiple channel/clients

Let me start with 1000 ft view.

This is a typical e-commerce checkout process where multiple types of clients can place orders via multiple channels. Left most sites of pic-1 are channels – Mobile/Site/Customer Care/Point Of Sales/3rdParty and many more customized channels. Orders can be shipped with the different type of shipping methods -

  • Premium/Standard /Regular/NoHurryShipping/SameDayDelivery
  • Merchandise can be small (Jean/T-shirts/Shoes etc) or Big (Bed/Couch/Mattresses etc ). Order Type may also be multiple types – Regular Order / BuyOnlinePickInStore / BuyOnLineShipToStore
  • Multiple type of payment (Cash/Credit (3rdParty CC/ Private Level Card)/G-Pay/Apple-Pay/PayPal/GiftCard/Digital – Earned Money)

Each client has a different set of validation and business rules to place an order. They also have a different level of orchestration to call rules/services for example Customer Care will collect all the data at there system and place order by calling directly placeOrder. Online/Mobile will call create/Update and Place Order. Customer care also wants to execute business rules in a different order as compared to order placed from site/Mobile. POS also has a different set of rule want to invoke a chain of validation or rules on a different order. For example, the following are different rules/features of each client/channels-

Customer Care

  • Customer Care
  • They can waive off/Update amount of any items
  • Tax Exempt rules
  • Extra discounts
  • Can Applied Customer care specialized Promotions i.e.Waived-off - shipping Fee.
  • Accept Payment only – CC/Gift-Card
  • Many more business rules.

Online

  • Can have Small/Big Type of orders
  • Accept Payment for all type of Tenders – CC/GC/Paypal/G-Pay/Apple-Pay etc.
  • Only Online promotion code.

Mobile Order

  • Can have Small/Big Type of orders
  • Accept Payment for all type of Tenders – CC/GC/Paypal/G-Pay/Apple-Pay etc. Only Online promotion code.
  • Mobile-specific promotion code like first-time mobile app download
  • Location-based

Given these type of orders and rules are very less but in actual, there are lots of business rules. Problem is as shown in the below diagram. Current design

We have multiple microservice which are good but checkout process code is very much monolithic thousands of if/else condition calling multiple chains of methods which caused too much confusion because everywhere we have a condition based on Client/Channels/type of order/Shipping methods etc. Everything falls on Single Façade layer which has methods of 1000 lines with multiple if else.

I am suggesting a design where each client will have their own facade layer which will be invoked by FrontFacade (Routing Gateway) based Channel/Client. Each client specific facade can orchestrate and define their own specific rules and execute them in their own defined order. There will be separate layer with client agnostic validation and rules which can be invoked by any client.

I am looking comments/remarks/suggestions on this to defined better approach to refractor it with clear separation, execution, and clean code without disturbing of others business rules/validation etc.

Note: Except 3rdPaties, all other teams will be contributing writing codes for this checkout process and one core team will be defining all common rules/validation/persistence/downstream connectivity etc.

Proposed new design

Aucun commentaire:

Enregistrer un commentaire