# Personalised user segments (Phase-I) ## Overview Merchant Segment Service (MSS) is responsible for 1. Storing user segments (merchant, segment-definition)->customer_ids. 2. While creating a promotion: If the merchant requests to target specific audience for that promo, MPS will talk with MSS to sync segments for that merchant, for that segment definition with CP/segmentation-service. 3. MSS will also keep a counter against each customer_id to keep track of how many segments have been synced for that customer ## DE <-> MSS We have decided to setup an actor for this. We also need to setup an internal endpoint on MSS to write/update segments to. We can split this part in two cards 1. Setup an "internal" endpoint on MSS to write/update segments 1. Create up the DB schema for storing segments 3. Setup Lambda actor, Kafka topic 1. Create a kafka topic 2. Setup actor to read from the topic 3. post segments to endpoint from #1 above ## Merchant Segment Service APIs: 1. Internet endpoint to sync up user segments 2. Sync-segments: MPS will call this endpoint while creating a promotion to sync segments 1. MPS will call with <merchant_id, segment_type, promo.end_date> 2. MSS will fetch the customer_ids for given segment, filter out those customer_ids which have more segments synced that set threshold. For the remaining ones, call CP/segment-service to create/update segments. 3. Update user_id thresholds NOTE: CP is yet to setup segment expiry field on create endpoint. We need them to do it in this iteration only. Expiry date would be promo.end_date ## Merchant Promotions Service 2. Sync segments if target_audience is set on create-request 1. After request validation, call MSS with <merchant_id, segment_type, end_date> 2. On success: share the segment info with markdown 3. On failure: we return error response NOTE: Food/markdown is yet to expose segment field on create-campaign endpoint ## Stories 1. Setup proto, kafka topic 2. Setup Elixir kafka consumer (segments->db) 3. API to sync segments (MPS->MSS) 5. Maintain thresholds 6. Add validations to the API 7. Update create-promo endpoint to accept target-audience 8. Call MSS to sync segments