This project implements a scalable key-value store using Kubernetes (k8s), FastAPI, and Huey as a REDIS queue. The key-value store is designed to be highly scalable, robust, and efficient, capable of handling a large number of concurrent requests while maintaining high availability and fault tolerance.
- Kubernetes Deployment: Utilizes Kubernetes for managing deployment, auto-scaling, and management of containerized applications.
- FastAPI: Modern, fast web framework for building APIs with Python 3.7+ based on standard Python type hints.
- Huey as a REDIS Queue: Lightweight task queue built on top of Redis, allows offloading time-consuming tasks to the background.
- Scalability: Designed to scale horizontally by adding more pods/deployments based on the metrics.
app/: Contains the main application codemodels/: Data model for our serverDockerfile: Dockerfile to create an image for the serverhuey_consumer.py: To run the Huey consumer for the tasksredis_huey.py: It contains the functions to Add/Get/Delete key to/from databaserequirements.txt: Dependencies required for this projectmain.py: FastAPI application entry point
deployments/: Kubernetes deployment filesredis/: To deploy redis on k8 clusterkvserver/: To deploy FastApi Server and consumer
tests/: Test casesREADME.md: Project documentation
Make sure you have the following tools installed on your system:
- Python 3.x
- FastAPI
- Huey
- Redis
- Docker
- Kubernetes (minikube for local development)
- kubectl
1. Clone the repository and Install dependencies
git clone https://github.com/Shikhar97/KeyValueStore.git
cd KeyValueStore/app; pip install -r requirements.txt2. Run the redis server
redis-server3. Run the FASTApi server
python3 uvicorn main:app --host 0.0.0.0 --port 80004. Run Huey consumer
python3 huey_consumer.py redis_huey.hueyAccess FastAPI server at http://localhost:8000/api/v1/ using Postman or any other tool.
1. Clone the repository
git clone https://github.com/Shikhar97/KeyValueStore.git
2. Start minikube(if not already running) and Deploy the redis stateful-set
minikube start
cd KeyValueStore/deployment/redis
kubectl -n kvstore apply -f redis-statefulSet.yml3. Deploy the FASTApi server
cd KeyValueStore/deployment/kvserver
kubectl -n kvstore apply -f kvserver-deployment.yml4. Enable port-forwarding
kubectl -n kvstore port-forward svc/fastapi-service 8000:80005. Cleanup
cd KeyValueStore/deployment/redis
kubectl -n kvstore delete -f redis-statefulSet.yml
cd KeyValueStore/deployment/kvserver
kubectl -n kvstore delete -f kvserver-deployment.yml
minikube stop
minikube deleteAccess FastAPI server at http://localhost:8000/api/v1/ using Postman or any other tool.
Docker images are built on arm64 architechture. Not supported on amd64.
Check the available APIs at http://localhost:8000/docs
-
Navigate to the root directory of your project:
cd KeyValueStore/app -
Install pytest:
pip install pytest
-
Run the test cases using pytest:
pytest tests.py
The test results will be displayed in the terminal, indicating whether each test passed or failed.
