#Ancillary Service
Build a “service” that does the following three jobs:
● Receive packets of data in real-time and pass this on to an ancillary service for processing.
● Collate the output from the ancillary service for a particular Primary Resource ID into a single data packet.
● Once all data packets for a particular Resource are received, pass on the collated output data further for downstream processing with minimum latency by calling a webhook.
- The service needs to be highly scalable.
- Hence, we will need a Redis instance. For the purpose of assignment, I have used in-memory cache.
- Ancillary Service is a long-running 'asynchronous' job. It can be used in a 'synchronous' manner also but that would mean we cannot scale this service for high traffic rate.
python 3.7 or higher
Development setup (for Ubuntu/Mac):
-
Ubuntu
sudo apt-get install python-pip
-
MAC
This command should install python3 and pip3.
brew install python@3.7
https://github.com/achugh95/ancillary-service
cd ancillary-service
python --version or python3 --version
Setup environment:
python3 -m venv <path>
source <path_to_virtual_environment>/bin/activate
pip3 install -r requirements.txt
python3 manage.py makemigrations
python3 manage.py migrate
Open terminal and run the following commands:
python3 manage.py runserver
python3 ancillary/tests.py
curl --location --request POST 'localhost:8000/api/v1/ancillary/packet/send-data/' \
--header 'Content-Type: application/json' \
--data-raw '{
"resource_id": 101,
"payload": "Bat Ball",
"packet_index": 1,
"last_chunk_flag": true
}'