This is sample clone for Digg.com with simple topics, in-memory storage(No persistence) using a Priority Queue(Min heap) of fixed size.
Assumptions:
- No user logins and registrations
- Topics with same title and content is allowed by same user or different user
- Upvotes and Downvotes can submitted by any user to any topic any number of times.
- UI fancy designs, validations etc are not needed. It is simple UI and might have some validation and rendering issues.
Design:
- REST services for every operation and UI just uses to render data.
- REST services implemented in java, springboot
- Proper exception handling framework created. Sending a new error response in generic format is just a config change
- Popular topics are maintained in a Priority Queue(Min heap). So, updating PQ is of time complexity O(LogN) and to get all popular topics O(20) which is constant.
- PQs size is configurable.
- PQs are maintained for every kind of vote (Upvote, Downvote etc). Just adding a new Enum takes care of everything and no further code changes needed.
- NO UNIT TESTS WERE WRITTEN. But, code is very much testable.
- All operations are thread safe. Used synchronization where ever it is required and provided comments at every place explaining why it is used.(See TopicsDao.java)