This problem requireds 2 micro serivce, one is loading home page and another to store user info and maintain it's social graph
Talking about first:
okay, going step by step on the API
b. display topK
Regarding NFR
Talking about second:
First microservice:
okay, so let;s setup schema real quick:
Tweet
a. tweetid
b. user
c. tweet text
d. ts.
Structure of messafge stored inthe queue
TweetId
Tweet metadata
targetUserId
priority
Audit table to store sent msgs or some metadata in the queue(if business asks for it) - future scope
Now, for 1st should be NoSql - since tweet can explode, need vertical scaling and new params can come
2 is just a java classm
Regd User Relations microserfice
Regarding the ingestion part:
this should be a cron job, every 5 mins or 10 mins (configurabel by the business based on user activity probably or whatever business want to track)
and can be triggered nefore as well in case of queue empty() event or fasterConsumption event
it will call the below microservice and get the nearest K users for the given user and get their top tweet from the tweet table and feed it to the queue.
for this queue i am thinking kafka (since i need ordering) for smaller usercase rabbit mq can be used but in long term kafka is better here
regd the infra setup, probably 6 (3+3) general purpose ec2 servers (hosting 3 microservices of homefeed and 3 of userRelations)
1 MYsql
! neo$j
1 nosql
1 Redis
1 Kafka setup
1 Classic Load balancer + api gateway
A CDN too if global customers
1 noSql