Converting videos (in almost all common formats) to mp3 format in a microservices architecture. Tech Stack Used: Python, Flask, RabbitMQ, Docker, Kubernetes, MongoDB, MySQL.
A user is first intended to hit the gateway
which will redirect user to /login
which will ask the user for credentials. These credentials will then be stored in an MySQL database. The user will then be returned with a JWT token which will be used for authentication in all subsequent requests. The user will then be redirected to the /upload
where they will be asked for a video file to be uploaded and an email address which will be used to send the converted file's download link. The file uploaded by the user is stored in MongoDB and it's data is pushed to a rabbitMQ queue called video
. Now, the converter
service will retrieve the mp4 file from monogDB using the message, convert the file to mp3, and push the resulting converted file's data to mp3
queue and the file itself is again stored in MongoDB. The notification
service then pulls the message from mp3
queue and sends the user an email containing the link which has the file Id associated. Upon clicking the link, the user is redirected to the /download
where they can then download the file which is served by the MongoDB.
Before you begin, ensure that the following prerequisites are met:
If you directly intend to use the app using existing containers, all you need is:
- Docker Desktop
- kubectl
- minikube
- k9s: optional; used to visualise the k8s cluster better.
- Postman: optional; to test the application. Otherwise use curl.
- *mongodb compass: optional; to visualise the database better.
If you need to make everything from scratch, in addition to above, you will need:
- Python: Ideally create a virtual environment.
- That's it !
Follow these steps to deploy your microservice application:
- Ensure Docker desktop is running with minikube on it.
- Run
minikube tunnel
. - Use
sudo vim /etc/hosts
to open up a file which helps map the domain-name we have specified that is mp3converter.com to our localhost. You also need to map rabbitmq-manager.com to your localhost to access the rabbitmq manager UI. So, add these 2 lines in the file:
127.0.0.1 mp3converter.com
127.0.0.1 rabbitmq-manager.com
- Navigate into each directory, example
cd python/src/auth
, and then runkubectl apply -f ./k8s
. Do this for all the directories. - Use
k9s
command to visualise the k8s cluster. - If you are using MongoDB compass, run
kubectl port-forward <mongodb-pod-name> 27017:27017
to connect to MongoDB instance running on the k8s cluster using port forwarding. Also remember to use default credentials specified inmongodb-secret.yaml
. The URI for connection should look likemongodb://root:password123@localhost:27017/
.
For configuring email notifications and two-factor authentication (2FA), follow these steps:
-
Go to your Gmail account and click on your profile.
-
Click on "Manage Your Google Account."
-
Navigate to the "Security" tab on the left side panel.
-
Enable "2-Step Verification."
-
Search for the application-specific passwords. You will find it in the settings.
-
Click on "Other" and provide your name.
-
Click on "Generate" and copy the generated password.
-
Paste this generated password in
notification/k8s/notification-secret.yaml
along with your email.
Run the application through the following API calls:
-
Login Endpoint
POST http://mp3converter.com/login
Use Postman for selecting 'Basic Auth' and give username and password, the default being: [email protected] and Admin123Expected output: success! and a JWT token.
-
Upload Endpoint
POST http://mp3converter.com/upload
along with headers in format ofAuthorization: Bearer <insert JWT Token>
and a body containing the mp4 file.Check if you received the ID on your email.
-
Download Endpoint
GET http://mp3converter.com/download?fid=<Generated file identifier>