This application/service allows users to track when they go to bed and when they wake up.
Minimum requirement of the features:
- Clock in operation and return all clocked-in times ordered by created time
- Users can follow and unfollow other users.
- See the sleep records of a user's All following users' sleep
records. from the previous week, which are sorted based on the duration
of All friends sleep length.
This is 3rd requirement response example
{
record 1 from user A,
record 2 from user B,
record 3 from user A,
...
}
- The system needs to handle high volume of data and concurrent requests as the user grows.
- Ruby on Rails
We chose RDBMS for this system due to the following reasons:
- Relationships
- Users following other users and users clocking in.
- Complex Queries
- Retrieving users' sleep lengths for the previous week.
- Transactional Operations
- Ensuring data consitency when clocking in.
For RDBMS, the popular options are PostgreSQL and MySQL. We chose PostgreSQL over MySQL for this scenario for the following reasons:
-
Concurrent Requests
- The system will handle concurrent requests (such as clock-in or follow/unfollow operations happening simultaneously).
- PostgreSQL’s MVCC (Multi-Version Concurrency Control):
- Is built-in and doesn't block read and write.
- While MySQL with InnoDB also supports MVCC, it may rely on locking mechanisms in some cases, leading to higher latency due to blocking.
-
Heavy write operations
- The system is expected to handle a high volume of data as the user grows, we assume that the clock-in and follow/unfollow traffics are also high.
- PostgreSQL is optimized for heavy write workloads, whereas MySQL is typically optimized for heavy read workloads.
Follow the installation guide at RVM Install.
Use RVM to install the required Ruby version and then install Rails:
rvm install ruby-3.0.0
rvm use ruby-3.0.0 --default
gem install railsPrepare the database:
rails db:create
rails db:migrateStart the Rails server:
rails serverPrepare the database:
RAILS_ENV=test rails db:drop
RAILS_ENV=test rails db:createNavigate to http://localhost:3000 to access the application.