Store the energy readings with intervals of 3 seconds. The application is built with NestJS and uses both MySQL and MongoDB databases, with Prisma as the ORM for MySQL and Mongoose for MongoDB. The application provides a RESTful API for managing energy readings, including features for adding, retrieving, updating, and deleting readings.
Why? To compare performance and scalability of both databases in a real-world scenario.
To compare I'm using two Ec2 intances:
- MySQL:
t2.micro
(Ubunto:24) instance with 1 vCPU and 1 GiB of memory 8GB. - MongoDB:
t2.micro
(Ubunto:24) instance with 1 vCPU and 1 GiB of memory 8GB. - NestJS:
t2.micro
(Ubunto:24) instance with 1 vCPU and 1 GiB of memory 16GB.
- Project setup
- Database setup
- Compile and run the project
- API Swagger Documentation
- Relational Conceptual Model
- Relational ERD
- Performance Tests - Consumer Energy Readings
- License
- Node.js (v18 or later)
This project is a NestJS application that serves as a RESTful API for managing energy readings. It supports both MySQL and MongoDB databases, allowing you to choose the database that best fits your needs.
$ npm install
Before the database setup, you need to create a .env
file in the root directory of the project. You can use the .env.example
file as a template. Make sure to set the environment variables for both MySQL and MongoDB connections. I created a docker-compose file to run both databases locally, you can use it to test the project.
docker-compose up -d
Migrate the database schema using Prisma:
$ npm run prisma:m
Generate Prisma client:
$ npm run prisma:g
Seed the database with initial data:
$ npm run seed:sql
Migrate the database schema
$ npm run mongo:up
Seed the database with initial data:
$ npm run seed:nosql
# development
$ npm run start
# watch mode
$ npm run start:dev
# production mode
$ npm run start:prod
To create a NestJS application that serves as a RESTful API for managing a collection of books, including features for adding, retrieving, updating, and deleting books: http://localhost:3000/api
NoSQL:
- 620.524 ms
- 600.568 ms
SQL:
- 2.7101 s
- 2.4061 s
NoSQL (863.163 registers):
- 845.917 ms
- 837.434 ms
SQL (863.307 registers):
- 1.5945 s
- 1.2670 s
NoSQL (4.330 registers):
- 179.563 ms
- 187.200 ms
SQL (4.262 registers):
- 328.213 ms
- 171.104 ms
NoSQL (337.069 registers):
- 603.715 ms
- 594.813 ms
SQL (262.996):
- 1.1459 s
- 925.286 ms
NoSQL (284.537 registers):
- 553.321 ms
SQL (272.166):
- 1.2236 s
NoSQL:
- 152.882 ms
SQL:
- 602.308 ms
NoSQL:
- 171.722 ms
SQL:
- 1.2072 s
NoSQL:
- 148.294 ms
SQL:
- 1.0485 s
Nest is MIT licensed.