This project serves as a test setup for the Finlens application. The candidate is required to set up the database and server locally, following the steps provided below. The current code represents an inefficient implementation for fetching transactions from an API, categorizing them, and saving them into the database. Currently, it takes a significant amount of time to process 3,000 transactions.
The candidate must write an optimized version of the code. The setup is designed to allow scalable processing of transactions, enabling multiple worker processes to handle the categorization queue in parallel. The candidate is expected to:
1.Implement an optimized version of the provided code.
2.Write performance hooks to log the execution time of the current inefficient version.
3.Compare and monitor the performance of the optimized version using the same performance hooks.
4.Provide a screen recording or screenshots demonstrating the performance metrics and terminal logs.
- An Express server with an API endpoint.
- A Sequelize model and migration for the Transaction table, including the category column.
- A service for transaction categorization that reads from APIs and uses BullMQ for queuing.
- A worker that processes the queued jobs and inserts categorized transactions into the database.
To set up and run this project, follow these steps:
-
Install dependencies:
npm install
-
Set up your PostgreSQL database and Redis server.
-
Create a
.env
file with your database and Redis connection details:DB_HOST=your_db_host DB_PORT=your_db_port DB_USER=your_db_user DB_PASS=your_db_password DB_NAME=your_db_name REDIS_HOST=your_redis_host REDIS_PORT=your_redis_port
-
Run migrations:
npm run migrate
-
Start the main server:
npm start
-
Start the worker in a separate terminal:
node src/workers/transactionWorker.js
To run the project using Docker, follow these steps:
-
Build and start the containers:
docker-compose up -d
-
Check the status of the containers:
docker-compose ps
-
Stop the containers:
docker-compose down
If you encounter an error indicating that a port is already in use, you can change the host port in the docker-compose.yml
file. For example, change the host port for the db
service:
services:
db:
ports:
- "5433:5432" # Changed host port to 5433