ECG Analyzer is distributed, scalable, secure and containerized web application built on top of FastAPI and Celery. For the sake of this challenge, it can be deployed locally with Docker Compose and provides a friendly API Documentation.
The service has been designed with scalability in mind, that's why Celery is the core here. FastAPI (with uvicorn workers) and Celery (with native worker approach) can be horizontally scaled whenever is needed. At the same time the API level just enqueue the tasks in the Celery broker (RabbitMQ) and perform some basic DB transactions.
The business logic is decoupled from the API and attached to the Celery Workers (or RabbitMQ consumers), which are the responsible for analyzing an ECG and performing the operations. In order to perform actions in a completely asynchronous manner, you will find some Celery Canvas implementations.
- Docker / Docker Compose
- .env file (Following good practices it has not been included in the repo but can be found here). Copy this file to the project root.
Service Name | Description |
---|---|
api | FastAPI service |
analyzer | Celery service |
rabbitmq | RabbitMQ service used as a broker within Celery |
redis | Redis service used as a backend within Celery |
db | PostgreSQL database service |
pgadmin (Optional) | PGAdmin service (UI for PostgreSQL database) |
- User passwords are hashed and persisted using Argon2.
Once all prerequisites are satisfied, navigate to the root directory of the project and run the following commands in order to deploy the services locally:
Building containers:
docker compose build
Running containers:
docker compose up
Providing an Analyzer interface (Abstract Class) is key for supporting new analyzers in the future.
The interface and its implementation can be found on: ./src/analyzer.py
.
There are 2 implementations that could analyze signals and return the count of zero-crossings.
ECG API has been designed with versioning pattern, so can easily be extended in the future with more functionalities. Explore the API and its endpoints using OpenAPI and Redoc documentation:
The authentication type is Basic Authentication (username and password)
- Authenticate as Admin with Basic Auth (credentials can be found on the
.env
file) - Perform a POST request to
/v1/admin/register_user
with the username and password to create. - This user can now perform ECG submissions and result retrievals (check API documentation).
pip install -r requirements-dev.txt
pytest ./tests