# Feed Flow GO 1. Fetcher 2. Pusher 3. Differ ## FETCHER ### /api/v1/feed (GetUserFeed) #### Request structure { "userId" int required "feedId" int required "languageId" int required "nextToken" int "mixed" bool "config" json {"ratio" map[int]int} } #### Flow ```flow st=>start: Receive API e=>end: Retention Tracking op1=>operation: getUserMetadata(cursor and top) cond1=>condition: Metadata found cond2=>condition: nextToken>0 cond3=>condition: top-cursor<30 cond4=>condition: isFirstFeedCallOfTheDay op2=>operation: Paginate from nextToken op3=>operation: Return trails,nextToken and cursor op5=>operation: Handle Missing Metadata (Look in mongodb if not found push data) op6=>operation: Get content above cursor (paginate from cursor) op8=>operation: fetch from bottom(paginate from 0) op9=>operation: Call Pusher st->op1->cond1 cond1(yes)->cond4 cond4(yes)->op9 cond4(no)->cond2 cond2(yes)->op2 cond2(no)->op6 op6->cond3 cond3(no)->op3 cond3(yes)->op9 cond1(no)->op5 op2->op3 op8->op3 op5->cond2 ``` ### /api/v1/feed/detailed (GetUserFeedDetailed) ``` Call Trail service /api/v1/trail/mobile/mini for detailed user feed ``` ### /api/v1/feed/reset (ResetUserFeed) ``` Deletes cursor and user feed from both redis and mongo ``` ## PUSHER { "userId" int required "categoruId" int required "languageId" int required "count" int required "userStackKey" string required "mixed" bool "config" json {"ratio" map[int]int} } ```flow st=>start: Start op1=>operation: get User feed stack key (uf:u:f:l) op2=>operation: Call diff service op3=>operation: Add result to user stack (redis and mongo) en=>end: Return no of items in user stack st->op1->op2->op3->en ``` ## DIFFER ```flow st=>start: Start op1=>operation: get userstack from redis op2=>operation: get (count) pinned trails from content stack that are not already in user stack cond1=>condition: If len (pinned )<count op3=>operation: Get popular content (old new and blog merged) cond2=>condition: If len(UserStack)>300 op4=>operation: get served but not seen content op5=>operation: merge in ratio en=>end: Return merged content (trailIds array) st->op1->op2->cond1 op3->cond2 op4->op5->en cond1(no)->en cond2(yes)->op4 cond2(no)->op5 cond1(yes)->op3 ``` ## Cron Job for populating stacks ```flow st=>start: Start op1=>operation: get active feed categories op2=>operation: get content for each afc op3=>operation: clear and add into content stack st->op1->op2->op3->op1 ``` ## Cron Job for populating Hot-start content stacks ```flow st=>start: Start op1=>operation: get active ad campaigns op2=>operation: get content for each active campaign op3=>operation: clear and add into content stack st->op1->op2->op3->op1 ```