A Django-based microservice that provides a REST API for processing background tasks using Celery and Redis. This application is containerized with Docker and deployed on AWS using Terraform and Kubernetes.
This project implements a microservice architecture with the following components:
- Web Service: Django + Django REST Framework
- Background Task Processing: Celery
- Message Broker/Results Backend: Redis
- Database: PostgreSQL
- API Documentation: Swagger/OpenAPI
- Containerization: Docker
- Orchestration: Kubernetes (EKS)
- Infrastructure as Code: Terraform
- REST API endpoints for processing tasks and checking their status
- Background task processing via Celery workers
- API documentation via Swagger UI
- Token-based authentication
- Containerized application for easy deployment
- Kubernetes deployment for scalability and reliability
- Terraform scripts for infrastructure provisioning
-
POST /api/process/: Submit a task for background processing{ "email": "user@example.com", "message": "Hello World" } -
GET /api/status/<task_id>/: Check the status of a background task -
/swagger/: API documentation using Swagger UI -
/admin/: Django admin interface
- Docker and Docker Compose
- Python 3.9+
- pip
Create a .env file in the root directory with the following variables:
SECRET_KEY=your_secret_key
DB_NAME=django_db
DB_USER=postgres
DB_PASSWORD=postgres
DB_HOST=db
DB_PORT=5432
POSTGRES_DB=django_db
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
-
Build and start the containers:
docker-compose up --build
-
Access the API at http://localhost:8000
-
Access the Swagger documentation at http://localhost:8000/swagger/
-
Install dependencies:
pip install -r requirements.txt
-
Start Redis server (required for Celery)
-
Configure environment variables
-
Run migrations:
python manage.py migrate
-
Start the Django development server:
python manage.py runserver
-
Start Celery worker:
celery -A core worker --loglevel=info
This project is configured for deployment on AWS EKS (Elastic Kubernetes Service) using Terraform.
- AWS CLI configured with appropriate permissions
- Terraform installed
- kubectl installed
-
Navigate to the terraform directory:
cd terraform -
Initialize Terraform:
terraform init
-
Apply Terraform configuration:
terraform apply
-
Configure kubectl to connect to the EKS cluster:
aws eks update-kubeconfig --name django-microservice-cluster
-
Deploy the application to Kubernetes:
kubectl apply -f ../microservices-k8.yml
-
Verify deployment:
kubectl get pods kubectl get svc
core/: Main Django project settingstasks/: Django app containing the API and task processing logicterraform/: Terraform scripts for AWS deploymentkubernetes/: Kubernetes configuration filesDockerfile: Docker configurationdocker-compose.yml: Docker Compose configuration for local developmentrequirements.txt: Python dependenciesmanage.py: Django management script
- Backend: Django, Django REST Framework
- Task Processing: Celery
- Database: PostgreSQL
- Cache/Message Broker: Redis
- Containerization: Docker
- Orchestration: Kubernetes (EKS)
- Infrastructure: AWS (EC2, EKS, RDS, etc.)
- IaC: Terraform
- Documentation: Swagger/OpenAPI
SmallClosedWorld Developer