https://github.com/felipeoriani/nodejs-database-concurrency
NodeJs Database Concurrency explores strategies to handle multiples users in high concurrency. Here I explore NodeJs, Typescript, PostgreSql with different packages including pg and Prisma ORM.
https://github.com/felipeoriani/nodejs-database-concurrency
database isolation-levels javascript locking locking-strategies mysql nodejs pessimistic-concurrency pg postgres postgresql transactions typescript
Last synced: 13 days ago
JSON representation
NodeJs Database Concurrency explores strategies to handle multiples users in high concurrency. Here I explore NodeJs, Typescript, PostgreSql with different packages including pg and Prisma ORM.
- Host: GitHub
- URL: https://github.com/felipeoriani/nodejs-database-concurrency
- Owner: felipeoriani
- Created: 2024-07-30T19:07:32.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-07-31T12:19:59.000Z (over 1 year ago)
- Last Synced: 2025-07-27T02:31:15.005Z (9 months ago)
- Topics: database, isolation-levels, javascript, locking, locking-strategies, mysql, nodejs, pessimistic-concurrency, pg, postgres, postgresql, transactions, typescript
- Language: TypeScript
- Homepage: https://github.com/felipeoriani/nodejs-database-concurrency
- Size: 43 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Node.JS Database Concurrency
In this repository, I aim to explore various _Database Concurrency Strategies_ in different databases including `Postgres`, `MySQL` and `Microsoft SQL Server` using `Node.JS` and `Typescript`. It covers strategies such as:
- Optimistic Concurrency Control
- Pessimistic Concurrency Control
- Hybrid Concurrency Control
The goal is to demonstrate these strategies in different databases and their respective packages. For instance, for `Postgres`, we'll explore implementations using the [`pg`](https://www.npmjs.com/package/pg) package, as well as _ORMs_ like [`Prisma`](https://www.prisma.io/) and [`Sequelize`](https://sequelize.org/). This repository serves as a reference for myself and anyone interested in learning how to apply these concurrency strategies.
:warning: _The code in this repository is still in progress._
## How to setup
To correctly use it, you need to have a `PostgreSQL` database running on your machine configured at the `.env` file. Make sure you have match the `.env` database connection info with the `docker-compose.yml` file.
You can easly do it using:
```
docker compose up -d
```
You can run the:
```
npm start
```
Just to check some extra information and also, you can run the following `npm` commands to explore the strategies:
```
npm run db:pg:optimistic
npm run db:pg:pessimistic
npm run db:pg:hybrid
```
or using `yarn`:
```
yarn db:pg:optimistic
yarn db:pg:pessimistic
yarn db:pg:hybrid
```
Most of them will reset the database, seed and run the strategy. You can check the files to understand each strategy.
At the end of the execution, you will see the results and some explanation why you get that result.
Thank you!