Skip to content

Repository files navigation

Database Benchmark - Undergraduate Thesis Project

This project is a web application for an academic benchmark of different database paradigms. It compares relational, document-oriented, NewSQL, and in-memory databases through equivalent operations and controlled synthetic data.

The goal is not to produce a universal database ranking. The application is designed to support an undergraduate thesis by showing how different storage models behave under the same local benchmark conditions.

Compared Databases

  • PostgreSQL: traditional relational SQL database.
  • MongoDB: document-oriented NoSQL database.
  • CockroachDB single-node: NewSQL database running as one local node.
  • CockroachDB cluster: NewSQL database running as a local three-node cluster.
  • Redis: in-memory key-value database.

Application Routes

  • /: introductory academic home page.
  • /sobre: detailed methodology page covering data preparation, operations, metrics, database behavior, and limitations.
  • /benchmark: benchmark execution page.
  • /api/benchmark: API route that runs the selected benchmark configuration.
  • /api/health: basic health endpoint.

Architecture

The application is built with Next.js App Router. The frontend renders the academic pages, benchmark form, result table, and charts. The backend benchmark execution runs inside a Next.js API route.

The benchmark flow is:

  1. The user selects databases, operations, volume, and number of rounds in /benchmark.
  2. The frontend sends the configuration to /api/benchmark.
  3. The benchmark runner prepares the required data for each selected database.
  4. Each selected operation is executed for the configured number of rounds.
  5. Metrics are calculated for the current execution.
  6. The frontend displays results in a sortable table and comparison charts.

The database containers are managed by Docker Compose. The application connects to them through localhost ports exposed by docker-compose.yml.

Benchmark Operations

The benchmark supports three operations:

  • INSERT: inserts generated application log records.
  • SELECT by ID: fetches one log record by unique identifier.
  • Relational SELECT: fetches related user and order data.

The relational operation is implemented according to each database model:

  • PostgreSQL and CockroachDB use SQL tables and JOIN.
  • MongoDB uses collections and aggregation with $lookup.
  • Redis uses hashes and sets to model related access by keys.

Metrics

For each database and operation, the application reports:

  • Average execution time.
  • Best execution time.
  • Worst execution time.
  • Estimated TPS, based on the configured volume and measured average time.

Results are calculated only for the current benchmark execution. They are not persisted as historical benchmark data.

Technologies

  • Next.js 14 with App Router.
  • React 18.
  • TypeScript.
  • Tailwind CSS.
  • shadcn-style UI primitives.
  • TanStack Table for sortable result tables.
  • Recharts for result charts.
  • PostgreSQL driver: pg.
  • MongoDB Node.js driver.
  • Redis Node.js client.
  • Docker Compose for local database orchestration.

Prerequisites

  • Node.js 20.19.0 or newer.
  • npm.
  • Docker.
  • Docker Compose.

Local Database Services

Running npm run db:up starts the following containers:

Service Container Host Port
PostgreSQL tcc_postgres 5433
MongoDB tcc_mongo 27017
Redis tcc_redis 6379
CockroachDB single-node SQL tcc_cockroach_single 26260
CockroachDB single-node dashboard tcc_cockroach_single 8083
CockroachDB cluster node 1 SQL tcc_cockroach1 26257
CockroachDB cluster node 1 dashboard tcc_cockroach1 8080
CockroachDB cluster node 2 SQL tcc_cockroach2 26258
CockroachDB cluster node 2 dashboard tcc_cockroach2 8081
CockroachDB cluster node 3 SQL tcc_cockroach3 26259
CockroachDB cluster node 3 dashboard tcc_cockroach3 8082

The Docker Compose file also includes a cockroach-init service that initializes the three-node CockroachDB cluster.

Setup

Install dependencies:

npm install

Start the database containers:

npm run db:up

Start the development server:

npm run dev

Open the application:

http://localhost:3000

Open the benchmark page directly:

http://localhost:3000/benchmark

Running a Benchmark

  1. Start the database containers with npm run db:up.
  2. Start the application with npm run dev.
  3. Open http://localhost:3000/benchmark.
  4. Select the databases to compare.
  5. Select one or more operations.
  6. Choose the record volume and number of rounds.
  7. Run the benchmark.
  8. Review the table and charts generated for the current execution.

Available Scripts

npm run dev

Starts the Next.js development server.

npm run build

Creates a production build.

npm run start

Starts the production server after a successful build.

npm run db:up

Starts all database containers with Docker Compose.

npm run db:down

Stops and removes the database containers.

Production Build

Create a production build:

npm run build

Start the production server:

npm run start

Notes and Limitations

  • The benchmark runs locally, so results depend on the host machine, Docker configuration, and available resources.
  • The data is synthetic and controlled for academic comparison.
  • Redis does not provide native joins; the relational operation uses hashes and sets as an equivalent key-based model.
  • CockroachDB cluster results can include distributed coordination overhead even when all nodes run on the same machine.
  • The benchmark is intended for controlled comparison in this project, not for general-purpose performance claims.

Stopping the Environment

Stop and remove the database containers:

npm run db:down

About

Database benchmark comparing PostgreSQL, CockroachDB, MongoDB and Redis.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages