Let us assume we have 100,000 daily active users over 5 supported applications. We will assume this application works in 10 countries and has a life span of 10 years. Lets assume the average user has around 500 actions per day
User{
user_id: 10 bytes
connected_services: 50 bytes (facebook,discord etc)
custom_status: 10 bytes
notification_subscription_list: 100 bytes
}
170 bytes
LinkedService{
linked_service_id: 10 bytes
service_id: 10 bytes,
service_username: 10 bytes,
service_password: 10 bytes,
access_token: 10 bytes
}
40 bytes
# This is an established websocket connection with a service which records their actions on this service
Presence{
presence_id: 10 bytes
service_id: 10 bytes
user_id: 10 bytes
action_log: 100 bytes (last 10 actions like typing, in a call, gaming, etc)
custom_status: 10 bytes
}
140 bytes
PresenceLog{
user_id: 10 bytes,
service_action_log: 700 bytes (action across 5 different apps)
}
710 bytes
Action {
action_id: 10 byte
action: 10 bytes
start_time: 8 bytes
}
28 bytes
ActionNotification {
action_id: 10 bytes
user_id: 10 bytes
service_id: 10 bytes
message: 50 bytes
}
80 bytes
Notification {
user_id: 10 bytes
subscriber_id: 10 bytes
action_id: 10 bytes
}
30 bytes
((28 * 100000 * 500) + (30 * 100000 * 500) + (80 * 100000 * 500) + (170 + 40 + 140 + 710)* 100000) * 365 * 10 = 25 TB
ConnectService(service_id,user_id,service_username,service_password) -> Attempts to login to a service like messenger or discord and receives an access token if successful
CollectPresence(service_id, action, start_time) -> Once a service is connected, start a websocket connection w/a service to collect action information
SetCustomStatus(custom_status,start_time,service_id) -> Allow a user to set a custom status for a connected service
ConnectionTimeout(service_id) -> Once a websocket connection has been going on for some time without action, end connection unless a new startup is initiated
ConnectionStart(service_id,user_id) -> Start a websocket connection with a connected service using the service api to listen for a startup of user activity
SendNotification(user_id,subscriber_id) -> Sends an notification using the subscriber_id's ActionNotification object to a user who is subscribed to another user's status information
AddSubscriber(user_id,subscriber_id) -> Will go to a subscriber's subscriber list and add the current user. This way whenever the subscriber does an action, it will send a notification to the current user
RemoveSubscriber(user_id,subscriber_id) -> Will go to a subscriber's subscriber list and remove the current user.
User{
user_id: string
connected_services: LinkedService[]
custom_status: string
notification_subscription_list: user_id[]
}
LinkedService{
linked_service_id: string
service_id: string,
service_username: string,
service_password: string,
access_token: string
}
# This is an established websocket connection with a service which records their actions on this service
Presence{
presence_id: string
service_id: string
user_id: string
action_log: Action[]
custom_status: Status (away, online, offline, etc)
}
PresenceLog{
user_id: string
service_action_log: Presence[]
}
710 bytes
Action {
action_id: string
action: string
start_time: datetime
}
28 bytes
ActionNotification {
action_id: string
user_id: string
service_id: string
message: string
}
Notification {
user_id: string
subscriber_id: string
action_id: string
}
Explain how the request flows from end to end in your high level design. Also you could draw a sequence diagram using the diagramming tool to enhance your explanation...
CollectPresence: This endpoint will maintain a websocket connection with a connected service. It will only change its status if a user switches actions so as to not continuously feed the same data which will help performance. We record the start time each time an action starts so we can use this info for analytics.
SendNotification: This endpoint will send a notification to all subscriber's in the current user's subscriber list when their actions change via the connection to the service