OMS DATA-FLOW

Key Components

  1. Order Initiation
    • Order Creation: Initiates an order and generates an orderId if not present.
    • OrderStatus Table: Stores the status of the order with timestamps.
    • OmsTaskEvent: A Kafka event encapsulating order details and current status.
  2. Event Publishing and Listening
    1. Kafka Topics:
      • internal_lead_generate: Main topic for internal event processing.
      • internal_drp_lead_submit: For submitting leads to external systems.
      • internal_drp_lead_status: For updating lead statuses.
    2. LeadProcessingEventListener: Listens to internal_lead_generate and processes events asynchronously.
  3. Processing Actions
    • OrderTaskProcessor: Interface for processing tasks based on order events.
    • EventActionFactory: Implements the Factory Pattern to instantiate appropriate action handlers.
    • Action Handlers:
      • GenerateLeadPdfAction
      • LeadCreateEventAction
      • UpdateCheckoutAction
      • SendLeadSubmitNotificationAction
  4. Database Interactions
    • OrderStatus Table: Tracks the current status of each order.
    • OrderError Table: Logs any errors encountered during processing.

Flow Summary

  1. Order Initiation
    • An order is initiated, and an orderId is generated if not present.
    • The initial status ORDER_INITIATED is saved to the orderStatus table.
    • An OmsTaskEvent is created and published to the internal_lead_generate Kafka topic.
  2. Event Processing
    • LeadProcessingEventListener consumes the event from Kafka.
    • OrderTaskProcessor uses EventActionFactory to determine the appropriate action based on the OrderEvent.
    • Actions are executed in sequence, updating the orderStatus and publishing new events as needed.
  3. Error Handling
    • If any action fails, the error is logged in the OrderError table, and the order status is updated to ORDER_FAILURE.
  4. Completion
    • Once all actions are successfully executed, the order status reaches SENT_NOTIFICATION, concluding the order processing.

LLD Flow

  1. Initiate order & get the “orderId” of orderCreation request.
    1. If “orderId” is not present, create one.
    2. Save the order status in orderStatus table (PostgreSQL)
      • orderStatus table has
        • orderId
        • orderStatus ENUM (ORDER_INITIATED(used in this step), LEAD_PDF_CREATED, VEHICLE_LEAD_SUBMITTED, CART_UPDATED, SENT_NOTIFICATION, ORDER_FAILURE)
        • created_time
    3. getOmsTaskEvent : (OmsTaskEvent - Kafka Event) 
      • headers
      • orderDTO
        1. The below fields are populated in this step
        • orderId
        • cartId
        • consumerInfo
        • dealerInfo
        • leadType (IMPLICIT, EXPLICIT)
        1. The below fields will be populated later when LeadProcessingEventListener listens to this event
        • List pdfFiles
        • CartDetails
        1. The below field will keep on changing on each step (1st and 2nd during each step)
        • OrderStatus
          • orderId
          • Value (ORDER_INITIATED, LEAD_PDF_CREATED, ORDER_CREATED, CART_UPDATED, SENT_NOTIFICATION)
      • x-correlationId
      • TaskError
      • Set next orderEvent (CREATE_LEAD_PDF*(used in this step) , CREATE_AURORA_LEAD, UPDATE_CHECKOUT_COMPLETED, SEND_LEAD_SUBMIT_CONFIRMATION_NOTIFICATION)
      • (Extended from Platform Kafka Event) typeName : helps identify which Listener will listen to this event and process it.
    4. Publish the event in “internal_lead_generate” topic.
  2. LeadProcessingEventListener will now process the OMS Task Event
    1. orderTaskProcessor interface processes OMS task event.
    2. processes tasks asynchronously by executing actions based on the type of OrderEvent received.
    3. The OrderTaskProcessor class uses the Factory Pattern through the EventActionFactory class.
      • Factory Class (EventActionFactory):
        • The EventActionFactory - creates instances of different actions based on the OrderEvent type.
        • method getAction(OrderEvent orderEvent): returns an appropriate action instance based on the OrderEvent type.
      • Client Class (OrderTaskProcessor):
        • The OrderTaskProcessor class uses the EventActionFactory to get the appropriate action for the given OrderEvent.
        • It calls the execute method on the action instance returned by the factory.
    4. GenerateLeadPdfAction
      • Fetch the cartDetails of that cartId //TODO: write and learn what’s in cartDetails
      • Convert pdfs to base64 and add them to orderDTO in OmsTaskEvent
      • Save OrderStatus in orderStatus table to LEAD_PDF_CREATED
      • Set the next orderEvent of OmsTaskEvent to CREATE_AURORA_LEAD
      • Publish the event in “internal_lead_generate” topic.
    5. LeadCreateEventAction
      • LeadType.EXPLICIT
        • VehicleLeadService class is called to transform the OmsTaskEvent
          • Transformed into LeadSubmissionEvent and published to another internal_drp_lead_submit topic : listened by outbound service to publish it to the public topic for it be consumed by another team which works on dealer side of things
          • Transformed into LeadRequestDto and sent to the OEM via integrations API
          • Again save the orderStatus in orderStatus table with orderStatus as VEHICLE_LEAD_SUBMITTED.
          • Then once the lead is submitted to both OEM and Dealer team, the status is changed and saved to ORDER_CREATED.
          • OmsTaskEvent’s next orderEvent is set to UPDATE_CHECKOUT_COMPLETED
          • Publish the event in “internal_lead_generate” topic.
        • If there’s an error in the above steps
          • saveOrderError in OrderError table with cartId, orderId and error message.
      • LeadType.IMPLICIT
        • Build the cart link
        • Submit implicit lead via integrations api to the OEM which contains customerInfo, vehicle cart link, has consented for promos and purchase interests like Vehicle configs and Subscriptions which is also sent to customer via an email.
    6. UpdateCheckoutAction
      • Checks if orderStatus is ORDER_CREATED or ORDER_FAILURE and publish it to “internal_drp_lead_status” topic.
      • Saves the order status to CART_UPDATED
      • OmsTaskEvent’s next orderEvent is set to SEND_LEAD_SUBMIT_CONFIRMATION_NOTIFICATION
      • Publish the event in “internal_lead_generate” topic.
    7. SendLeadSubmitNotificationAction (FINAL STEP)
      • Save the order status to SENT_NOTIFICATION.
      • OmsTaskEvent’s next orderEvent is set to NULL and not published to the topic.
    8. This concludes all the steps on order processing.