This project is a basic catalog system to manage products, built as part of a technical test for ZeBrands. Each product has basic information such as SKU, name, price, and brand.
The system has two types of users:
- Administrators who can create, update, and delete products, as well as create, update, and delete other administrators.
- Anonymous users who can only retrieve product information but cannot make changes.
As a special requirement, every time an administrator makes a change to a product (for example, adjusting a price), we notify all other administrators about the change, either by email or another mechanism.
We also track the number of times an anonymous user queries each product, so we can create some reports in the future.
The task was to build this system by implementing a REST or GraphQL API using the stack of your preference.
-
Clone the repository:
git clone https://github.com/Ventura94/ZebrandsBackendTechnicalTest.git
-
Navigate to the project directory:
cd ZebrandsBackendTechnicalTest
-
Create a virtual environment:
python -m venv env source env/bin/activate
-
Install poetry:
pip install poetry
-
Export requirements with poetry:
poetry export -f requirements.txt --output requirements.txt --without-hashes
-
Install the dependencies:
pip install -r requirements.txt
-
Create a
.env
file in the root directory of the project and add your environment variables:POSTGRESQL_URL
: The connection string for your PostgreSQL database. It includes the username, password, host, port, and database name.SECRET_KEY
: A secret key for your application which is used for security purposes.MAIL_USERNAME
: The username for the email account you're using to send emails.MAIL_PASSWORD
: The password for the email account you're using to send emails. (https://support.google.com/accounts/answer/185833?hl=es#:~:text=En%20%22Iniciar%20sesi%C3%B3n%20en%20Google,Selecciona%20Generar.)MAIL_FROM
: The email address that will appear in the "From" field of the emails you send.MAIL_PORT
: The port to use when connecting to the email server.MAIL_SERVER
: The hostname of the email server.MAIL_TLS
: A boolean value that indicates whether to use TLS (Transport Layer Security) when connecting to the email server.MAIL_SSL
: A boolean value that indicates whether to use SSL (Secure Sockets Layer) when connecting to the email server.
POSTGRESQL_URL=postgresql://zebrands:zebrands@localhost:5432/zebrands SECRET_KEY=secretkey MAIL_USERNAME=example@gmail.com MAIL_PASSWORD=password MAIL_FROM=example@gmail.com MAIL_PORT=587 MAIL_SERVER=smtp.gmail.com MAIL_TLS=True MAIL_SSL=False
-
Run test:
pytest
-
Start the server:
uvicorn src.asgi:app --reload
Open your browser and visit http://localhost:8000/docs to see the application documentation.
The system will be based on a microservices architecture, which will allow for efficient horizontal scaling as the system grows. Each microservice will be responsible for a specific functionality and will communicate with others through REST or GraphQL APIs.
-
Product Service: This service will handle all operations related to products (create, read, update, delete). It will use a PostgreSQL database to store product information.
-
User Service: This service will handle user operations, including authentication and authorization of administrators. It will also handle the creation and management of administrators.
-
Notification Service: This service will handle sending notifications to administrators when a change is made to a product. It could use an email service like AWS SES or SendGrid for this.
-
Tracking Service: This service will track the number of times an anonymous user queries each product. This information will be stored in a database and used to generate reports and recommendations system.
As the system grows, we might encounter several scalability challenges. Here are some strategies we could use to address these challenges:
-
Horizontal Scaling: If a specific service is experiencing high load, we can scale it horizontally by adding more instances of that service. This can be done manually or using a container orchestration service like Kubernetes.
-
Load Balancing: We can use a load balancer to distribute incoming requests among different instances of a service. This will help ensure that no single instance is overloaded.
-
Caching: We can use a cache to store the results of frequently made database queries. This can help reduce the load on the database and improve system performance.
-
Message Queues: For notifications, we can use a message queue to handle spikes in load. When a product changes, the product service can put a message in the queue, and the notification service can consume these messages at its own pace.
This guide will walk you through the steps to execute Terraform, including the creation of a variables file.
- Terraform installed on your machine.
- Access to the terminal or command line interface.
- DigitalOcean account
- Domain in DigitalOcean account
-
Create a Variables File
Create a file with the
.tfvars
extension, for example,variables.tfvars
. Inside this file, define your variables as follows:do_token = "my_digitalocean_token" do_region = "nyc1" # This is default maintainer_email = "arianventura94@gmail.com" # This is default zebrands_postgres_password = "postgresql_password" secret_key = "my_secret_key" service_email = "arianventura94@gmail.com" # This is default mail_password = "email_password" domain = "domain.com"
-
Initialize Terraform
Navigate to your Terraform directory and initialize Terraform by running the following command in your terminal:
terraform init
-
Apply Configuration
Apply your Terraform configuration. Make sure to include your variables file using the
-var-file
option:terraform apply -var-file="variables.tfvars"