---
# System prepended metadata

title: Sutirtha Rej | R2 | 4+ yea

---

# Sutirtha Rej | R2 | 4+ years
- NOt satisfactory db design solution for chat system. Not scalable. 
- PLease reject

# Question 1: Chat System

- 1<>1 chat
- text message
- when was the user last online


 schema - 
 
 user - id, name, etc
 -----------------------------
 assochiated_chat
 name          datatype
 id              string 
 chat_content.   [{
 
 chat_user_id - string
 chat_content - ""
 timestamp.   -  
 }, {}]json           
 
 
 -----------------------------
 
chats 
name.   datatype

user_from    id (string)
user_to.     id (string)
chat         assochiated_chat_id (foreign key)
is_active.   boolean
last_message string
created_at    timestamp
updated_at.   timestamp


first page - 
GET (chats) -> then u get the chat_id
GET (assochiated_chat) -> chat_content

chat_content = [
{
 
 chat_user_id - string
 chat_content - ""
 timestamp.   -  
 }, {}
]
s3 (old content)
media content (s3 / blob storage)

API - 
----------
GET - /preview-chats

headers - auth key


query on chat- where
            user_from: user_id,
            is_active: true
            
            
GET - /chat
headers - auth key
query-params = chat_id

query on assochiated_chat-
where 
    id: chat_id
            

POST - /chat
headers - auth key
body = {
    content - ""
    user    - id string 
}
logic - 




