Club Leavers/Joiners Technical Design

Overview

This repository is not just for NHS discount, but any process that requires a customer adding/removing from an OSP group. This repository contains the code for lambdas and Step function required to Add or Remove the Club Joiners or Leavers respectively from OSP. Hence we will refer to it as Club Leavers/Joiners hereon instead of NHS Discount repo.

Leavers or Joiners are fetched from Club events on scheduled basis for NHS DISCOUNT, COLLEAGUE DISCOUNT and ADDITIONAL MEMBER DISCOUNT clubs and those are then POSTed or DELETEd from the OSP/OCEAN systems if those customers are Online customers too.

Updates in Ocado’s OSP happen through API endpoints while that in Ocado’s OCEAN happen through CSV file uploads.

In a nutshell, following important steps are performed by the lambdas and step function present in this repository. Please refer to the Architecture Document below for more details.

  1. Fetch events from Club service based on EventId water-mark triggered by CloudWatch scheduled job

  2. Water-mark is stored in dynamodb, updated after events are fetched

  3. Check whether Customers fetched in the events are OSP customers or not

  4. For OSP customers decide Add/Remove action based on operation in Club event (JOINER or LEAVER) and call respective lambda accordingly

  5. Log response coming from OSP into BigQuery (using SNS)

Swaggers

All swaggers are maintained in Pymorri for Integration testing. Paths below

Club

OSP Customer Group

References

Document

Ref

Architecture Document

Solution Architecture.

Main Jira Story

NHS Discount Workflow: SPDP-2137.

Components

Diagrams

Flow Diagram

_images/StepFunctionFlow.png

AWS Step Function

Below is the AWS Step function which is triggered by Step Function Trigger Lambda and gets the Club service events as input so that those can be processed for Adding or Removing customers from OSP Customer group.

_images/AWS_Step_Function.png

Event Pattern

Pattern 2 shown in below diagram has been used to follow the event based triggering approach.

_images/GenericPatterns.png

Sequence Diagrams

@startuml
skinparam sequenceArrowThickness 2
skinparam roundcorner 20
skinparam maxmessagesize 600


box "Morrisons Services AWS" #LightBlue
    actor storepickSNSTopic
    participant "AWS Lambda \n (gets promotion data from BigQuery)" as AWSLambda
end box


storepickSNSTopic -> AWSLambda: SNS triggers Lambda\n message is filtered based\non a specific filter
AWSLambda -> AWSLambda: from event get \neventType(action)
AWSLambda -> AWSLambda: from event get \neventData
AWSLambda -> AWSLambda: from eventData get \ncustomerId
AWSLambda -> AWSLambda: from eventData get \ngroupId
AWSLambda -> AWSLambda: update event object \nwith downstream \nacceptable format
AWSLambda -> AWSLambda: return update event

@enduml

@startuml
skinparam sequenceArrowThickness 2
skinparam roundcorner 20
skinparam maxmessagesize 600


box "Morrisons Services AWS" #LightBlue
    actor EventTransformerLambda
    participant "AWS Lambda \n (remove customers from group)" as AWSLambda
    participant "SSM \n (Store for Free Delivery \n auth info)" as SSM
    participant "ConfigService \n (Store for Free Delivery \n config info)" as ConfigService
end box
box "OSP Service" #LightCyan
    participant "OSP \n (Service hosted by Ocado)" as OSP
end box


EventTransformerLambda -> AWSLambda: Upstream Lambda in workflow
AWSLambda -> SSM: Get NHS Discount SSM
AWSLambda -> ConfigService: Get NHS Discount config info
AWSLambda -> AWSLambda: from event get customerIds
AWSLambda -> AWSLambda: from event get retailerCustomerGroupId
AWSLambda -> OSP: call to remove customer from cust_group
AWSLambda -> AWSLambda: from event action
AWSLambda -> AWSLambda: return event

@enduml