Backend Assignment | GreedyGame
Http Module insert/fetch request are pushed to RequestProcessor channel. Insert call is async and returns 200 imideatlly. Fetch call is sync and waits for response from fetchProcessor to return back.
RequestProcessor fans out the request based on type(insert or fetch) to InsertProcessor or FetchProcessor
KEY POINTS:
-
RequestProcessor also sends all the request of insert type to InsertLogProcessor as well. InsertLogProcessor writes down the insert queries to log, so that they can be used to reconstruct the Data collection state incase of system failure.
-
The updates to the data collection state are written in thread safe manner. All updates to counter values are done atomicaly and rare case of duplication insertion of any new node is prevented by using mutexes.
-
The Insert request is processed asyncrhronously as requested.
-
Maintainability: Adding new levels like "States" and or "Cities" can be easyly handled by adding their level/priority to the LevelOrder enum.
-
Maintainability: Adding new functionality like remove node can also be easily added in thread safe manner by adding new processor (like insertProcessor).
IMPROVEMENTS POSSIBLE:
- Request validation
- Graceful termination by adding quit channel for all processors
TESTS:
Tests wirtten for core logic of inserting into tree and fetching from tree // insertProcessor and fetchProcesser go files
POSTMAN LINK: https://www.getpostman.com/collections/7831c0a082cc4cd623c9
HOW TO RUN:
Dockerized as requested.
$>docker build .
$>docker run -d -p 8080:8080 <image_id>