High-Level Design
Describe the overall system architecture. Identify the main components needed to solve the problem end-to-end. Use the diagramming tool to create a block diagram.
- 100 million user
- Daily active users can be of 10 million
- 10 million every day
- qps 100 peak qps 500
- sycn fanout architecture to sycn accross devices
Calculateion -
user id 16 bytes, workout type- 20 bytes , duration - 8 bytes, caloires bured 4 bytes,distance 0 8 bytet, heatrate- 4 bytest, timestamp 8 byte -- 200bytes
2kb * 1m== 2gb per day - 700gb per year
peak 10gb per day
5 Year 3.5 tb
Let me try to put down things
- User can login via any watch, mobile app, web
- Api gateway will manage routing,authentication and etc
- We can keep a rate limiter for handling request and the same way we will make sure that there is a burst setting that after a certain limiti like 10 per minute we send 429 or basically slow down message
- During high load we will have more service of activity service and etc we can keep load balancer for each service too when expanding it
- Activity service will be use message queue for entry of workload and use object storage for s3 storage for files and all.
- here we can use chunking for uploads
- We will also have time series for histroy based
- Main data will be stored in Main database which will keep a master slave architecture
- Redis will suffice the stats service and we will keep the 80:20 rule for here too
- If the app is offline we will store that in local storage and when the user comes to online we will add that
- We will keep the cache workout data for selceting if user is offline
- Message queues will be there for using and will we use event streaming to store in analytical service
- After update or delete entry we will delete it and update the cache .
- The flow will be userId and starttime will be used for primary entry and if any things needs to be update we will put last updated time
- Goal service will be used to track user goal
- Integration service will be useful for syncing the data across device once the data base is populated we can have a pub sub pattern
- For bult import we can have a csv file pattern and it can be send via queue to service via bulk api. Worket process files asnyncrohoulsy and storea data
- From we can call the analystics to store data based on each day once the record is updated and can then update the db and cache for the same value
- If any service fails we have circuit breaker to check the service incase it failes we try to fix it and at the same time have the data read from the last replication , if that is also not available we let the other service do the job
- Flow Activity Service → Event Queue → Analytics Service → Analytics DB
- When ever new activity will come it will create an event, activiy create, updated,deltered - via kafka/sqs + sns , anaylics service will substribe to this mertics\
- we will only update relevenat nbucket user-date, user-date-activity
- Daily serciwill be udpated to a fast store could be anything like a separte DB service
- if any service is updated or delted we can use eventid+ versiom/ipdate AT tso that we handle idempotency.
- After analytice update the daily summary it can either invalidate the cahce or write a fresh value in redis
Main Database (OLTP)
- Stores user activity, goals,metadata
- primary- replica architecutue for high availabilty
- primary handles write replioca handles read
- userId,activituId,starttime,duration,calories
Time series Database
- Stores historical fitness metrics like steps, heart rate
- Optimized upload used for reliability and handling large files
- activity service- main DB - time servies DB (steps ,heaart rate
- Object storage- workout images, activiy export, GPS (outdoor)
- Daily step count and calories will go in analytics
Goal serive.
- User goal activities ( steps/day, calories
- tracks progress based on activity day
- user cached and aggregared data for fast reposnse