---
# System prepended metadata

title: Arshpreet

---

# Arshpreet | 4 years
- Good with DB design. Gave proper schema structure to tables and datatype and queries.
- Event System Design. Gave basic solution.
- Can be compared with blessy

# Question 1: Facebook Post
- Post, like, comments(nested), share(as post).


Clarifications:
    - Post - Text + Media?
    
    
Tables:

    1. User: 
        a. user_id: int
        b. user_name: varchar
        c. last_active: timestamp
        d. email: varchar
    
    2. PostCommentMapping (PostCommentID + Post_id) 
        a. Post_id: FK
        b. Comment_id: FK
    
    3. Post: # Post -> Comment 1 : many, Comment -> 1 : many
        a. post_id: int
        b. user_id: int (user_id FK)
        c. text: varchar
        d. media: varchar(link to s3)
        f: created_at: timestamp
        g: share_post_id: int (link to the original post)
        h: like_counter: int
        
    4. Comments:
        a. comment_id: int (PK)
        b. user_id: int(FK)
        c. text: varchar
        d. like_counter: int
        e. parent_counter_id: int (FK to comment_id)
        f: created_at


# Get Post, Like, Comment of a user in paginated manner.

1. Get Post, like counter for a user:
    a. Select * from Post where user_id = 10;
    
2. Get Post, Comments for a user:
    a. Select * from Post p inner join PostCommentMapping m on p.post_id = m.post_id where p.post_id = 123;

3. Insert comment for a post

4. Insert nested comment for a comment on a post

5. Like the post/comment



# Question 2: Event Driven System 
(kafka)

- Queue
- publish - Producers
- subscribe - Consumers


# Steps and things to take care of / Prototype to build kafka


# Flow:

    Producers => Queue => Consumers
    
    Producers publish into topics (topic name should be unique) 
    Consumers subscribe into topics

    Two methods:
        1. Push
        2. Pull / Polling

    1. Queue will be fixed size (list) - Thread safe shared resource
    
    Producers:
        Map<topic_name, topic_id> topicMap
        
        createTopic(topic_name){
            uniq topic_id is generated
            topicMap[topic_name] = topic_id
        }
        
        publish(data, topic_name){
            1. Writing the data into particular topic_id
            2. Call the set() to set the data into Queue
            3. Wake up the consumer worker threads
        }
        
        
    Queue:
        Arr[] objects:
        
        set()
        
        get()
        
        offset
        
        
    Consumers:
        Map<consumer_id, topic_id> consumerMap;
        
        addConsumer(topic_name){
            1. Create a new consumer
            2. Add the relation into map
        }
        
        subscribe(){
            1. Fetch all consumers for that particular topic_id   
            2. Consume from the Queue - Monitor Locks
        }


